rm(list=ls()) #remove everything setwd("D:/adsm/lehre/PhD_Oekologie/WS2010/Assignments/Assignment3") ######Problem 1##### data1 <- read.csv("data_set1.csv",header=TRUE) summary(data1) attach(data1) #What are the estimates for the coefficients? Are all significant? model1<-lm(y1~x1+x2_2+x3) summary(model1) #Do all residual diagnostic plots suggested by R. plot(model1) #Recompute the linear regression without observation units \$40\$ and \$70\$. data1_2<-rbind(data1[1:39,],data1[41:69,],data1[71:100,]) model1_2<-lm(y1~x1+x2_2+x3,data=data1_2) #Do all residual diagnostic plots suggested by R again. plot(model1_2) #What are now the estimates for the coefficients? summary(model1_2) ######Problem 2##### data2<- read.csv("data_set2.csv",header=TRUE) attach(data2) #What are the estimates for the coefficients? Are all significant? model2<-lm(y2~x1+x2+x3) summary(model2) #Plot the residuals versus the fitted values. plot(model2\$fitted,model2\$resid) #Plot the residuals versus all independent variables. par(mfrow=c(2,2)) plot(x1,model2\$resid) plot(x2,model2\$resid) plot(x3,model2\$resid) #Conduct the Breusch-Pagan Test for heteroscedasticity. library(AER) bptest(model2) #Compute heteroscedastic robust standard errors coeftest(model2,vcov=vcovHC) #models the underlying heteroscedasticity model2_het<-lm(y2~x1+x2+x3,weights=1/x3^2) summary(model2_het) plot(model2_het) ######Problem 3##### data3<- read.csv("data_set3.csv",header=TRUE) attach(data3) #Do all residual diagnostic plots suggested by R. model3<-lm(y3~x1+x2+x3) summary(model3) plot(model3) #Plot the residuals versus all independent variables. par(mfrow=c(2,2)) plot(x1,model3\$resid) plot(x2,model3\$resid) plot(x3,model3\$resid) #Regress \$y3\$ on \$x1,x2^2\$ and \$x3\$. model3_2<-lm(y3~x1+I(x2^2)+x3) #Do all residual diagnostic plots suggested by R. plot(model3_2) #What are now the estimates for the coefficients? Are they significant? summary(model3_2)