bergreg: BerG Regression for Count Data

Description Usage Arguments Details Value Author(s) References Examples

View source: R/berg_fit_function.R

Description

Fit of the BerG regression model via maximum likelihood for a new parameterization of this distribution that is indexed by the mean and the dispersion index.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
bergreg(
  formula,
  data,
  link = c("log", "sqrt", "identity"),
  link.phi = "log",
  disp.test = FALSE,
  optimizer = c("nloptr", "optim"),
  y = FALSE,
  x = FALSE,
  control = berg_control(...),
  ...
)

Arguments

formula

a simbolic description of the model, of type y ~ x for covariates in the mean submodel only or y ~ x | z to enter covariates in the dispersion index submodel. See details below.

data

an optional data frame containing the variables in the formula. By default the variables are taken from environment(formula).

link, link.phi

character; specification of the link function in the mean and dispersion index submodels. The links "log" (default), "sqrt", and "identity" can be used.

disp.test

logical; if TRUE, the function bergreg returns the test for constant dispersion.

optimizer

character; specification of the optimization algorithm. By default, estimates are obtained using sequential quadratic programming method via nloptr package ("nloptr"). However, it is also possible to obtain the estimates via the optim function ("optim").

y, x

logicals; if TRUE the corresponding components of the fit, response and model matrices, are returned.

control

a list of control arguments specified via berg_control (under development).

...

arguments passed to berg_control (under development).

Details

The basic formula is of type y ~ x1 + x2 + ... + xp which specifies the model for the mean response only with p explanatory variables. Following the syntax of the betareg package (Cribari-Neto and Zeileis, 2010), the model for the dispersion index, say in terms of z1, z2, ..., zk, is specified as y ~ x1 + x2 + ... + xp | z1 + z2 + ... +zk using functionalities inherited from package Formula (Zeileis and Croissant, 2010).

Value

The bergreg function returns an object of class "bergreg", which consists of a list with the following components:

coefficients

a list containing the elements "mean" and "dispersion," which consists of the estimates of the coefficients associated with the mean and the dispersion index, respectively.

fitted.values

a vector with the fitted means.

phi

a vector with the fitted dispersion indexes.

residuals

a vector of raw residuals (observed - fitted).

link

a list with elements "mean" and "dispersion" containing the link objects for the respective submodels.

vcov

asymptotic covariance matrix of the maximum likelihood estimator of the model parameters vector. Specifically, the inverse of the Fisher information matrix.

logLik

log-likelihood of the fitted model.

freq

expected frequencies after fitting the BerG regression.

nobs

the number of observations in the sample.

df.null

residual degrees of freedom in the null model (constant mean and dispersion), that is, n - 2.

df.residual

residual degrees of freedom in the fitted model.

feasible

logical; if TRUE, the estimates satisfy the constraints.

call

the function call.

formula

the formula used to specify the model in bergreg.

terms

a list with elements "mean", "dispersion" and "full" containing the terms objects for the respective models.

y

the response vector (if y = TRUE).

x

a list with elements "mean" and "dispersion" containing the model matrices from the respective models (if X = TRUE).

Author(s)

Rodrigo M. R. Medeiros <rodrigo.matheus@live.com>

References

Bourguignon, M. & Medeiros, R. (2021). A simple and useful regression model for fitting count data.

Cribari-Neto F, Zeileis A (2010). Beta regression in R. Journal of Statistical Software, 34, 1–24

Zeileis A, Croissant Y (2010). Extended model formulas in R: multiple parts and multiple responses. Journal of Statistical Software, 34, 1–13.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
## Not run: 
# Dataset: grazing
data(grazing)
head(grazing)

layout(matrix(c(1, 2, 1, 3), 2, 2))
# Response variable (Number of understorey birds)
barplot(table(grazing$birds), xlab = "Number of understorey birds", ylab = "Frequency")

# Explanatory variables
boxplot(birds ~ when, grazing, ylab = "Number of understorey birds",
        xlab = "When the bird count was conduct", pch = 16)
boxplot(birds ~ grazed, grazing, ylab = "Number of understorey birds",
        xlab = " Which side of the stockproof fence", pch = 16)
layout(1)

# Fit of the BerG regression model with varying dispersion
fit_disp <- bergreg(birds ~ when + grazed | when + grazed, data = grazing)
summary(fit_disp)

# Fit of the BerG regression model with constant dispersion
fit <- bergreg(birds ~ when + grazed, data = grazing, link.phi = "identity")
summary(fit)

# Diagnostic
layout(matrix(c(1, 3, 5, 2, 4, 5), 3, 2))
plot(fit, which = 1:5, ask = FALSE)
layout(1)

## End(Not run)

rdmatheus/bergreg documentation built on Dec. 22, 2021, 1:04 p.m.