#Biostatistics 370 #SIMPLE LINEAR REGRESSION #ZAR EXAMPLE 19.1 ZAR=read.table("ZarEX19.1aR.txt") ZAR attach(ZAR) X=winglen Y=taillen #CREATING LINEAR MODEL LM: LM=lm(Y~X) Yhat=fitted(LM) e=residuals(LM) RESULTS=data.frame(X,Y,Yhat,e) RESULTS #ANOVA F-TEST FOR SLOPE: anova(LM) #t-TESTS FOR SLOPE & INTERCEPT: summary(LM) #TEST OF CORRELATION: cor.test(X,Y, method="pearson",alternative="two.sided",conf.level=0.95) #FISHER'S Z TRANSFORMATION TEST: rho0=0.750 #set test value n=length(Y) n r=sqrt(summary(LM)$r.squared) r z=(1/2)*log((1+r)/(1-r)) z z0=(1/2)*log((1+rho0)/(1-rho0)) z0 #TEST STATISTIC Z: Z=(z-z0)*sqrt(n-3) Z #CRITICAL VALUE OF TEST: alpha=0.05 #set type 1 error rate C=abs(qnorm(alpha/2,0,1)) C #PROBABILITY: PA=2*pnorm(Z,0,1) PA PB=2*(1-pnorm(Z,0,1)) PB P=min(PA,PB) P #CONFIDENCE INTERVAL FOR RHO z1=z-C*(1/sqrt(n-3)) z1 z2=z+C*(1/sqrt(n-3)) z2 CILower=(exp(2*z1)-1)/(exp(2*z1)+1) CILower CIUpper=(exp(2*z2)-1)/(exp(2*z2)+1) CIUpper