Title: | Double Generalized Linear Models Extending Poisson Regression |
---|---|
Description: | Model estimation, dispersion testing and diagnosis of hyper-Poisson Saez-Castillo, A.J. and Conde-Sanchez, A. (2013) <doi:10.1016/j.csda.2012.12.009> and Conway-Maxwell-Poisson Huang, A. (2017) regression models. |
Authors: | Antonio Jose Saez-Castillo [aut], Antonio Conde-Sanchez [aut], Francisco Martinez [aut, cre] |
Maintainer: | Francisco Martinez <[email protected]> |
License: | GPL-2 |
Version: | 0.2.3 |
Built: | 2025-01-17 05:07:39 UTC |
Source: | https://github.com/franciscomartinezdelrio/dglmextpois |
Computes the Akaike's information criterion or the Schwarz's Bayesian criterion for hyper-Poisson Fits
## S3 method for class 'glm_hP' AIC(object, ..., k = 2) ## S3 method for class 'glm_hP' BIC(object, ...)
## S3 method for class 'glm_hP' AIC(object, ..., k = 2) ## S3 method for class 'glm_hP' BIC(object, ...)
object |
an object of class |
... |
optionally more fitted model objects. |
k |
numeric, the penalty per parameter to be used; the
default |
## Fit a hyper-Poisson model Bids$size.sq <- Bids$size ^ 2 fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) ## Obtain its AIC and BIC AIC(fit) BIC(fit)
## Fit a hyper-Poisson model Bids$size.sq <- Bids$size ^ 2 fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) ## Obtain its AIC and BIC AIC(fit) BIC(fit)
Computes the Akaike's information criterion or the Schwarz's Bayesian criterion for COM-Poisson Fits
## S3 method for class 'glm_CMP' AIC(object, ..., k = 2) ## S3 method for class 'glm_CMP' BIC(object, ...)
## S3 method for class 'glm_CMP' AIC(object, ..., k = 2) ## S3 method for class 'glm_CMP' BIC(object, ...)
object |
an object of class |
... |
optionally more fitted model objects. |
k |
numeric, the penalty per parameter to be used; the
default |
## Estimate a COM-Poisson model Bids$size.sq <- Bids$size ^ 2 fit <- glm.CMP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.nu = numbids ~ 1, data = Bids) ## Compute its AIC and BIC AIC(fit) BIC(fit)
## Estimate a COM-Poisson model Bids$size.sq <- Bids$size ^ 2 fit <- glm.CMP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.nu = numbids ~ 1, data = Bids) ## Compute its AIC and BIC AIC(fit) BIC(fit)
A dataset with bids received by U.S. firms.
Bids
Bids
A data frame with 126 rows and 13 variables:
doc no.
weeks
count
delta(1 if taken over)
bid Premium
institutional holdings
size measured in billions
legal restructuring
real restructuring
financial restructuring
regulation
white knight
Sanjiv Jaggia and Satish Thosar (1993) "Multiple Bids as a Consequence of Target Management Resistance", Review of Quantitative Finance and Accounting, 3(4), pp. 447-457.
A. Colin Cameron and Per Johansson (1997) "Count Data Regression Models using Series Expansions: with Applications", Journal of Applied Econometrics, 12, pp. 203-223.
Computes confidence intervals for one or more parameters in a glm_CMP
object.
## S3 method for class 'glm_CMP' confint(object, parm, level = 0.95, ...)
## S3 method for class 'glm_CMP' confint(object, parm, level = 0.95, ...)
object |
a fitted object of class inheriting from |
parm |
a specification of which parameters are to be given confidence intervals, either a vector of numbers or a vector of names. If missing, all parameters are considered. |
level |
the confidence level required. |
... |
additional argument(s) for methods. |
A matrix (or vector) with columns giving lower and upper confidence
limits for each beta
parameter. These will be labelled as
(1-level)/2 and 1 - (1-level)/2 in (by default 2.5% and 97.5%).
## Estimate the model Bids$size.sq <- Bids$size ^ 2 fit <- glm.CMP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.nu = numbids ~ 1, data = Bids) ## Compute confidence intervals confint(fit)
## Estimate the model Bids$size.sq <- Bids$size ^ 2 fit <- glm.CMP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.nu = numbids ~ 1, data = Bids) ## Compute confidence intervals confint(fit)
Computes confidence intervals for one or more parameters in a "glm_hP"
object.
## S3 method for class 'glm_hP' confint(object, parm, level = 0.95, ...)
## S3 method for class 'glm_hP' confint(object, parm, level = 0.95, ...)
object |
a fitted object of class inheriting from |
parm |
a specification of which parameters are to be given confidence intervals, either a vector of numbers or a vector of names. If missing, all parameters are considered. |
level |
the confidence level required. |
... |
additional argument(s) for methods. |
A matrix (or vector) with columns giving lower and upper confidence
limits for each beta
parameter. These will be labelled as
(1-level)/2 and 1 - (1-level)/2 in % (by default 2.5% and 97.5%).
## Estimate the model Bids$size.sq <- Bids$size ^ 2 fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) ## Compute confidence intervals for parameters confint(fit)
## Estimate the model Bids$size.sq <- Bids$size ^ 2 fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) ## Compute confidence intervals for parameters confint(fit)
An observation corresponds to the census tracts within 10-mile radius around certain store.
CustomerProfile
CustomerProfile
A data frame with 110 rows and 6 variables:
number of customer of the census tracts who visit the store.
number of housing units in the census tracts
average income in dollars
average housing unit in years
distance to the nearest competitor in miles
distance to store in miles
http://www.leg.ufpr.br/lib/exe/fetch.php/publications:papercompanions:ptwdataset4.txt
The hP_expected
and CMP_expected
functions calculate the
probability distribution of the count response variable Y for each observation
and obtain the corresponding expected frequencies. It is an informal way of
assessing the fit of the hP or CMP model by comparing the predicted
distribution of counts with the observed distribution.
hP_expected(object) CMP_expected(object)
hP_expected(object) CMP_expected(object)
object |
a fitted object of class inheriting from |
The average expected probabilities are computed as
The expected frequencies are obtained by multiplying by n.
Two measures are offered for summarizing the comparison between expected and observed frequencies: the sum of the absolute value of differences and the sum of the square of differences (similar to the Pearson statistic of goodness of fit).
A list containing the following components:
frequencies |
the expected counts for the hP or CMP fit. |
observed_freq |
the observed distribution. |
probabilities |
the expected distribution for the hP or CMP fit. |
dif |
sum of the absolute value of differences between
|
chi2 |
sum of the
square of differences between |
J. M. Hilbe (2011). Negative Binomial Regression. (2nd ed.). Cambridge University Press.
M. Scott Long and Jeremy Freese (2014). Regression Models for Categorical Dependent Variables using STATA. (3rd ed.). Stata Press.
## Fit a hyper-Poisson model Bids$size.sq <- Bids$size ^ 2 hP.fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) ## Compute the expected probabilities and the frequencies hP_expected(hP.fit) ## Estimate a COM-Poisson model Bids$size.sq <- Bids$size ^ 2 CMP.fit <- glm.CMP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.nu = numbids ~ 1, data = Bids) ## Compute the expected probabilities and the frequencies CMP_expected(CMP.fit)
## Fit a hyper-Poisson model Bids$size.sq <- Bids$size ^ 2 hP.fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) ## Compute the expected probabilities and the frequencies hP_expected(hP.fit) ## Estimate a COM-Poisson model Bids$size.sq <- Bids$size ^ 2 CMP.fit <- glm.CMP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.nu = numbids ~ 1, data = Bids) ## Compute the expected probabilities and the frequencies CMP_expected(CMP.fit)
The glm.CMP
function is used to fit a COM-Poisson double generalized
linear model with a log-link for the mean (mu
) and the dispersion
parameter (nu
).
glm.CMP( formula.mu, formula.nu, init.beta = NULL, init.delta = NULL, data, weights, subset, na.action, maxiter_series = 1000, tol = 0, offset, opts = NULL, model.mu = TRUE, model.nu = TRUE, x = FALSE, y = TRUE, z = FALSE )
glm.CMP( formula.mu, formula.nu, init.beta = NULL, init.delta = NULL, data, weights, subset, na.action, maxiter_series = 1000, tol = 0, offset, opts = NULL, model.mu = TRUE, model.nu = TRUE, x = FALSE, y = TRUE, z = FALSE )
formula.mu |
regression formula linked to |
formula.nu |
regression formula linked to |
init.beta |
initial values for regression coefficients of |
init.delta |
initial values for regression coefficients of |
data |
an optional data frame, list or environment (or object coercible
by |
weights |
an optional vector of ‘prior weights’ to be used in the
fitting process. Should be |
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
na.action |
a function which indicates what should happen when the data
contain |
maxiter_series |
Maximum number of iterations to perform in the calculation of the normalizing constant. |
tol |
tolerance with default zero meaning to iterate until additional terms to not change the partial sum in the calculation of the normalizing constant. |
offset |
this can be used to specify an a priori known component to be
included in the linear predictor during fitting. This should be |
opts |
a list with options to the optimizer,
|
model.mu |
a logical value indicating whether the mu model frame should be included as a component of the returned value. |
model.nu |
a logical value indicating whether the nu model frame should be included as a component of the returned value. |
x |
logical value indicating whether the mu model matrix used in the fitting process should be returned as a component of the returned value. |
y |
logical value indicating whether the response vector used in the fitting process should be returned as a component of the returned value. |
z |
logical value indicating whether the nu model matrix used in the fitting process should be returned as a component of the returned value. |
Fit a COM-Poisson double generalized linear model using as optimizer the
NLOPT_LD_SLSQP algorithm of function nloptr
.
glm.CMP
returns an object of class "glm_CMP"
. The
function summary
can be used to obtain or print a
summary of the results. An object of class "glm_CMP"
is a list
containing at least the following components:
coefficients |
a named vector of coefficients. |
residuals |
the residuals, that is response minus fitted values. |
fitted.values |
the fitted mean values. |
linear.predictors |
the linear fit on link scale. |
call |
the matched call. |
offset |
the offset vector used. |
weights |
the weights initially supplied,
a vector of |
y |
if requested (the default) the y vector used. |
matrix.mu |
if requested, the mu model matrix. |
matrix.nu |
if requested, the nu model matrix. |
model.mu |
if requested (the default) the mu model frame. |
model.nu |
if requested (the default) the nu model frame. |
nloptr |
an object of class |
Alan Huang (2017). "Mean-parametrized Conway–Maxwell–Poisson regression models for dispersed counts", Statistical Modelling, 17(6), pp. 359–380.
S. G. Johnson (2018). The nlopt nonlinear-optimization package
## Fit model Bids$size.sq <- Bids$size^2 fit <- glm.CMP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.nu = numbids ~ 1, data = Bids) ## Summary of the model summary(fit) ## To see termination condition of the optimization process fit$nloptr$message ## To see number of iterations of the optimization process fit$nloptr$iterations
## Fit model Bids$size.sq <- Bids$size^2 fit <- glm.CMP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.nu = numbids ~ 1, data = Bids) ## Summary of the model summary(fit) ## To see termination condition of the optimization process fit$nloptr$message ## To see number of iterations of the optimization process fit$nloptr$iterations
The glm.hP
function is used to fit a hyper-Poisson double generalized
linear model with a log-link for the mean (mu
) and the dispersion
parameter (gamma
).
glm.hP( formula.mu, formula.gamma, init.beta = NULL, init.delta = NULL, data, weights, subset, na.action, maxiter_series = 1000, tol = 0, offset, opts = NULL, model.mu = TRUE, model.gamma = TRUE, x = FALSE, y = TRUE, z = FALSE )
glm.hP( formula.mu, formula.gamma, init.beta = NULL, init.delta = NULL, data, weights, subset, na.action, maxiter_series = 1000, tol = 0, offset, opts = NULL, model.mu = TRUE, model.gamma = TRUE, x = FALSE, y = TRUE, z = FALSE )
formula.mu |
an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted. |
formula.gamma |
regression formula linked to |
init.beta |
initial values for regression coefficients of |
init.delta |
initial values for regression coefficients of |
data |
an optional data frame, list or environment (or object that can
be coerced by |
weights |
an optional vector of ‘prior weights’ to be used in the
fitting process. Should be |
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
na.action |
a function which indicates what should happen when the data
contain |
maxiter_series |
Maximum number of iterations to perform in the calculation of the normalizing constant. |
tol |
tolerance with default zero meaning to iterate until additional terms to not change the partial sum in the calculation of the normalizing constant. |
offset |
this can be used to specify an a priori known component to be
included in the linear predictor during fitting. This should be |
opts |
a list with options to the optimizer,
|
model.mu |
a logical value indicating whether the mu model frame should be included as a component of the returned value. |
model.gamma |
a logical value indicating whether the gamma model frame should be included as a component of the returned value. |
x |
logical value indicating whether the mu model matrix used in the fitting process should be returned as a component of the returned value. |
y |
logical value indicating whether the response vector used in the fitting process should be returned as a component of the returned value. |
z |
logical value indicating whether the gamma model matrix used in the fitting process should be returned as a component of the returned value. |
Fit a hyper-Poisson double generalized linear model using as optimizer the
NLOPT_LD_SLSQP algorithm of function nloptr
.
glm.hP
returns an object of class "glm_hP"
. The
function summary
can be used to obtain or print a
summary of the results.
The generic accessor functions coef
,
fitted.values
and residuals
can
be used to extract various useful features of the value returned by
glm.hP
.
weights
extracts a vector of weights, one for each case in the fit
(after subsetting and na.action
).
An object of class "glm_hP"
is a list containing at least the
following components:
coefficients |
a named vector of coefficients. |
residuals |
the residuals, that is response minus fitted values. |
fitted.values |
the fitted mean values. |
linear.predictors |
the linear fit on link scale. |
call |
the matched call. |
offset |
the offset vector used. |
weights |
the weights initially supplied, a
vector of |
df.residual |
the residual degrees of freedom. |
df.null |
the residual degrees of freedom for the null model. |
y |
if requested (the default) the y vector used. |
matrix.mu |
if requested, the mu model matrix. |
matrix.gamma |
if requested, the gamma model matrix. |
model.mu |
if requested (the default) the mu model frame. |
model.gamma |
if requested (the default) the gamma model frame. |
nloptr |
an object of class |
Antonio J. Saez-Castillo and Antonio Conde-Sanchez (2013). "A hyper-Poisson regression model for overdispersed and underdispersed count data", Computational Statistics & Data Analysis, 61, pp. 148–157.
S. G. Johnson (2018). The nlopt nonlinear-optimization package
## Fit model Bids$size.sq <- Bids$size ^ 2 fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) ## Summary of the model summary(fit) ## To see the termination condition of the optimization process fit$nloptr$message ## To see the number of iterations of the optimization process fit$nloptr$iterations
## Fit model Bids$size.sq <- Bids$size ^ 2 fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) ## Summary of the model summary(fit) ## To see the termination condition of the optimization process fit$nloptr$message ## To see the number of iterations of the optimization process fit$nloptr$iterations
Density, distribution function and random generation for the hyper-Poisson
distribution with parameters gamma
and lambda
.
dhP(x, gamma, lambda) phP(q, gamma, lambda, lower.tail = TRUE) rhP(n, gamma, lambda)
dhP(x, gamma, lambda) phP(q, gamma, lambda, lower.tail = TRUE) rhP(n, gamma, lambda)
x |
vector of (non-negative integer) quantiles. |
gamma |
dispersion parameter. Must be strictly positive. |
lambda |
location parameter. Must be strictly positive. |
q |
vector of quantiles. |
lower.tail |
logical; if |
n |
number of random values to return. |
dhP
gives the density, phP
gives the distribution
function and rhP
generates random deviates.
Invalid gamma
or lambda
will result in return value
NaN
, with a warning.
The length of the result is determined by n for rhP
, and is the
maximum of the lengths of the numerical arguments for the other functions.
The numerical arguments other than n
are recycled to the length of
the result. Only the first element of the logical arguments is used.
## density function for hyper-Poisson dhP(3, 15, 2) ## distribution function for hyper-Poisson phP(3, 15, 2) ## random generation for the hyper-Poisson rhP(10, 15, 2)
## density function for hyper-Poisson dhP(3, 15, 2) ## distribution function for hyper-Poisson phP(3, 15, 2) ## random generation for the hyper-Poisson rhP(10, 15, 2)
Performs the likelihood ratio chi-squared test to compare nested models.
lrtest(object1, object2)
lrtest(object1, object2)
object1 , object2
|
fitted objects of classes inheriting from
|
The test statistics is calculated as .
The test statistics has a chi-squared distribution with r degrees of freedom,
where r is the difference in the number of parameters between the full and
null models.
A list with class "lrtest"
containing the following components:
statistics |
the value of the statistic. |
df |
the degrees of freedom. |
p-value |
the p-value for the test. |
Bids$size.sq <- Bids$size ^ 2 ## Fit null model fit0 <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) ## Fit full model fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ leglrest, data = Bids) ## Likelihood ratio test for the nested models lrtest(fit,fit0)
Bids$size.sq <- Bids$size ^ 2 ## Fit null model fit0 <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) ## Fit full model fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ leglrest, data = Bids) ## Likelihood ratio test for the nested models lrtest(fit,fit0)
Two plots are currently available: a plot of residuals against fitted values and a Normal Q-Q plot.
## S3 method for class 'glm_hP' plot( x, type = c("quantile", "pearson", "response"), ask = prod(graphics::par("mfcol")) < 2 && grDevices::dev.interactive(), ... ) ## S3 method for class 'glm_CMP' plot( x, type = c("quantile", "pearson", "response"), ask = prod(graphics::par("mfcol")) < 2 && grDevices::dev.interactive(), ... )
## S3 method for class 'glm_hP' plot( x, type = c("quantile", "pearson", "response"), ask = prod(graphics::par("mfcol")) < 2 && grDevices::dev.interactive(), ... ) ## S3 method for class 'glm_CMP' plot( x, type = c("quantile", "pearson", "response"), ask = prod(graphics::par("mfcol")) < 2 && grDevices::dev.interactive(), ... )
x |
|
type |
the type of residuals. The alternatives are: "quantile" (default), "pearson" and "response". Can be abbreviated. |
ask |
logical; if TRUE, the user is asked before each plot, see
|
... |
other parameters to be passed through to plotting functions. |
## Fit the hyper-Poisson model Bids$size.sq <- Bids$size ^ 2 hP.fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) oldpar <- par(mfrow = c(1, 2)) ## Plot diagnostics plot(hP.fit) par(oldpar) ## Fit the COM-Poisson model Bids$size.sq <- Bids$size ^ 2 CMP.fit <- glm.CMP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.nu = numbids ~ 1, data = Bids) oldpar <- par(mfrow = c(1, 2)) ## Plot diagnostics plot(CMP.fit) par(oldpar)
## Fit the hyper-Poisson model Bids$size.sq <- Bids$size ^ 2 hP.fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) oldpar <- par(mfrow = c(1, 2)) ## Plot diagnostics plot(hP.fit) par(oldpar) ## Fit the COM-Poisson model Bids$size.sq <- Bids$size ^ 2 CMP.fit <- glm.CMP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.nu = numbids ~ 1, data = Bids) oldpar <- par(mfrow = c(1, 2)) ## Plot diagnostics plot(CMP.fit) par(oldpar)
Obtains predictions from a fitted glm_CMP
object.
## S3 method for class 'glm_CMP' predict(object, newdata = NULL, type = c("link", "response"), ...)
## S3 method for class 'glm_CMP' predict(object, newdata = NULL, type = c("link", "response"), ...)
object |
a fitted object of class inheriting from |
newdata |
optionally, a data frame in which to look for variables with which to predict. If omitted, the fitted linear predictors are used. |
type |
the type of prediction required. The default is on the scale of
the linear predictors; the alternative |
... |
further arguments passed to or from other methods. |
A vector with the prediction means.
## Fit a model Bids$size.sq <- Bids$size ^ 2 fit <- glm.CMP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.nu = numbids ~ 1, data = Bids) ## As the newdata parameter is not used the fitted values are obtained predict(fit, type = "response")
## Fit a model Bids$size.sq <- Bids$size ^ 2 fit <- glm.CMP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.nu = numbids ~ 1, data = Bids) ## As the newdata parameter is not used the fitted values are obtained predict(fit, type = "response")
Obtains predictions from a fitted "glm_hP"
object.
## S3 method for class 'glm_hP' predict(object, newdata = NULL, type = c("link", "response"), ...)
## S3 method for class 'glm_hP' predict(object, newdata = NULL, type = c("link", "response"), ...)
object |
a fitted object of class inheriting from |
newdata |
optionally, a data frame in which to look for variables with which to predict. If omitted, the fitted linear predictors are used. |
type |
the type of prediction required. The default is on the scale of
the linear predictors; the alternative |
... |
further arguments passed to or from other methods. |
A vector with the prediction means.
data(Bids) ## Fit a hype-Poisson model Bids$size.sq <- Bids$size ^ 2 fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) ## As the newdata parameter is not used the fitted values are obtained predict(fit, type = "response")
data(Bids) ## Fit a hype-Poisson model Bids$size.sq <- Bids$size ^ 2 fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) ## As the newdata parameter is not used the fitted values are obtained predict(fit, type = "response")
residuals is a method which extracts model residuals from a "glm_hP"
or "glm_CMP"
object, commonly returned by glm.hP
or
glm.CMP
. Optionally, it produces a half normal plot with a
simulated envelope of the residuals.
## S3 method for class 'glm_hP' residuals( object, type = c("pearson", "response", "quantile"), envelope = FALSE, rep = 19, title = "Simulated Envelope of Residuals", ... ) ## S3 method for class 'glm_CMP' residuals( object, type = c("pearson", "response", "quantile"), envelope = FALSE, rep = 19, title = "Simulated Envelope of Residuals", ... )
## S3 method for class 'glm_hP' residuals( object, type = c("pearson", "response", "quantile"), envelope = FALSE, rep = 19, title = "Simulated Envelope of Residuals", ... ) ## S3 method for class 'glm_CMP' residuals( object, type = c("pearson", "response", "quantile"), envelope = FALSE, rep = 19, title = "Simulated Envelope of Residuals", ... )
object |
an object of class |
type |
the type of residuals which should be returned. The alternatives are: "pearson" (default), "response" and "quantile". Can be abbreviated. |
envelope |
a logical value indicating whether the envelope should be computed. |
rep |
number of replications for envelope construction. Default is 19, that is the smallest 95 percent band that can be built. |
title |
a string indicating the main title of the envelope. |
... |
further arguments passed to or from other methods. |
The response residuals (), Pearson
residuals (
) or randomized
quantile residuals are computed. The randomized quantile residuals are
obtained computing the cumulative probabilities that the fitted model being
less than y and less or equal than y. A random value from a
uniform distribution between both probabilities is generated and the value of
the residual is the standard normal variate with the same cumulative
probability. Four replications of the quantile residuals are recommended
because of the random component (see Dunn and Smyth, 1996 for more details).
The functions plot.glm_hP
and plot.glm_CMP
generate a residuals against fitted values plot and a Normal Q-Q plot.
The Normal Q-Q plot may show an unsatisfactory pattern of the Pearson residuals of a fitted model: then we are led to think that the model is incorrectly specified. The half normal plot with simulated envelope indicates that, under the distribution of the response variable, the model is fine when only a few points fall off the envelope.
Residual values.
Peter K. Dunn and Gordon K. Smyth (1996). "Randomized quantile residuals". Journal of Computational and Graphical Statistics, 5(3), pp. 236-244.
A. C. Atkinson (1981). "Two graphical displays for outlying and influential observations in regression". Biometrika, 68(1), pp. 13–20.
## Estimate a hyper-Poisson model Bids$size.sq <- Bids$size ^ 2 hP.fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) ## Compute residuals r <- residuals(hP.fit) ## Estimate a COM-Poisson model Bids$size.sq <- Bids$size ^ 2 CMP.fit <- glm.CMP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.nu = numbids ~ 1, data = Bids) ## Compute its residuals r <- residuals(CMP.fit)
## Estimate a hyper-Poisson model Bids$size.sq <- Bids$size ^ 2 hP.fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) ## Compute residuals r <- residuals(hP.fit) ## Estimate a COM-Poisson model Bids$size.sq <- Bids$size ^ 2 CMP.fit <- glm.CMP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.nu = numbids ~ 1, data = Bids) ## Compute its residuals r <- residuals(CMP.fit)
These functions are all methods for class "glm_CMP"
or
summary.glm_CMP
objects.
## S3 method for class 'glm_CMP' summary(object, ...) ## S3 method for class 'summary.glm_CMP' print( x, digits = max(3, getOption("digits") - 3), signif.stars = getOption("show.signif.stars"), ... )
## S3 method for class 'glm_CMP' summary(object, ...) ## S3 method for class 'summary.glm_CMP' print( x, digits = max(3, getOption("digits") - 3), signif.stars = getOption("show.signif.stars"), ... )
object |
an object of class |
... |
further arguments passed to or from other methods. |
x |
an object of class |
digits |
the number of significant digits to use when printing. |
signif.stars |
logical. If |
## Fit a COM-Poisson model Bids$size.sq <- Bids$size^2 fit <- glm.CMP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.nu = numbids ~ 1, data = Bids) ## Obtain a summary of the fitted model summary(fit)
## Fit a COM-Poisson model Bids$size.sq <- Bids$size^2 fit <- glm.CMP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.nu = numbids ~ 1, data = Bids) ## Obtain a summary of the fitted model summary(fit)
These functions are all methods for class "glm_hP"
or
summary.glm_hP
objects.
## S3 method for class 'glm_hP' summary(object, ...) ## S3 method for class 'summary.glm_hP' print( x, digits = max(3, getOption("digits") - 3), signif.stars = getOption("show.signif.stars"), ... )
## S3 method for class 'glm_hP' summary(object, ...) ## S3 method for class 'summary.glm_hP' print( x, digits = max(3, getOption("digits") - 3), signif.stars = getOption("show.signif.stars"), ... )
object |
an object of class |
... |
further arguments passed to or from other methods. |
x |
an object of class |
digits |
the number of significant digits to use when printing. |
signif.stars |
logical. If |
## Fit a hyper-Poisson model Bids$size.sq <- Bids$size ^ 2 fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) ## Obtain a summary of the fitted model summary(fit)
## Fit a hyper-Poisson model Bids$size.sq <- Bids$size ^ 2 fit <- glm.hP(formula.mu = numbids ~ leglrest + rearest + finrest + whtknght + bidprem + insthold + size + size.sq + regulatn, formula.gamma = numbids ~ 1, data = Bids) ## Obtain a summary of the fitted model summary(fit)