#MULTIPLE LINEAR REGRESSION #DATA INPUT - "volume.txt" - v-volume of tree in m^3, # d - BHD in cm, h - height in m, lc - length of a tree crown in m volume=read.table("http://user.mendelu.cz/drapela/Forest_Biometry/Data/volume.txt",sep="\t",header=T) head(volume) attach(volume) #exploratory data analysis and plots library(car) scatterplotMatrix(~v+d+h+lc,diagonal="boxplot",lwd=2) cor(cbind(v,d,h,lc)) vif(lm(v~d+h+lc)) avPlots(lm(v~d+h+lc)) # full linear model lm_vol1=lm(v~d+h+lc) summary(lm_vol1) confint(lm_vol1) #SIMPLIFIED MODEL lm_vol2=lm(v~d) summary(lm_vol2) scatterplot(d,v, id.n=5, lwd =2,lty.smooth = 5, lty.spread =3,lwd.smooth=1,lwd.spread=1) #polynomial regression lm_vol3= lm(v~d+I(d^2)) summary(lm_vol3) lm_vol4= lm(v~-1+d+I(d^2)) summary(lm_vol4) AIC(lm_vol2) AIC(lm_vol3) AIC(lm_vol4) anova(lm_vol3,lm_vol2) anova(lm_vol4,lm_vol3) plot(d,v, xlab="diameter (cm)", ylab="volume(m^3)") xx=(seq(min(d),max(d),1)) lines(xx,coef(lm_vol4)[1]*xx+coef(lm_vol4)[2]*I(xx^2),col="red") lines(xx,coef(lm_vol2)[1]+coef(lm_vol2)[2]*xx,col="blue")