## ----include=FALSE------------------------------------------------------- library(knitr) opts_chunk$set( fig.path='l4figs/', tidy=FALSE ) ## ----vocab1, echo=T, include=T------------------------------------------- library(car) data(Vocab) summary(mod <- lm(vocabulary ~ education + sex, data=Vocab)) ## ----rbyhand, echo=T----------------------------------------------------- V <- vcov(mod) b <- coef(mod) se.sum <- sqrt(V[1,1] + V[3,3] + 2*V[1,3]) t <- (b[1] + b[3])/se.sum pval <- 2*pt(t, mod$df.residual, lower.tail=F) res <- c(b[1] + b[3], se.sum, t, pval) names(res) <- c("est", "se", "t", "pval") round(res, 3) ## ----linhyp, echo=T------------------------------------------------------ linearHypothesis(mod, "sexMale + (Intercept) = 0") ## ----contrasts, echo=T--------------------------------------------------- data(Prestige) Prestige$income <- Prestige$income/1000 contrasts(Prestige$type) ## ----prestige, echo=T---------------------------------------------------- summary(mod <- lm(prestige ~ income + education + type, data=Prestige)) ## ----changebase, echo=T-------------------------------------------------- Prestige$type <- relevel(Prestige$type, 2) summary(mod1 <- lm(prestige ~ income + education + type, data=Prestige)) ## ----Anova, echo=T------------------------------------------------------- Anova(mod) linearHypothesis(mod, c("typeprof = 0", "typewc = 0")) ## ----ornmod, echo=F, warning=F, message=F, results='asis'---------------- data(Ornstein) omod <- lm(interlocks ~ nation + sector + assets, data=Ornstein) library(apsrtable) apsrtable(omod, Sweave=T) ## ----ornfp, echo=FALSE, warning=F, message=F,fig.show='hide'------------ library(factorplot) ofp <- factorplot( omod, factor.variable="sector") plot(ofp) ## ----mtest, echo=F, fig.show='hide'-------------------------------------- m <- 1:50 alpha <- c(.1, .05, .01, .001) sigfun <- function(alpha, m){1-(1-alpha)^m} sigres <- outer(alpha, m, sigfun) plot(c(1,max(m)), c(0, 1), type="n", xlab="m", ylab="Pr(Type I Error)") for(i in 1:4){ lines(m, sigres[i,], lty=i) } legend("topleft", as.character(alpha), lty=1:4, inset=.01) ## ----bonomod, echo=F, fig.show='hide'------------------------------------ ofp2 <- factorplot(omod, factor.variable="sector", adjust.method="holm") plot(ofp2) ## ----fpsum, echo=T------------------------------------------------------- summary(ofp2) ## ----fpp, echo=T--------------------------------------------------------- print(ofp2, sig=TRUE)