(*intervaly spolahlivosti*)

(*testujeme dobu pohotovostneho rezimu(v hodinach) na 10 kusoch 1neho typu vyrobku
zostroj
90%IS pre mi,ak sigma=0.5
99% lavostranny IS pre mi
95%pravostranny IS pre mi*)

mb={212,205,230,224,235,218,220,223,210,231}

<<HypothesisTesting`

MeanCI[mb,KnownVariance->0.5^2,ConfidenceLevel->0.9]

MeanCI[mb,KnownVariance->0.5^2,ConfidenceLevel->0.98]

(*IS 2 je (220.432,inf)  *)

MeanCI[mb,KnownVariance->0.5^2,ConfidenceLevel->0.9]

(*IS pre mi ak sugna nieje zname*)

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

(*pouzijeme  kvantili Studentovho  trozdelenia s n-1 stupnami vol., inak sa postup nemani*)

kvantilT0975=Quantile[StudentTDistribution[Length[data]-1],0.975]

LS=Mean[data]-(kvantilT0975*StandardDeviation[data])/(Sqrt[Length[data]])

PS=Mean[data]+(kvantilT0975*StandardDeviation[data])/(Sqrt[Length[data]])

MeanCI[data,ConfidenceLevel->0.95]

MeanCI[data,ConfidenceLevel->0.8]

(*lavo a pravostranny 90%*)

(*teraz si vykreslime hodnoty studentovho t rozdelenia a porovname  s normalny*)

graf=Plot[PDF[NormalDistribution[0,1],t],{t,-3,3},PlotStyle->{Hue[0.1],Thickness[0.01]},Axes->{True,False}]

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

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

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

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

(*zaver Cim viac stupnov volnosti tym viac sa Student rodelenie podoba na Norm rozdelenie*)

kvantilCHI0025=Quantile[ChiSquareDistribution[Length[data]-1],0.025]

kvantilCHI0975=Quantile[ChiSquareDistribution[Length[data]-1],0.025]

VarianceCI[data](*95 % IS pre Sigma^2*)

VarianceCI[data,ConfidenceLevel->0.8]

(*90% lavo a pravo stranny*)

(*vyjreskime si hustoity rozdel CHi kvadrat*)

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

Do[g[i]=Plot[densityCH[t,i*10],{t,0,80},PlotRange->All,Axes->{True,False},PlotStyle->{Thickness[0.001*i]}],{i,1,10}]
Show[Table[g[i],{i,1,8}]]

(*priklady*)

data1={32.5,45.2,32.8,39,41.2,38.3,31.9}

MeanCI[data1,KnownVariance->10.72,ConfidenceLevel->0.95]
MeanCI[data1,KnownVariance->10.72,ConfidenceLevel->0.8]

MeanCI[data1,ConfidenceLevel->0.95]
MeanCI[data1,ConfidenceLevel->0.8]

VarianceCI[data1,ConfidenceLevel->0.90]
VarianceCI[data1,ConfidenceLevel->(0.90)]

data2={28,29,30,30,27,31,29,25,30,32}

MeanCI[data2,KnownVariance->2.98,ConfidenceLevel->0.99]
MeanCI[data2,KnownVariance->2.98,ConfidenceLevel->(1-2*0.05)]

VarianceCI[data2,ConfidenceLevel->0.90]
VarianceCI[data2,ConfidenceLevel->(1-2*0.05)]

data3={2345,2875,2638,2743,2738,2438,2094,2845,2875,2986}

MeanCI[data2,ConfidenceLevel->0.95]
MeanCI[data2,ConfidenceLevel->(1-2*0.1)]

VarianceCI[data2,ConfidenceLevel->0.90]
VarianceCI[data2,ConfidenceLevel->(1-2*0.05)]