HEAD
=======
>>>>>>> 6543c0c4e4108becf65f6577b8d4b862afdadf49
class: center, middle, inverse, title-slide # Lecture 8 ## Introduction to hierarchical models ###
WILD6900 (Spring 2021) --- ## Readings > Kéry & Schaub 73-82 --- class: inverse, center, middle # What are random effects? --- ## What are random effects? <br/> -- - Fixed effects are constant across observational units, random effects vary across units <br/> -- - Fixed effects are used when you are interested in the specific factor levels, random effects are used when you are interested in the underlying population <br/> -- - When factors levels are exhaustive, they are fixed. When they are a sample of the possible levels, they are random <br/> -- - Random effects are the realized values of a random variable <br/> -- - Fixed effects are estimated by maximum likelihood, random effects are estimated with shrinkage ??? Definitions from Gelman & Hill (2007) pg. 245 --- ## A simple linear model `$$\Large y_{ij} = \beta_{[j]} + \epsilon_i$$` `$$\Large \epsilon_i \sim normal(0, \tau)$$` -- - If `\(\beta_{[1]} = \beta_{[2]} = \beta_{[3]} = ...=\beta_{[J]}\)` -- ``` model { # Priors beta0 ~ dnorm(0, 0.33) tau ~ dgamma(0.25, 0.25) # Likelihood for (i in 1:N){ y[i] ~ dnorm(mu[i], tau) mu[i] <- beta0 } #i } ``` --- ## A simple linear model `$$\Large y_{ij} = \beta_{[j]} + \epsilon_i$$` `$$\Large \epsilon_i \sim normal(0, \tau)$$` -- - If `\(\beta_{[1]} \perp \beta_{[2]} \perp \beta_{[3]} \perp ...\perp \beta_{[J]}\)` -- ``` model { # Priors for(j in 1:J){ beta0[j] ~ dnorm(0, 0.33) } tau ~ dgamma(0.25, 0.25) # Likelihood for (i in 1:N){ y[i] ~ dnorm(mu[i], tau) mu[i] <- beta0[group[j]] } #i } ``` ??? nb `\(\perp\)` means "independent of" This should look familiar - it's the means parameterization of the ANOVA model --- ## A simple linear model `$$\Large y_{ij} = \beta_{[j]} + \epsilon_i$$` `$$\Large \epsilon_i \sim normal(0, \tau)$$` -- - If `\(\beta_{[j]} \sim normal(\mu_{\beta}, \tau_{\beta})\)` <img src="Lecture8_files/figure-html/unnamed-chunk-1-1.png" width="576" style="display: block; margin: auto;" /> --- ## A simple linear model `$$\Large y_{ij} = \beta_{[j]} + \epsilon_i$$` `$$\Large \epsilon_i \sim normal(0, \tau)$$` -- - If `\(\beta_{[j]} \sim normal(\mu_{\beta}, \tau_{\beta})\)` -- ``` model { # Priors for(j in 1:J){ beta0[j] ~ dnorm(mu.beta, tau.beta) } mu.beta ~ dnorm(0, 0.33) tau.beta ~ dgamma(0.25, 0.25) tau ~ dgamma(0.25, 0.25) # Likelihood for (i in 1:N){ y[i] ~ dnorm(mu[i], tau) mu[i] <- beta0[group[j]] } #i } ``` --- ## Random effects <br/> -- - Only apply to factors <br/> -- - Imply grouped effects <br/> -- - Can include intercept, slope, and variance parameters <br/> -- - Assume exchangeability <br/> -- - Represent a compromise between total pooling `\((\beta_{[1]}=\beta_{[2]}=...=\beta_{[J]})\)` and no pooling `\((\beta_{[1]} \perp \beta_{[2]} \perp ...\perp \beta_{[J]})\)` <br/> -- - Typically require `\(>5-10\)` factor levels --- ## Random effects = hierarchical model <br/> <br/> `$$\Large [\beta_{[j]}, \mu_{\beta}, \tau_{\beta}, \tau|y_{ij}] = [y_{ij}|\beta_{[j]}, \tau][\beta_{[j]}|\mu_{\beta}, \tau_{\beta}][\tau][\mu_{\beta}][\tau_{\beta}]$$` <br/> -- - Can include multiple random effects - Can include fixed and random effects (mixed-models) - Can include multiple levels of hierarchy --- ## Why use random effects? 1) Scope of inference - learn about `\(\beta_{[j]}\)` **and** `\(\mu_{\beta}\)`, `\(\tau_{\beta}\)` - prediction to unsampled groups (in space or time) --- ## Why use random effects? 1) Scope of inference 2) Partitioning of variance - Account for variability among groups vs. among observational units --- ## Why use random effects? 1) Scope of inference 2) Partitioning of variance 3) Accounting for uncertainty - modeling `\(\tau_{\beta}\)` recognizes uncertainty from sampling groups --- ## Why use random effects? 1) Scope of inference 2) Partitioning of variance 3) Accounting for uncertainty 4) Avoiding psuedo-replication - Account for non-independence within groups --- ## Why use random effects? 1) Scope of inference 2) Partitioning of variance 3) Accounting for uncertainty 4) Avoiding psuedo-replication 5) Borrowing strength - `\(\beta_{[j]}\)` estimating from group `\(j\)` observations + all other groups - "shrinkage"" towards mean + degree of shrinkage inversely proportional to precision --- ## Why not use random effects? #### Always use random effects (Gelman & Hill 2007) #### but... -- - Assumption of exchangeability <br/> -- - Requires 5-10 levels <br/> -- - Computationally intensive <br/> -- - Harder to interpret