#WEEK 5 Lecture # R Code #Start class with single regression in R library(car) attach(Davis) #What is in the dataframe ?Davis dim(Davis) nrow(Davis) ncol(Davis) #Basic Linear Regression Model davis.mod <- lm(weight~repwt, data=Davis) #data= redundant because of attach #Basic Arguments/Other possible arguments ?lm #What is in the lm function davis.mod summary(davis.mod) ?lm davis.mod$coefficients davis.mod$residuals sum(davis.mod$residuals) #that is a relief sqrt(sum(davis.mod$residuals^2)/(181-2)) #estimate of the residual standard error #why 181 and not 200-2 #other stuff from the book confint(davis.mod) scatterplot(weight~repwt) #A word about other people's graph code #found a crazy outlier/should we do something about it? Davis[12,] davis.mod.2 <- update(davis.mod, subset=-12) summary(davis.mod.2) #Interpret the regression table/ all stats #End class with Fox Companion multiple regression example attach(Prestige) dim(Prestige) ?Prestige prestige.mod <- lm(prestige~education + log2(income) + women, data=Prestige) summary(prestige.mod) #interpret all output #women is percent women in an occupation