Ecol 596W – Programming for Data Analysis in R
Spring semester 2016
R Course Homework
Due Friday, April 22.
Your final homework assignment is a short set of drills. See the script here: R Class_HW11.R
Due Friday, April 15.
1) Read Part 4 of the Custom Functions tutorial: Developing from blank screen to custom function.
2) Create the boot_power() custom function described in this pdf: R Class HW10.pdf.
*As you work, write down any questions that you’d like me to cover in class.
Due Friday, April 8. The assignment is Part 1 of Class Exercise 3 (bootstrap power analysis), which is in dropbox. Part 1 is building the custom t-test function. See the CE3 script and this homework document: R Class HW09.pdf.
The assignment is problem 6 in Class Exercise 2 (LiDAR looping): adding summary stats data frames to each lidar survey sublist. Due Mar 26. Each survey sublist contains four transect matrices and you want summary stats about the four transects in a single data frame (one data frame for each survey). This PDF shows our progress on ClassEx 2 so far.
It might help to visualize the data structure. Below is an image.plot() of one of the transects. This is a “heat map” created directly from the matrix data. The y axis is height in the forest, x axis is distance along the transect, and ‘heat color’ is the leaf-area-density (leaf area per volume). The white pixels represent missing data (NAs). Problem six asks you to get summary data such as the mean leaf-area-density at each height.
Problem 6 is copied here:
# Loop to add summary stats data frames to each survey sub-list
# (6) Stats table:
# – We want a summary table that contains statistics for each height (1m – 60m) from each
# transect matrix.
# – In each sub-list, create a stats data frame with one column for height. Name the data
# frames ‘s1.stats’ and ‘s2.stats’.
# – Use an inner loop to get the stats from each matrix into the stats data frame.
# — For each matrix, there should be three stats columns for the sums, means, and
# maximums for each row (height): e.g., ‘t1.max.lad’, ‘t1.sum.lad’, ‘t1.mean.lad’. So
# you’ll also get stats for t2, t3, and t4.
# — You can even create the named columns using this loop by df[[paste0(t,”stat.col”)]].
# — For sums and means, look up rowSums(). These are vectorized, so they’ll give you all
# the row sums from a matrix all at once.
# — For max, well, there’s no vectorized function for that! So, you know what to do…
# — IMPORTANT NOTE: Meter 1 is in row 1 of each lidar matrix, so height matches row num.
This assignment is to practice with nested for loops, and to see the Central Limit Theorem at work. Due this Friday, Mar 11. PDF download: R Class HW07.pdf.
This assignment is to practice for-loops in the context of Poisson distributions. Due this Friday, Mar 4th. Download the assignment here: R Class HW06.pdf.
Part 1 (complete by next class): Complete on your own, Tutorial 2 Indexing, Part 6 subparts “NA and NaN”; “Indexing with grep()”; and “Joining datasets with merge()”. Use the latest tutorial versions in the dropbox, v160212.
Part 2 (due in two weeks, Fri 26th): A fairly open-ended assignment to work with your own data. Please read the guidelines in the homework PDF here: R Class HW05.pdf. You will also need the function in this script, which I will demo how to use in class: scramble_csv.R. Feel free to email me with any questions.
Part 1: Complete on your own, Tutorial 2 Indexing, Part 2 subpart “Using objects for indexing” through Part 3 subpart “Creating matrices”. Stop before “One-dimensional indexing: using a matrix like a vector”. Here is a printable version of the Indexing tutorial: R_Indexing_160128.pdf. YOU MAY IGNORE THE “INTERMISSION” PROBLEMS. However, if you want more practice with what we’ve been learning, they make a nice set of drills! Answers to them are at the bottom of the completed tutorial.
Part 2: Complete and submit this problem set to your dropbox folder: R Class HW04.R. This problem set is adapted from Brian McGill’s biostats class materials. Here is an accompanying PowerPoint with a few slides explaining the tests in the assignment: R Class HW04_stats.pptx.
Part 1: Complete on your own, Tutorial 2 Indexing, Part 2 through section “<< the which() function >>”. Stop at “<< A note on vectorization >>”. Here is a printable version of that section: T2 Indexing_Part 2 through which funtcion.pdf. Nothing to submit for this part of the homework. Ignore the POP QUIZ and ‘class exercise’.
Part 2: Complete and submit this problem set to your dropbox folder: R Class HW03.R