#montoria dia 17 de junho install.packages('wooldridge') library(wooldridge) data("vote1") vote1 attach(vote1) model1 = lm(voteA~lexpendA+lexpendB+prtystrA) summary(model1) diff_exp = lexpendA - lexpendB model2 = lm(voteA ~diff_exp+prtystrA) summary(model2) coeffs <- coefficients(model1) model1$model coeffs <- summary(model1)$coefficients dim(coeffs) (coeffs[2,1]+coeffs[3,1])/sqrt(coeffs[2,2]^2+coeffs[3,2]^2) #chap3 C10 #i data("htv") attach(htv) var(educ) educ fatheduc sum(educ<=12)/length(educ) sum(educ>12 & educ<=16)/length(educ) mean(educ) mean(fatheduc) #ii attach(htv) model1 = lm(educ~motheduc+fatheduc) summary(model1) #iii model2 = lm(educ~motheduc+fatheduc+abil) summary(model2) #iv abil2 = abil^2 model3 = lm(educ~motheduc+fatheduc+abil+abil2) summary(model3) #v coeffs <- summary(model3)$coefficients f <- function(abil){ y <- coeffs[1,1]+coeffs[2,1]*12.18+coeffs[3,1]*12.45+ coeffs[4,1]*abil + coeffs[5,1]*abil^2 } y <- f(abil) plot(abil, y) #chap 4 C11 #ii (coeffs[2,1]-coeffs[3,1])/sqrt(coeffs[2,2]^2+coeffs[3,2]^2) pt(2.36,1230,lower.tail = FALSE)*2 pt(2.36,1230,lower.tail = FALSE) #iii model3 <- lm(educ~motheduc+fatheduc+abil+abil2+ tuit17+tuit18) summary(model3) linearHypothesis(model3, c("tuit17=0", "tuit18=0")) #iv cor(tuit17,tuit18) tuit1718 = (tuit17+tuit18)/2 model4 <- lm(educ~motheduc+fatheduc+abil+abil2+ +tuit1718) summary(model4)