-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhw_week_07.Rmd
65 lines (34 loc) · 4.1 KB
/
hw_week_07.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
title: "EEEB UN3005/GR5005 \nHomework - Week 07 - Due 07 Apr 2020"
author: "USE THE NUMERIC PORTION OF YOUR UNI HERE"
output: pdf_document
fontsize: 12pt
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(rethinking)
library(dplyr)
library(ggplot2)
```
**Homework Instructions:** Complete this assignment by writing code in the code chunks provided. If required, provide written explanations **below** the relevant code chunks. Replace "USE THE NUMERIC PORTION OF YOUR UNI HERE" in the document header with the numbers appearing in your UNI. When complete, knit this document within RStudio to generate a PDF file. Please review the resulting PDF to ensure that all content relevant for grading (i.e., code, code output, and written explanations) appears in the document. Rename your PDF document according to the following format: hw_week_07_UNInumbers.pdf. Upload this final homework document to CourseWorks by 5 pm on the due date.
All of the following homework problems will use a dataset called `simulated_falcons.csv` which contains wingspan measures (in centimeters) for male and female falcons. For any problems that ask you to create statistical models, use priors of `dnorm(0, 100)` for all intercept and beta coefficient parameters and a prior of `dcauchy(0, 10)` for all standard deviation parameters. Use explicit start values of 0 for all model parameters to ensure a good model fit. In addition, **you will have to use** `method = "SANN"` as an additional argument to `map()` to ensure all these models fit correctly. This additional argument simply indicates a particular parameter search method for `map()`. By default, `map()` uses `method = "BFGS"`, so we have to specify we want to use a different `method`. This bit of code will just be an extra part of your `map()` call in addition to your `data`, model code, and `start` arguments.
## Problem 1 (2 points)
Import the `simulated_falcons` dataset, and create a jitter plot with the `sex` variable ("female" or "male") on the x-axis and the `wingspan` variable on the y-axis. This should give you an idea as to the variation in falcon wingspan values both between and within sexes.
```{r}
```
## Problem 2 (2 points)
Now fit a basic Gaussian model (i.e., with no predictors) with wingspan as the outcome variable, and report the 99% PIs for all model parameters using `precis()`.
Based on these parameter posterior estimates, your visualization in Problem 1, and any other analyses/calculations you'd like to provide, do you think this model provides a good description of the data? Why or why not?
```{r}
```
## Problem 3 (3 points)
Now fit a linear regression model with sex as a predictor of mean falcon wingspan. This is the same as the book and lecture examples using a categorical predictor variable in a linear regression. Note, since the falcon sex variable is currently represented as a factor in the `simulated_falcons` dataset, you'll have to create a dummy variable for sex to use within your model. You can generate the dummy variable as you wish, coding either "male" or "female" with a value of 1. After you've fit the model, report the 99% PIs for all model parameters.
Based on these model results and any other analyses/calculations you'd like to provide, do you think this model provides a better description of the data than the model from Problem 2? Why or why not?
```{r}
```
## Problem 4 (3 points)
And now we come to a bit of a challenge.
Can you fit a model that assumes falcon wingspan is a Gaussian outcome where both the mean wingspan AND the standard deviation in wingspan differs by sex? If you're able to fit the model for Problem 3, you have all of the conceptual tools needed to tackle this problem too. Think about how we go about modeling the Gaussian mean parameter in a typical linear regression model and apply those same strategies to modeling the standard deviation parameter...
Once you've fit the model, summarize all model parameters using 99% PIs. What do the parameter estimates indicate about the standard deviation in wingspan of male versus female falcons? Would you interpret this as a strong or weak effect?
```{r}
```