<<HypothesisTesting`

(*pre Mi, ak Sigma je zname, alebo mame velky pocet merani*)

(*(1-alfa)*100%    - alfa - uroven spolahlivosti*)

(*Priklad*)
nb={212,205,230,224,235,218,220,223,210,231}

MeanCI[nb,KnownVariance->0.5^2,ConfidenceLevel->0.9](*90% IS*)

MeanCI[nb,KnownVariance->0.5^2,ConfidenceLevel->0.98] (*lavostranny 99%, zanedbam pravu stranu*)

MeanCI[nb,KnownVariance->0.5^2,ConfidenceLevel->0.9] (*pravostranny 95%, zanedbam lavu stranu*)

(*pre Mi, ak Sigma nie je zname*)

(*.... ma Studentovo T rozdelenie*)

(*Priklad2*)
(*95% IS*)

data={51.3,62.8,51.9,57,55.3,52.1,58.4}

aritpriem=Mean[data]

n=Length[data]

kvantilT0975=Quantile[StudentTDistribution[n-1],0.975]

lavastrana=aritpriem-((kvantilT0975*StandardDeviation[data])/(Sqrt[n]))

pravastrana=aritpriem+((kvantilT0975*StandardDeviation[data])/(Sqrt[n]))

(*lavostranny 95%*) Jlavastrana=aritpriem-((Quantile[StudentTDistribution[n-1],0.9]*StandardDeviation[data])/(Sqrt[n]))

(*pravostranny 95%*) Jpravastrana=aritpriem+((Quantile[StudentTDistribution[n-1],0.9]*StandardDeviation[data])/(Sqrt[n]))

MeanCI[data,ConfidenceLevel->0.95]

MeanCI[data](*to iste *)

(*lavostranny 90%*)MeanCI[data,ConfidenceLevel->0.8](*namiesto (1-alfa)  -  (1-2*alfa) !!!!!!!!!!*)

g[11]=Plot[PDF[NormalDistribution[0,1],t],{t,-3,3},PlotStyle->{Hue[0.1],Thickness[0.001],Axes->{True,True}}]

densityT[x_,st_]:=PDF[StudentTDistribution[st],x]

Do[g[i]=Plot[densityT[t,i+20],{t,-3,3},PlotRange->All,Axes->{True,False},PlotStyle->{Thickness[0.0005*i]}],{i,1,10}]

Show[Table[g[i],{i,1,8}],g[11]]

(*IS pre Sigma, Sigma^2*)
(*95% , 90% pravy, lavy*)

SigmaLavastrana=(((n-1)*StandardDeviation[data]^2)/(Quantile[ChiSquareDistribution[n-1],0.975]))

SigmaPravastrana=(((n-1)*StandardDeviation[data]^2)/(Quantile[ChiSquareDistribution[n-1],0.025]))

JSigmaLavastrana=(((n-1)*StandardDeviation[data]^2)/(Quantile[ChiSquareDistribution[n-1],0.9]))

JSigmaPravastrana=(((n-1)*StandardDeviation[data]^2)/(Quantile[ChiSquareDistribution[n-1],0.1]))

?VarianceCI

VarianceCI[data] (*95% IS*)

VarianceCI[data,ConfidenceLevel->0.95]

(*jednostrnne 1-2*ALFA*)

densityCHI[x_,st_]:=PDF[ChiSquareDistribution[st],x]

Do[g[i]=Plot[densityCHI[t,i*10],{t,0,280},PlotRange->All,Axes->{True,False},PlotStyle->{Thickness[0.0005*i]}],{i,1,15}]

Show[Table[g[i],{i,1,15}]]

(*TESTY HYPOTEZ*)
(*-pizza do 30 minut- odchylka je 4 min => sigma^2=4^2*)
(*alfa= 0.05*)

pizza={24,32,31,29,28,29,35,34,30,31,27,28,35,36,29,24,30,26}

n=Length[pizza]

MeanCI[pizza,KnownVariance->16,ConfidenceLevel->0.95]