#Biostatistics 390 #GLM & DUMMY VARIABLES #COMPARING TWO-SAMPLE T-TEST WITH GLM: ZAR=read.table("ZarEX8.1R.txt") ZAR attach(ZAR) Y=data X=group #PERFORMING TWO-SAMPLE TWO-SIDED t-TEST: t.test(Y~X,alternative="two.sided",var.equal=TRUE, conf.level=0.95) detach(ZAR) #PERFORMING EQUIVALENT GLM REGRESSION: ZAR2=read.table("ZarEX8.1bR.txt") ZAR2 attach(ZAR2) Y=data X=group summary(lm(Y~X)) detach(ZAR2) #COMPARING ONE-WAY ANOVA AS GLM: ZAR3=read.table("ZarEX10.1R.txt") ZAR3 attach(ZAR3) Y=weights X=factor(feed) LM=lm(Y~X) model.matrix(LM) anova(LM) USEFUL CONTRASTS IN R FOR UNORDERED FACTORS: #TREATMENT CONTRASTS (DEFAULT) LM=lm(Y~X) contrasts(X) model.matrix(LM) summary(LM) #CELL MEANS CONTRASTS: LM=lm(Y~X-1) #Note use of -1 contrasts(X) model.matrix(LM) summary(LM)