Practical Computing Exercise for Week 2 :Reworking of the Tree Diameters example

Download the template R markdown file for this workshop.

Aims of this practical exercise

In this exercise you will:

  • rework some of the example given in ELMER
  • get some practice using R markdown

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

data(TreeDiams, package="ELMER")
str(TreeDiams)
'data.frame':   12 obs. of  2 variables:
 $ Diameter: num  0.9 1.2 2.9 3.1 3.3 3.9 4.3 6.2 9.6 12.6 ...
 $ Height  : num  18 26 32 36 44.5 35.6 40.5 57.5 67.3 84 ...

Fit the models

Fit the models used in the example in Chapter 1 of ELMER.

Make the graph

Just create the graph that shows the fitted models on the original data scale because this is the one that is important.

N.B. You should try to do this using ggplot() if you can. To get the curves of your models on your scatter plot, you might make use of geom_function()

Make the tables of fitted values

Use predict() to find the fitted values from the three models used so far. Use kable() to put them into a nice table.

Additional exercises

Calculate a regression of height on diameter and height on log(Diameter) omitting the largest tree in the TreeDiams data.

Replot the scatter plots using the reduced data, with the fitted lines added.

Which of the two regressions would you choose, and why?

Solutions

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