Last Updated: 2019-04-16
Show your work. The response to each question should include all of the commands necessary to reproduce your results, and should be commented to give a naive reader an idea of the intent behind each section of code. Answers to questions should be clearly shown in the code output or spelled out in text or comments.
Before submitting your assignment, ensure that your code for each question works correctly when the lines are run in sequence, starting with an empty environment. You may submit either this R Markdown document with your code entered into the appropriate code blocks, or a regular R script with the question numbers as comments and the answers following. If you choose to Knit the R Markdown document to HTML or PDF, include those files with your submission (but it is not required that it Knit successfully).
Download the following data set, from Wielgus & Peebles (2014), and place it in your /data
directory: https://rewberl.github.io/nr592/assignments/data/wielgus2014.csv
You can read about the data and the analyses performed in the paper:
Wielgus, R. B., & Peebles, K. A. (2014). Effects of wolf mortality on livestock depredations. PLOS ONE, 9(12), e113505. doi: 10.1371/journal.pone.0113505
I converted and “tidied” the data from a Word document table in Table S1 of the article’s supporting information: https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0113505#s5
In addition, I also added time-lagged versions of three variables (cattleDepredated
, sheepDepredated
, and wolvesKilled
) to the CSV. Each of these variables were shifted forward one year, so that their values represent those of their respective variables for the previous year.
Load the data into R as wolf
.
# Load data
Examine the head, dimensions, and structure of the data frame.
For each of the following questions:
1. Choose and run the appropriate statistical test.
2. Report whether you reject or fail to reject the null hypothesis.
It is okay to create new data frames (such as subsets), variables, or vectors as needed to run your analyses.
Did Wyoming kill fewer wolves than Idaho each year, from 1996 to 2012?
Delete this and enter your response here.
Did the number of sheep depredated in Wyoming from 1995 to 2012 average over 15?
Delete this and enter your response here.
In Montana, was the number of cattle depredated associated with the total number of cattle, from 1987 to 2011?
Delete this and enter your response here.
If so, was this association positive or negative?
Delete this and enter your response here.
Run a linear regression using cattleDepredated
as your outcome variable and wolvesKilledL1
(the number of wolves killed the previous year) as your predictor. Assign the result to a variable.
Display the summary of your model object.
Does wolvesKilledL1
have a significant effect on cattleDepredated
?
Is its effect positive or negative?
What does this relationship mean, in plain language? Do you find it surprising?
Delete this and enter your response here.
Load the ggplot2
package.
Using ggplot()
, create a plot of your choice that shows the relationship between these two variables.
Use State
as a grouping variable in your plot. Optionally, use colors or fills to distinguish each State
.
Add a regression line for each group of values by State
.
Run an ANOVA using sheepDepredated
as your outcome variable, and: sheepDepredatedL1
, wolfPopulation
, wolvesKilledL1
, wolfBreedingPairs
, numberOfSheep
, and State
as your predictors (without interactions). Assign the result to a variable.
Display the summary of your model object.
Run Tukey’s Honest Significant Differences (HSD) test on the ANOVA model for the levels of State
.
Were any states significantly different from one another?
Delete this and enter your response here.
Examine the normal quantile-quantile plot for the ANOVA model.
Do you think the data look sufficiently close to a normal distribution?
Are there any outliers?
Delete this and enter your response here.