.R), R markdown (.Rmd), or Sweave (.Rnw)setwd()rm(list=ls())attach()install.packages(...)Load the faraway package (install it first if necessary) and translate the discoveries data set to a more useful/general format (as loaded it is a time-series object, which has a single vector of values with the starting time and measurement frequency as attributes. R has some useful time-series analysis methods, but it will be easier to deal with in a GLM context as a data frame.
library(faraway)
dd <- data.frame(year=1860:1959,discoveries=c(discoveries))
Read the (very short!) help page: ?faraway.
broom::augment() and ggplot2::ggplot to construct three plots: residuals vs time, residuals vs fitted values, and a scale-location plot (\(\sqrt{|r_i|}\) vs. fitted value). Make sure you include both points and smooth lines. Interpret the plots.glmmTMB() to fit negative binomial response models that use both the linear (NB1, family=nbinom1) and quadratic (NB2, family=nbinom2) parameterizations of the negative binomial distribution. Compute the AIC values for the Poisson, NB1, and NB2 models and decide which model has the best expected predictive value: how big are the differences between the models?ziformula=~1 if you use glmmTMB, or discoveries ~ ... | 1 if you use pscl::zeroinfl (where ... represents the conditional/non-zero-inflated model formula). What is the estimated zero-inflation probability? (Note that zero-inflated models estimate this probability on the logit scale.)Read in the singingmouse_playback.csv data set (from Pasch, Bolker, and Phelps (2013)); compute a Bernoulli response variable [the original responses are on a count scale, but over a very small range: of 64 responses, 27 have 0 counts (number of vocalizations recorded), 30 have 1 count, and only 7 have 2 counts]. Use bresponse as your response variable for the following questions.
sm <- read.csv("singingmouse_playback.csv")
sm <- transform(sm, Stimulus= factor(Stimulus,
labels=c("pre","white","het","con")),
ID=factor(ID),
bresponse=as.numeric(Response>0))
brglm2 to do a more formal test of complete separation.arm::bayesglm() or brglm2 to fit a regularized version of the logistic model.dotwhisker::dwplot() works for brglm2-based fits, you’ll need arm::coefplot() for bayesglm fits).Pasch, Bret, Benjamin M. Bolker, and Steven M. Phelps. 2013. “Interspecific Dominance via Vocal Interactions Mediates Altitudinal Zonation in Neotropical Singing Mice.” The American Naturalist 182 (5): E161–E173. doi:10.1086/673263.