# # Epage # # Written by: # -- # John L. Weatherwax 2009-04-21 # # email: wax@alum.mit.edu # # Please send comments and especially bug reports to the # above email address. # #----- if(is.null(version$language) == FALSE){ require(alr3) }else{ library(alr3) } data(UN3) UN3$logPPgdp <- log(UN3$PPgdp) m0 <- lm( ModernC ~ logPPgdp+Change+Pop+Fertility+Frate+Purban, data=UN3 ) s0 <- summary(m0) # use avp (added variable plot) found in the car package library(car) postscript("../../WriteUp/Graphics/Chapter9/prob_9_avp.eps", onefile=FALSE, horizontal=FALSE) avp(m0, ask=FALSE, one.page=TRUE, identify.points=FALSE) dev.off() ind1 <- match( max(UN3$Pop), UN3$Pop ) # 25 #UN3$Pop[ind1] <- 0 # used to find the second largest element ind2 <- match( max(UN3$Pop), UN3$Pop ) # 50 UN3[c(25,50),] # look for the point that has the largest value of Change: # ind1 <- match( max(UN3$Change), UN3$Change ) # 77 UN3[ind1,] ti <- rstudent(m0) ind1 <- match( max(ti), ti ) # 28 ti[ind1] <- 0 ind2 <- match( max(ti), ti ) # 76 ti[ind2] <- 0 ind3 <- match( max(ti), ti ) # 125 ti[ind3] <- 0 ind4 <- match( max(ti), ti ) # 65 posOut <- c(28,76,125,65) n <- length(UN3$Pop) pprime <- length(m0$coefficients) n * 2 * ( 1 - pt( ti[posOut],n-pprime-1) ) DI <- cooks.distance( m0 ) plot(DI)