Assignment 4

Due Date

Friday, September 28, 2012

Data Source

The data for this assignment is poplars.txt, a tab-delimited text file. This data set is a homework exercise in Sokal and Rohlf (1995), p. 390, and the original data are taken from Lunt (1947). The set-up is as follows. Oven-dry weights (in grams) of new growth of hybrid poplars grown in concrete soil frames and treated with lime (L), nitrogen (N), phosphorus (P), and/or potassium (K) were obtained. The frames were laid out in three blocks with no replication of the treatments within blocks. The goal was to determine the manner in which the different soil additives affected growth.

Questions

  1. In Sokal and Rohlf (1995) only the variables weight, trt, and block are given. I constructed the four factors L, N, P, and K in poplars.txt from the treatment variable (trt). In trt a value of O indicates the absence of treatment (controls) while the symbols L, N, P, and K indicate that the particular soil additive was present. Question 1 is to figure out a way to repeat what I've already done. Write a few lines of R code that will create the variables L, N, P, and K from the single variable trt.
  2. Analyze the new growth weights of poplars (weight) to determine the manner in which different combinations of soil additives affects growth. Report your final model.
  3. Give a one or two sentence description of what your final model says.
  4. Create a single graphic (the graphic may contain more than one part) that completely summarizes the results of your analysis.
    1. It should show the average growth of hybrid poplars as predicted by your model for those treatments that had a significant effect on growth.
    2. It should allow the user to assess the precision of the estimates of the means and be able to make comparisons among the means.
    3. It should clearly demonstrate how the individual factors operate separately and in concert.

Hints

  1. There are many ways to generate the variables L, N, P, and K for question 1. If you're stuck, here is a rough outline of what I did. I used the functions as.character, strsplit, sapply, ifelse, and the operator %in%. If you choose to match what I did you'll need to examine the help screen for some of these functions to see how to use them properly.
    1. I began by splitting each of the character strings of trt into vectors each of whose elements were single characters. For this I used as.character to first convert the factor values to character values followed by strsplit with an appropriate value for the split argument to create a vector of singletons from each separate value of trt. The result will be a list whose elements are character vectors of varying lengths.
    2. I then used four ifelse statements to separately create the individual variables L, N, P, and K based on the entries of the list created in (a). The logical test condition of each ifelse statement was constructed by using sapply on the list of vectors from (a). The generic function I wrote for sapply tested whether a particular character, 'L', 'N', 'P', or 'K' was present among the elements of each vector in the list.
    3. For example to create the variable L I had to test whether the character 'L' was among the vector entries. This had to be done separately for each element of the list. For this I used the %in% logical intersection operator. The %in% operator works as follows.

      'L' %in% c('N','K')
      [1] FALSE
      'L' %in% c('N','K','L')
      [1] TRUE

    4. The first input to %in% is the character we're searching for. The second input to %in% is an element of the list created in (a). The element of the list should be indexed by the variable of the generic function. As a result the list element will change as sapply moves through the list. Remeber that list elements are accessed using the double bracket notation: [[ ]]. The sapply is needed here because otherwise %in% would look for an 'L' in the entire list rather than element by element.
    5. The output of (d) will be a vector of TRUEs and FALSEs. For each entry that evaluates to TRUE, ifelse should assign the value 'present' to L. For each entry that evaluates to FALSE, ifelse should assign the value 'absent' to L.
    6. This whole process then needs to be repeated to create N, P, and K.
  2. When constructing a function for use with sapply try getting your ideas to work on a single element first before using it in sapply. Once you're successful then rewrite it as a generic function for use in sapply.

Cited references

Course Home Page


Jack Weiss
Phone: (919) 962-5930
E-Mail: jack_weiss@unc.edu
Address: Curriculum in Ecology, Box 3275, University of North Carolina, Chapel Hill, 27599
Copyright © 2012
Last Revised--September 20, 2012
URL: https://sakai.unc.edu/access/content/group/3d1eb92e-7848-4f55-90c3-7c72a54e7e43/public/docs/assignments/assign4.htm