Skip to contents

Functions to create a Mean-Variance plot for checking the distribution assumptions of the mean and the variance. Distributions available are Gaussian, Poisson, QuasiPoisson, Gamma and Tweedie.

Usage

plotMeanVar(model, cut.bins = 20, save = FALSE, label = NULL, print = TRUE)

Arguments

model

Fitted model object (glm or gam)

save

(default=FALSE). Logical stating whether plot should be saved into working directory. See label to change directory.

label

Character string indicating an label to be added to the plot when using save = TRUE. Can also include a pathway to a directory of choice.

print

Logical stating whether or not to print the plot. If FALSE then the plot object is returned.

cut.prob.by

Numerical input to state the increment for the sequence of cut probabilities.

Value

A plot showing the observed mean and variance (cutting the fitted values into bins and finding the mean fitted value and the variance for each bin) and the assumed relationship under various distributions depending on the model fitted (lines on the plot).

Examples

# load data
data(ns.data.re)

model<-glm(birds ~ observationhour + as.factor(floodebb) + as.factor(impact), 
           family='quasipoisson', data=ns.data.re)

plotMeanVar(model)
#> Error in ggplot(): could not find function "ggplot"