Christoph´s mixed R functions

This is a continuously updated file containing useful snippets of R code.

New!General collection of useful R functions, Version 2015-01-22

Multinomial models

When fitting multinomial models with the nnet package (multinom() function), it is sometimes desirable to increase the number of weights (especially when there is a large number of response categories). This may happen for example in the analysis of next-generation sequencing data. The Anova() function from John Fox´s package "car" can not deal with the MaxNWts argument and hence cannot be used for multinomial models with user-specified maximum number of weights. Below, I provide a function called Anova.multinom2, which allows MaxNWts to be set to any desirded number.
Anova for models with user-specified weights, fitted with the multinom() function

Nonlinear regression

In nonlinear regression situations, one often wishes to use power law functions of the form y=a+b*x^c. The following code allows starting estimates for this function to be estimated automatically.
New!Self-starting non-linear power law function in R

Model selection

StepAICc function for linear, generalized linear and mixed models

selMod function for model selection in mixed models

Contrast matrices

Working with orthogonal contrasts in R

Test for orthogonality of a contrast matrix

Linear mixed models

Extract lme ANOVAs from multiple models

Extract lme summaries from multiple models

Generalized linear mixed models

ANOVA method for lmer models

Time series analysis

A short introduction to time-series analysis in R


Creating publication-quality R Graphics

Ecological diversity

Calculate Shannon´s diversity index

Seed bank data analysis

Analyzing data from a seed bank study using R