Advanced Modeling in R
Non-linear, Bayesian, and mixed effect methods
R. Condit∗
Smithsonian Tropical Research Institute, 7-9 May 2012
Assignments
- Fit a linear model with optim
- Functions llike.linearmodel, sumsq.linearmodel
- agb data: log(agb) as a function of log(dbh)
- Minimize either sum of squares or likelihood
- How many parameters?
- Fit a linear model with variable SD
- cecrin data: growth (gr12) as a function of diameter (dbh1)
- Minimize either sum of squares or likelihood
- How many parameters?
- Fit a non-linear model to quantitative data
- Model types
- treeheight: ht as a function of dbh (extract one species, eg quaras or tri2tu or
pri2co)
- Use data from a single species to estimate the 3 parameters using maximum
likelihood and a Gaussian error.
- y = Hmax (it’s in teaching.functions.r)
Hmax, a, and b are parameters, y is height and x is dbh.
- grwfull300: growth as a function of dbh
- y ∼ x + log(x) (write yourself)
- Error functions
- Try first with Gaussian error
- For growth rates, then use log-normal or Gamma error (but beware that growth
must then be > 0)
- Fit linear and non-linear models with Metropolis method
- Linear
- Test function linearfit.Bayes in file modelfitBayes.intro.r with any linear
model
- Plot parameter runs
- Find confidence limits
- Adapt linearfit.Bayes to asymptotic (or other model of your preference)
- Simulation: Create a simulated correlation and test how well lm fits the parameters
- The basics
- Define x from normal distribution
- Define slope and intercept parameters
- Define error with rnorm and sd
- Calculate y
- Use lm to estimate slope and intercept
- More information
- Evaluate impact of increasing error
- Evaluate impact of error in measuring x
- Evaluate impact of highly non-Gaussian x
- Advanced (extra credit)
- Test multiple regression, with x1 and x2 predictors
- Evaluate impact of correlation between x1 and x2
- Program a Gibbs sampler for tree height model
- Adapt survivalGibbs.r to linear model
- Test hierarchical linear model of growth in growthGibbsHier.r
- Graph all species responses on top of the forest-wide response
- Histogram of species responses (slope, intercept of linear model) in hierarchical
vs. non-hierarchical model
- Run lmer on growth data
- Linear model of log(growth) vs. log(dbh) with species a random effect
- Graph all species responses on top of the forest-wide response
- Compare results of lmer to Bayesian hierarchical model
- Run lmer on full growth data
- Linear model of log(growth) vs. log(dbh)
- Possible random or fixed effects: species, time period
- Run lmer on treemass data
- Linear model of log(agb) vs. log(dbh), or with rainfall, or dry season months
- Possible random or fixed effects: species, forest type