#Biostatistics 140 #TEST OF VARIANCE FOR A NORMAL DISTRIBUTION #ZAR EXAMPLE 7.4 ZAR=read.table("ZarEX7.4.txt") ZAR attach(ZAR) X=distime n=length(X) s=sqrt(var(X)) #SET THE FOLLOWING AS DESIRED: alpha=0.05 sigma0=sqrt(1.5) #CALCULATING BY HAND: #CHI SQUARE STATISTIC: Xsq=((n-1)*s^2)/sigma0^2 Xsq #CRITICAL VALUES: C1=qchisq(alpha/2,n-1) C1 C2=qchisq(1-alpha/2,n-1) C2 C3=qchisq(alpha,n-1) C3 C4=qchisq(1-alpha,n-1) C4 #PROBABILITY: P=2*(1-pchisq(Xsq,n-1)) # two sided case P P=pchisq(Xsq,n-1) #one sided case lower tail P P=1-pchisq(Xsq,n-1) #one sided case upper tail P #CONFIDENCE INTERVALS: #TWO SIDED CASE: CIL=((n-1)*s^2)/C2 CIL CIU=((n-1)*s^2)/C1 CIU #ONE SIDED CASE LOWER TAIL: CIL=((n-1)*s^2)/C3 CIL #ONE SIDED CASE UPPER TAIL: CIU=((n-1)*s^2)/C4 CIU #USING FUNCTION varTest() in {EnvStats}: library(EnvStats) varTest(X,sigma.squared = 1.5,alternative="two.sided",conf.level=0.95)