# 1 seedl<-read.delim2("clipboard") summary(seedl) lm.0<-lm(seedlings~+1, data=seedl) summary(lm.0) add1(lm.0, .~.+(treatment+productivity+temperature)^2, test="F") # Single term additions # # Model: # seedlings ~ +1 # Df Sum of Sq RSS AIC F value Pr(>F) # 819.37 101.220 # treatment 2 400.47 418.90 85.093 12.9059 0.0001166 *** # productivity 1 100.72 718.65 99.285 3.9241 0.0574976 . # temperature 1 39.55 779.81 101.736 1.4203 0.2433658 # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 lm.1<-update(lm.0, .~.+treatment) summary(lm.1) add1(lm.1, .~.+(treatment+productivity+temperature)^2, test="F") # Single term additions # # Model: # seedlings ~ treatment # Df Sum of Sq RSS AIC F value Pr(>F) # 418.90 85.093 # productivity 1 48.958 369.94 83.364 3.4408 0.07498 . # temperature 1 45.090 373.81 83.677 3.1362 0.08830 . # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 lm.2<-update(lm.1, .~.+productivity) summary(lm.2) add1(lm.2, .~.+(treatment+productivity+temperature)^2, test="F") lm.3<-update(lm.2, .~.+treatment:productivity) add1(lm.3, .~.+(treatment+productivity+temperature)^2, test="F") Single term additions # Model: # seedlings ~ treatment + productivity + treatment:productivity # Df Sum of Sq RSS AIC F value Pr(>F) # 290.73 80.135 # temperature 1 26.427 264.30 79.276 2.2998 0.143 plot(lm.3) anova(lm.0, lm.1, lm.3, test="F") summary(lm.3) # Call: # lm(formula = seedlings ~ treatment + productivity + treatment:productivity, # data = seedl) # # Residuals: # Min 1Q Median 3Q Max # -6.5919 -2.1628 -0.1457 1.9462 5.5582 # # Coefficients: # Estimate Std. Error t value Pr(>|t|) # (Intercept) 12.881195 4.483482 2.873 0.00837 ** # treatmentmown1 4.868860 6.052372 0.804 0.42903 # treatmentmown2 5.794768 5.659757 1.024 0.31611 # productivity 0.012357 0.009391 1.316 0.20068 # treatmentmown1:productivity -0.025282 0.011947 -2.116 0.04490 * # treatmentmown2:productivity -0.028249 0.011482 -2.460 0.02147 * # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # Residual standard error: 3.48 on 24 degrees of freedom # Multiple R-squared: 0.6452, Adjusted R-squared: 0.5713 # F-statistic: 8.728 on 5 and 24 DF, p-value: 7.967e-05 # Task 2 transpi<-read.delim2("clipboard") summary(transpi) lm.0<-lm(transpiration~+1, data=transpi) add1(lm.0, .~.+wind+temperature+humidity+sunshine, test="F") # Single term additions # # Model: # transpiration ~ +1 # Df Sum of Sq RSS AIC F value Pr(>F) # 158.000 35.930 # wind 1 75.369 82.631 28.855 10.9454 0.006243 ** # temperature 1 93.763 64.237 25.329 17.5157 0.001265 ** # humidity 1 0.038 157.962 37.926 0.0029 0.958179 # sunshine 1 4.667 153.333 37.510 0.3652 0.556876 # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 lm.1<-update(lm.0, .~.+temperature) summary(lm.1) add1(lm.1, .~.+wind+temperature+humidity+sunshine, test="F") lm.2<-update(lm.1, .~.+wind) add1(lm.2, .~.+wind+temperature+humidity+sunshine, test="F") summary(lm.2) # Call: # lm(formula = transpiration ~ temperature + wind, data = transpi) # # Residuals: # Min 1Q Median 3Q Max # -2.8698 -0.7002 -0.2190 0.8018 2.2732 # # Coefficients: # Estimate Std. Error t value Pr(>|t|) # (Intercept) 5.45464 1.14007 4.784 0.000567 *** # temperature 0.38619 0.08048 4.798 0.000555 *** # wind 0.67796 0.17247 3.931 0.002349 ** # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # Residual standard error: 1.558 on 11 degrees of freedom # Multiple R-squared: 0.8309, Adjusted R-squared: 0.8002 # F-statistic: 27.03 on 2 and 11 DF, p-value: 5.681e-05 plot(lm.2) #Task 3 plants<-read.delim2("clipboard") summary(plants) lm.1<-lm(biomass~watering*fertil, data=plants) summary(lm.1) plot(lm.1) lm.1<-lm(log(biomass)~watering*fertil, data=plants) plot(lm.1) summary(lm.1) # Call: # lm(formula = log(biomass) ~ watering * fertil, data = plants) # # Residuals: # Min 1Q Median 3Q Max # -0.215320 -0.065523 0.009066 0.081658 0.213493 # # Coefficients: # Estimate Std. Error t value Pr(>|t|) # (Intercept) 4.36385 0.05277 82.695 < 2e-16 *** # wateringWatered 0.07558 0.07463 1.013 0.32328 # fertilFertilized 0.24639 0.07463 3.301 0.00356 ** # wateringWatered:fertilFertilized 0.37369 0.10554 3.541 0.00205 ** # --- # Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 # # Residual standard error: 0.1293 on 20 degrees of freedom # Multiple R-squared: 0.8396, Adjusted R-squared: 0.8155 # F-statistic: 34.89 on 3 and 20 DF, p-value: 3.862e-08 library(sciplot) lineplot.CI(plants$watering, log(plants$biomass), group=plants$fertil) #Task 4 people<-read.delim("clipboard") summary(people) lm.0<-lm(mass~+1, data=people) lm.sel<-step(lm.0, .~+sex+height+colour+vegetarian+hours, direction="forward") summary(lm.sel) plot(lm.sel)