Practical Computing Exercise for Week 5 :The second River Problems exercise using all of the data

Download the template R markdown file for this workshop.

Aims of this practical exercise

In this exercise you will:

  • Complete the exercise given in ELMER
  • get some practice using R markdown
  • fit a variety of models to the entire RiverProbAll data.

Before you undertake this exercise…

You should only attempt this (second) exercise using this dataset after completing the first exercise.)

Get the data

data(RiverProbAll, package="ELMER")
str(RiverProbAll)
'data.frame':   91 obs. of  3 variables:
 $ Flow    : int  24 24 26 26 50 48 72 72 25 23 ...
 $ Type    : Factor w/ 3 levels "Canadian","Kayak",..: 1 3 2 1 1 1 1 2 1 2 ...
 $ Problems: int  1 0 0 0 1 0 1 2 1 3 ...

You’ll also want the subset used previously.

data(RiverProb, package="ELMER")
str(RiverProb)
'data.frame':   21 obs. of  2 variables:
 $ Flow    : int  24 36 24 25 72 37 46 24 37 46 ...
 $ Problems: int  0 0 0 0 0 0 0 0 0 0 ...

The Exercise

The dataset RiverProbAll gives the number of problems experienced by travelers on the Whanganui river. This is the full data set including the craft type as a categorical variable.

In the previous exercise, you fitted a generalised linear model to this data using a Poisson distribution for the number of problems, using a log link function.

The example in Chapter 3 of ELMER used a subset of the Whanganui river data for Other craft. An identity link was used in that analysis instead of a log link.

Calculate the predicted number of problems for a range of river flows using this model, and compare with the predictions for the same flow and Other craft type for the model in the previous exercise .

Compare the models using a graph.

Hint: the values of the final parameters after 8 iterations were 1.22329 and -0.01703 for the weighted model fitted in Chapter 3.

Solutions

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