################################################### ### chunk number 1: ################################################### options(show.signif.stars=FALSE, digits=4) options(SweaveHooks=list(fig=function(){par( mar=c(4.1,4.1,1.6,2.1), mgp=c(2.5,0.5,0), tck=-0.02)})) ################################################### ### chunk number 2: DAAG ################################################### library(DAAG) ################################################### ### chunk number 3: ex1 eval=FALSE ################################################### ## conc <- c(.1, .5, 1, 10, 20, 30, ## 50, 70, 80, 100, 150) ## no <- c(7, 1, 10, 9, 2, 9, 13, 1, 1, 4, 3) ## yes <- c(0, 0, 3, 4, 0, 6, 7, 0, 0, 1 ,7) ## n <- no + yes ## plot(log(conc), log((yes+0.5)/(no+0.5))) ################################################### ### chunk number 4: ################################################### conc <- c(.1, .5, 1, 10, 20, 30, 50, 70, 80, 100, 150) no <- c(7, 1, 10, 9, 2, 9, 13, 1, 1, 4, 3) yes <- c(0, 0, 3, 4, 0, 6, 7, 0, 0, 1 ,7) n <- no + yes plot(log(conc), log((yes+0.5)/(no+0.5))) ################################################### ### chunk number 5: ex1-code eval=FALSE ################################################### ## conc <- c(.1, .5, 1, 10, 20, 30, ## 50, 70, 80, 100, 150) ## no <- c(7, 1, 10, 9, 2, 9, 13, 1, 1, 4, 3) ## yes <- c(0, 0, 3, 4, 0, 6, 7, 0, 0, 1 ,7) ## n <- no + yes ## plot(log(conc), log((yes+0.5)/(no+0.5))) ################################################### ### chunk number 6: ################################################### p <- yes/n inhibit.glm <- glm(p ~ I(log(conc)), family=binomial, weights=n) summary(inhibit.glm) ################################################### ### chunk number 7: ex2 ################################################### sapply(head.injury, range) injury.glm <- glm(clinically.important.brain.injury ~ ., data=head.injury, family=binomial) summary(injury.glm) ################################################### ### chunk number 8: ex3c ################################################### sapply(split(moths$P, moths$habitat), sum) moths$habitat <- relevel(moths$habitat, ref="Lowerside") P.glm <- glm(P ~ habitat + log(meters), family=quasipoisson, data=moths) ################################################### ### chunk number 9: ex4 ################################################### str(mifem) sapply(mifem[, c("age", "yronset")], range) lapply(mifem[, -(1:3)], table) ################################################### ### chunk number 10: mifem-glm ################################################### for(j in 4:10)mifem[,j] <- relevel(mifem[,j], ref="n") mifem1.glm <- glm(outcome ~ ., family=binomial, data=mifem) mifem2.glm <- glm(outcome ~ .^2, family=binomial, data=mifem) anova(mifem1.glm, mifem2.glm) CVbinary(mifem1.glm) CVbinary(mifem2.glm)