Skip to content

Commit

Permalink
Adding week 06 lecture, lab, and data
Browse files Browse the repository at this point in the history
  • Loading branch information
eveskew committed Mar 2, 2020
1 parent b86fd0d commit ccc67fe
Show file tree
Hide file tree
Showing 4 changed files with 480 additions and 0 deletions.
101 changes: 101 additions & 0 deletions data/simulated_trees.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"height","age"
685,82
1202,232
1072,147
667,132
1441,190
1439,167
628,86
1328,223
964,173
1045,199
1047,112
736,161
1252,170
678,106
900,148
1341,181
1461,169
722,96
937,143
573,64
1149,149
879,140
1319,194
647,108
839,125
977,124
645,129
847,146
1436,242
1494,189
510,101
659,56
1285,179
1485,188
997,94
1105,211
1314,181
774,109
1142,162
644,106
1443,256
785,160
610,62
656,64
1403,173
1259,158
1430,263
833,125
978,126
1271,176
506,103
513,83
1148,164
1381,188
760,92
1268,241
1242,210
1433,265
1078,151
1168,166
1224,158
1333,194
1086,175
744,146
1304,210
909,148
862,160
931,168
704,108
561,65
756,144
788,122
539,124
671,90
669,74
1199,193
766,98
1301,211
871,88
1028,111
822,141
1118,176
523,100
868,80
683,133
1284,223
1388,234
795,139
1169,228
810,85
1389,194
861,139
845,107
1008,153
920,157
1487,207
886,149
584,101
604,70
896,109
78 changes: 78 additions & 0 deletions lab/lab_week_06.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
title: "EEEB UN3005/GR5005 \nLab - Week 06 - 02 and 04 March 2020"
author: "USE YOUR NAME HERE"
output: pdf_document
fontsize: 12pt
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(rethinking)
library(dplyr)
library(ggplot2)
```


# Gaussian Regression Models

This week we'll be working with simulated data that's based on a real ecological research scenario. Tree age (in years) can be evaluated using tree core data, while tree height (in centimeters) can be remotely sensed using LIDAR technology. Given some initial data relating tree age and tree height, a researcher interested in tree population demography might reasonably want to estimate tree age based on tree height, avoiding the time, expense, and labor associated with the field work needed to collect tree core data.


## Exercise 1: Importing and Visualizing Tree Age Data

First, import the `simulated_trees.csv` dataset into R. This data contains tree height and age variables. Visualize the tree age variable using a plot type of your choice.

```{r}
```


## Exercise 2: Fitting a Gaussian Model of Tree Age

Now, construct a Gaussian model of tree age, and use `map()` to fit the model. Assume priors of `dnorm(0, 50)` for the mean parameter and `dcauchy(0, 5)` for the standard deviation parameter. Visualize these priors before you fit your model. To ensure a good model fit, you will likely need to explicitly define starting values: 0 for the mean parameter and 40 for the standard deviation parameter.

After fitting the model, use `precis()` to display the 99% PIs for all model parameters. How do you interpret the fit model parameters?

```{r}
```


## Exercise 3: Fitting a Linear Regression of Tree Age

Now, use tree `height` as a predictor of tree `age` in a linear regression model. Assume priors of `dnorm(0, 50)` for the intercept parameter, `dnorm(0, 50)` for the slope parameter, and `dcauchy(0, 5)` for the standard deviation parameter. To ensure a good model fit, you will likely need to explicitly define starting values: 0 for the intercept and slope parameters and 40 for the standard deviation parameter. Again, use `map()` to fit the model.

After fitting the model, use `precis()` to summarize the 99% PIs for all model parameters. What does the estimated value of the slope parameter suggest about the relationship between tree height and tree age? What does the intercept parameter correspond to in this model?

```{r}
```


## Exercise 4: Plotting Raw Data and the *Maximum a Posterior* Trend Line

Using either base R or `ggplot()`, plot tree age versus tree height, and add the *maximum a posterior* line for the estimated mean age at each tree height value. In other words, this line is the relationship between tree height and mean age implied by the *maximum a posterior* intercept and slope estimates from your fit model.

```{r}
```


## Exercise 5: Generating Tree Age Predictions

Generate 10,000 posterior samples from your fit model from Exercise 3 with `extract.samples()`. Using these samples, make 10,000 age predictions for a tree with a height of 1,200 centimeters. What is the mean value of these age predictions? What is the 50% HPDI of these age predictions? Plot the density of these age predictions.

```{r}
```


## Bonus Exercise: Visualizing Uncertainty in the Posterior

Recreate the plot from Exercise 4, but instead of overlaying the *maximum a posterior* trend line, overlay the trend lines implied by the first 100 posterior samples.

```{r}
```
Loading

0 comments on commit ccc67fe

Please sign in to comment.