# Exercise 6 # a ds <- read.csv("http://www.math.ntnu.no/~erikblys/TMA4255-V14/Data/data4.csv") colnames(ds) fit <- lm(Volume~.,data=ds) summary(fit) # look at standardized or studentized residuals plot(ds$Height,rstudent(fit)) plot(ds$Diameter,rstudent(fit)) plot(fit$fitted.values,rstudent(fit)) qqnorm(rstudent(fit)) qqline(rstudent(fit)) # or by using plot(rstudent(fit)) # b - adding IQ set.seed(123) # reproducible results iq <- rnorm(31,100,16) fit2 <- lm(Volume~Height+Diameter+iq,data=ds) summary(fit2) plot(iq,rstudent(fit2)) plot(fit2$fitted.values,rstudent(fit2)) qqnorm(rstudent(fit2)) qqline(rstudent(fit2)) library(nortest) ad.test(rstudent(fit2)) # focus on R2 and R2 adjusted we see that # R2 has increased from 0.948 to 0.9486 to and R2adj has decreased from 0.9442 to 0.9429 # c # new variable x <- ds$Diameter^2*ds$Height fitx <- lm(ds$Volume~x) summary(fitx) plot(fitx$fitted,rstudent(fitx)) plot(rstudent(fitx)) qqnorm(rstudent(fitx)) fitx2 <- lm(ds$Volume~x-1) #without intercept summary(fitx2) newobs <- data.frame("x"=15^2*80) predict(fitx2,newdata=newobs,interval="prediction") # d lnD <- log(ds$Diameter) lnV <- log(ds$Volume) lnH <- log(ds$Height) lnds <- data.frame(lnD,lnH,lnV) fitln <- lm(lnV~lnD+lnH,data=lnds) summary(fitln) plot(fitln$fitted,rstudent(fitln)) plot(rstudent(fitln)) qqnorm(rstudent(fitln)) qqline(rstudent(fitln)) ad.test(rstudent(fitln)) newobs <- data.frame("lnD"=log(15),"lnH"=log(80)) predint <- predict(fitln,newdata=newobs,interval="predict") predint # backtransform to original units exp(predint)