#5710 Lab Week of 2/23 R Script #The following reads it in from the web. If you do something in Rcmdr you will have to select charity as the active dataset. charity <- read.table("http://www.unt.edu/rss/class/mike/data/charity.txt", header=TRUE, sep="", na.strings="NA", dec=".", strip.white=TRUE) #1. Conduct multiple regression RegModel.1 <- lm(GIVEN~CASH+GENDER+IMPORT, data=charity) summary(RegModel.1) #2. Obtain confidence intervals for raw coefficients. confint(RegModel.1, level=.95) #3. Obtain graphs of the unique relationships of each predictor with GIVEN. av.plots(RegModel.1, ask=FALSE, identify.points=TRUE) #4. Calculate relative importance. library(relaimpo) calc.relimp(RegModel.1, rela=T) #5. a) Graphical diagnostic tests. Shown here just for giggles, Rcmdr menu is much more efficient. oldpar <- par(oma=c(0,0,3,0), mfrow=c(2,2)) plot(RegModel.1) par(oldpar) #5. b) Statistical test of normality of residuals. shapiro.test(RegModel.1$res) #6. b) Statistical test of homoscedasticity. Requires lmtest package if you aren't doing it in Rcmdr menus. bptest(GIVEN ~ CASH + GENDER + IMPORT, varformula = ~ fitted.values(RegModel.1), studentize=FALSE, data=charity) #7. a) Graphical test of linearity. cr.plots(RegModel.1, ask=FALSE) #b) Statistical test of linearity. Requires lmtest package if you aren't doing it in Rcmdr menus. resettest(GIVEN ~ CASH + GENDER + IMPORT, power=2:3, type="regressor", data=charity) #8. Variance inflation factors to test assumption of collinearity. vif(RegModel.1) #9. Conduct robust regression. library(MASS) summary(rlm(GIVEN ~ CASH + GENDER + IMPORT, data=charity)) #10. Validate the model and obtain bias-adjusted R square. library(Design) myvalidatedmodel=ols(GIVEN ~ CASH + GENDER + IMPORT, x=T, y=T, data=charity) validate(myvalidatedmodel)