MAR 580: Models for Marine Ecosystem-Based Management
TMB workshop
Session II
(Acknowledgements: Mollie Brooks, Kasper Kristensen, Arni Magnusson, Anders Nielsen, André Punt)
06 September 2022
Schedule
When should I use TMB?
When are numerical methods used?
Main types of problems:
Calculus
a
b
x
Numerical integration
Numerical integration: single step methods
Numerical integration
The error function, or how I learned to stop worrying & use someone else’s code.
Mixed effects models
Linear modeling review LMs, GLMs, NLMs
Quite flexible as it is
Any error distribution
Any relationship between Y and X
closed�form�solution
iterative�solution
What are Fixed and Random Effects?
Linear Mixed Effects Models
Vector of fixed effects
Vector of random effects
Observations for group i
The traditional linear modeling framework is a special case of
of this model in which there are no random effects.
Example 1: Streams�(sensu Pinherio and Bates, Chapter 1)
Example 1: Streams mixed effects model
Fitting linear mixed effects models
These estimates are similar to the linear model with separate “stream effects” (but would not be if this was an unbalanced design).
Mixed Effects Models (Some notes)
Estimation of mixed effects models
Maximum Likelihood Estimation (MLE)
is the vector of fixed effects parameters.
are the parameters controlling the distribution for the random effects.
We integrate across the random effects.
Effectively weight the probability of the observations given values for random effects by the probability of those values.
In the linear case, closed form solutions exist. For nonlinear models, we evaluate numerically or use approximations.
Estimating using R
lme() output
among stream variation
within stream variation
fixed effects
Extending the linear mixed model
Non-linear Mixed Effects Models
Fitting non-linear mixed effects models
Skaug & Fournier (2006), Thorson & Minto (2015)
Random effects in TMB
Streams model
Exercise: Poisson GLMM�Summer flounder recreational catch per trip
We have data on the number of flounder caught on observed samples of angling trips across the Atlantic states. The number of sampled trips is uneven by state.
Fit a mixed-effects model for the catch per trip by state. Assume that the number of fish caught on a trip is Poisson distributed, with an intercept and a state-specific random effect.�Report values for estimated parameters and their variance. Compare the fit to a model with a single intercept and no random effects for state.
Exercise: Growth estimation from lengths at release and recapture
Parameters:
Data
Length 1
Length 2
dt
For each fish:
Mu_L1 (eq 3.5a)
Mu_L2 (eq 3.5b)
Sigma_L1 (eq 3.5c)
Sigma_L2 (eq 3.5d)
Cov_L1L2 (eq 3.5e)
MVNORM LIKELIHOOD