##---------------------------------------------------------------------## ## Script for Soc 740 Lecture 7 ## ## John Fox ## ## Winter 2014 ## ##---------------------------------------------------------------------## library(car) mod.prestige <- lm(prestige ~ income + education + women, data=Prestige) vif(mod.prestige) sqrt(vif(mod.prestige)) mod.prestige.1 <- lm(prestige ~ income + education + women + type, data=Prestige) vif(mod.prestige.1) ?Bfox Bfox$time <- 1:30 par(mfrow=c(3, 2)) vars <- names(Bfox) for (i in 1:6) plot(1946:1975, Bfox[,i], type="l", ylab=vars[i], xlab="Year") Bfox$tfr[28] <- 1931 # fix error in the data cor(Bfox) mod.bfox <- lm(partic ~ ., data=Bfox) summary(mod.bfox) round(sqrt(vif(mod.bfox)), 2) library(leaps) sub <- regsubsets(partic ~ ., data=Bfox, nbest=10) par(mfrow=c(1,3)) subsets(sub, statistic="bic") subsets(sub, statistic="cp") subsets(sub, statistic="adjr2") step(mod.bfox, k=log(30)) # k = log(n) gives BIC step(mod.bfox) # uses the AIC