Practical Computing Exercise for Week 3 :The Tree Volumes exercise

Download the template R markdown file for this workshop.

Aims of this practical exercise

In this exercise you will:

  • get some more practice using R markdown
  • fit a variety of models to the Tree Volumes data involving a selection of transformations.

Before you undertake this exercise…

You need to have installed R, RStudio, and the necessary packages for the course, including the ELMER package. See how to get set up for this course

Get the data

data(TreeVols, package="ELMER")
str(TreeVols)
'data.frame':   31 obs. of  3 variables:
 $ Volume: num  0.29 0.29 0.28 0.46 0.53 0.55 0.44 0.63 0.56 0.68 ...
 $ Height: num  21.3 19.8 19.2 21.9 24.6 25.2 20.1 24.3 22.8 24 ...
 $ Girth : int  210 218 223 266 271 274 279 281 284 287 ...

The Exercise

  1. Fit y to x1 and x2.

  2. Fit \(\ln y\) to \(\ln x_1\) and \(\ln x_2\). Is this model definitely better than the first model?

  3. Fit \(y^*(\lambda)\) to \(x_1\) and \(x_2\). Estimate the value of \(\lambda\) by maximum likelihood. Is this model definitely better than the first model?

Hint: Use the boxcox() function in the MASS package.

library(MASS)
TreeVols.bc = boxcox(Volume ~ Height + Girth, data =TreeVols)
# to get exact value of lambda:
Lambda = TreeVols.bc$"x"[which.max(TreeVols.bc$"y")]
Lambda
  1. Girth is much easier to measure than height. Is there evidence that the height variable is necessary?

Finally, which model would be expected to fit best, based on a physical model?

Solutions

You should compare your work with the solutions for this workshop.