Practical Computing Exercise for Week 4: The first River Problems exercise

Download the template R markdown file for this workshop.

Aims of this practical exercise

In this exercise you will:

  • rework the example given in ELMER
  • get some practice using R markdown
  • fit a variety of models to the RiverProb data involving a variety 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(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

A straight line did not model the mean of the river problems in the example found in ELMER at all well. Try fitting: \[\begin{aligned} \mu_{Y} & = & \beta_0 + \beta_1\ln{x} \\ var(Y) & = &k \mu_Y\end{aligned}\] Compare the fit of this model with the earlier one.

Step 1: Fit the unweighted model ModelU, and make a copy called ModelW.

Step 2: Start to collect the values of the parameters you want to track, and set up the Results matrix to collate them.

Step 3: Write out the working for the weighted model, and then wrap it in a loop to produce enough iterations. (10 should suffice).

You will need to:

  • determine the weights you want to use
  • make sure the weights are non-negative.
  • Use update() to incorporate the weights.
  • Collate the results for each iteration.

Step 4: Print out the Results to see that sufficient iterations have ben completed to assure convergence.

Step 5: Graph your new model.

Solutions

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