CompGLM (version 2.0)

glm.comp: Conway-Maxwell Poisson GLM Fitting Function

Description

A function in similar format to glm which provides a linear form regressing on the parameters lambda and mu.

Usage

glm.comp(lamFormula, nuFormula = NULL, data, lamStart = NULL,
  nuStart = NULL, sumTo = 100L, method = "BFGS", ...)

Arguments

lamFormula

an object of class formula which determines the form of regression for the model parameter \(\lambda\). An offset can also be added in the formula.

nuFormula

an object of class formula which determines the form of regression for the model parameter \(\nu\). The default value is NULL meaning the formula is intercept only. An offset can also be added in the formula.

data

an optional data.frame containing the variables in the model. If not found in data, the variables are taken from environment(lamFormula).

lamStart

optional vector of starting values for the coefficients of the \(\lambda\) regression.

nuStart

optional vector of starting values for the coefficients of the \(\nu\) regression.

sumTo

an integer for the summation term in the density (default 100).

method

optimisation method passed to optim (default "BFGS").

...

further arguments to be passed to optim.

Value

An object of class 'Comp' which is a list with all the components needed for the relevant S3 class methods.

Details

A log link is used for regression of the model parameters \(\lambda\) and \(\nu\), that is: $$\log(\lambda) = \beta X$$ $$\log(\nu) = \zeta Y$$ where: \(\beta\) is the vector of coefficients for the parameter \(\lambda\), \(\zeta\) is the vector of coefficients for the parameter \(\nu\), \(X\) is the model matrix for the parameter \(\lambda\), and \(Y\) is the model matrix for the parameter \(\nu\).

The parameter vectors are calculated via maximum likelihood using the general optimisation function optim. A Poisson model will be fit using glm.fit and (unless starting values are supplied) the coefficients will be used as starting values for the parameter vector \(\beta\).

Several S3 functions have been implemented for model analysis print, coef, extractAIC, logLik, predict, and summary,

References

A Flexible Regression Model for Count Data, by Sellers & Shmueli, http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1127359

Examples

Run this code
# NOT RUN {
set.seed(1)
n <- 5000
x1 <- rnorm(n, -1.0, 0.5)
x2 <- rnorm(n, 1.0, 0.7)
x3 <- rnorm(n, 2.0, 0.4)
y <- rpois(n, exp(-0.5 + 0.3 * x1 + 0.8 * x2 + 0.2 * x3))
data <- data.frame(y, x1, x2, x3)
model <- glm.comp(y ~ ., data = data)
print(model)
summary(model)
coef(model)
head(predict(model))
AIC(model)
# }

Run the code above in your browser using DataCamp Workspace