class-methods {cplm} | R Documentation |

## Classes and Methods for a Compound Poisson Linear Model Object

### Description

Documented here are the `"cplm"`

class and its derived classes `"cpglm"`

, `"cpglmm"`

, and `"bcplm"`

. Several primitive methods and statistical methods are created to facilitate the extraction of specific slots and further statistical analysis. `"gini"`

is a class that stores the Gini indices and associated standard errors that could be used to perform model comparison involving the compound Poisson distribution. `"NullNum"`

, `"NullList"`

, `"NullFunc"`

and `"ListFrame"`

are virtual classes for `c("NULL", "numeric")`

, `c("NULL","list")`

, `c("NULL","function")`

and `c("list","data.frame")`

, respectively.

### Objects from the Class

`"cplm"`

Objects can be created by calls of the form

`new("cplm", ...)`

.`"cpglm"`

Objects can be created by calls from

`new("cpglm", ...)`

or`cpglm`

.`"cpglmm"`

Objects can be created by calls of the form

`new("cpglmm", ...)`

, or a call to`cpglmm`

.`"summary.cpglmm"`

Objects can be created by calls of the form

`new("summary.cpglmm", ...)`

, or a call to`summary`

on a`cpglmm`

object.`"bcplm"`

Objects can be created by calls from

`new("bcplm", ...)`

or`bcplm`

.`"gini"`

Objects can be created by calls from

`new("gini", ...)`

or`gini`

.`"NullNum"`

,`"NullList"`

,`"NullFunc"`

These are virtual classes and no objects may be created from them.

### Slots

The `"cplm"`

class defines the slots common in all the model classes in the `cplm`

package, and thus the utility methods defined on the `"cplm"`

class such as `[`

, `names`

and so on are applicable to all of the derived classes.

`call`

:the matched call.

`formula`

:the formula supplied, class

`"formula"`

`contrasts`

:the contrasts used, class

`"NullList"`

`link.power`

:index of power link function, class

`"numeric"`

. See`tweedie`

.`model.frame`

:the data frame used. class

`"ListFrame"`

.`inits`

:initial values used, class

`"NullList"`

.

The `"cpglm"`

class extends `"cplm"`

directly. Most of the slots have the same definition as those in `glm`

. The following slots are in addition to those in `"cplm"`

:

`coefficients`

:estimated mean parameters, class

`"numeric"`

.`residuals`

:the working residuals, that is the residuals in the final iteration of the IWLS fit, class

`"numeric"`

`fitted.values`

:the fitted mean values, obtained by transforming the linear predictors by the inverse of the link function, class

`"numeric"`

`linear.predictors`

:the fitted linear predictors, class

`"numeric"`

`weights`

:working weights from the last iteration of the iterative least square, class

`"numeric"`

`df.residual`

:residual degrees of freedom, class

`"integer"`

`deviance`

:up to a constant, minus twice the maximized log-likelihood. Where sensible, the constant is chosen so that a saturated model has deviance zero. This is computed using

`tweedie.dev`

.`aic`

:a version of Akaike's Information Criterion, minus twice the maximized log-likelihood plus twice the number of mean parameters. This is computed using the tweedie density approximation as in

`dtweedie`

.`offset`

:the offset vector used, class

`"NullNum"`

,`prior.weights`

:the weights initially supplied, a vector of

`1`

s if none were, class`"NullNum"`

`y`

:the response vector used.

`control`

:the value of the control argument used, class

`"list"`

`p`

:the maximum likelihood estimate of the index parameter.

`phi`

:the maximum likelihood estimate of the dispersion parameter.

`vcov`

:estimated variance-covariance matrix, class

`"matrix"`

`iter`

:the number of Fisher's scoring iterations in the final GLM.

`converged`

:indicating whether the algorithm has converged, class

`"logical"`

.`na.action`

:method of handling

`NA`

's, class`"NullFunc"`

.

The `"cpglmm"`

class extends `"cplm"`

and the old version of `"mer"`

class from `lme4`

directly, and has the following additional slots:

`p`

:estimated value of the index parameter, class

`"numeric"`

`phi`

:estimated value of the dispersion parameter, class

`"numeric"`

`bound.p`

:the specified bounds of the index parameter, class

`"numeric"`

`vcov`

:estimated variance-covariance matrix, class

`"matrix"`

`smooths`

:a list of smooth terms

The slots it used from the old `"mer"`

class has the following slots (copied from `lme4_0.999999-2`

):

`env`

:An environment (class

`"environment"`

) created for the evaluation of the nonlinear model function.`nlmodel`

:The nonlinear model function as an object of class

`"call"`

.`frame`

:The model frame (class

`"data.frame"`

).`call`

:The matched call to the function that created the object. (class

`"call"`

).`flist`

:The list of grouping factors for the random effects.

`X`

:Model matrix for the fixed effects.

`Zt`

:The transpose of model matrix for the random effects, stored as a compressed column-oriented sparse matrix (class

`"dgCMatrix"`

).`pWt`

:Numeric prior weights vector. This may be of length zero (0), indicating unit prior weights.

`offset`

:Numeric offset vector. This may be of length zero (0), indicating no offset.

`y`

:The response vector (class

`"numeric"`

).`Gp`

:Integer vector of group pointers within the random effects vector. The elements of

`Gp`

are 0-based indices of the first element from each random-effects term. Thus the first element is always 0. The last element is the total length of the random effects vector.`dims`

:A named integer vector of dimensions. Some of the dimensions are

`n`

, the number of observations,`p`

, the number of fixed effects,`q`

, the total number of random effects,`s`

, the number of parameters in the nonlinear model function and`nt`

, the number of random-effects terms in the model.`ST`

:A list of S and T factors in the TSST' Cholesky factorization of the relative variance matrices of the random effects associated with each random-effects term. The unit lower triangular matrix,

`T`

, and the diagonal matrix,`S`

, for each term are stored as a single matrix with diagonal elements from`S`

and off-diagonal elements from`T`

.`V`

:Numeric gradient matrix (class

`"matrix"`

) of the nonlinear model function.`A`

:Scaled sparse model matrix (class

`"dgCMatrix"`

) for the the unit, orthogonal random effects,`U`

.`Cm`

:Reduced, weighted sparse model matrix (class

`"dgCMatrix"`

) for the unit, orthogonal random effects, U. .`Cx`

:The

`"x"`

slot in the weighted sparse model matrix (class`"dgCMatrix"`

) for the unit, orthogonal random effects,`U`

, in generalized linear mixed models. For these models the matrices`A`

and`C`

have the same sparsity pattern and only the`"x"`

slot of`C`

needs to be stored.`L`

:The sparse lower Cholesky factor of

`P(AA'+I)P'`

(class`"dCHMfactor"`

) where`P`

is the fill-reducing permutation calculated from the pattern of nonzeros in`A`

.`deviance`

:Named numeric vector containing the deviance corresponding to the maximum likelihood (the

`"ML"`

element) and`"REML"`

criteria and various components. The`"ldL2"`

element is twice the logarithm of the determinant of the Cholesky factor in the`L`

slot. The`"usqr"`

component is the value of the random-effects quadratic form.`fixef`

:Numeric vector of fixed effects.

`ranef`

:Numeric vector of random effects on the original scale.

`u`

:Numeric vector of orthogonal, constant variance, random effects.

`eta`

:The linear predictor at the current values of the parameters and the random effects.

`mu`

:The means of the responses at the current parameter values.

`muEta`

:The diagonal of the Jacobian of

`\mu`

by`\eta`

. Has length zero (0) except for generalized mixed models.`var`

:The diagonal of the conditional variance of

`Y`

given the random effects, up to prior weights. In generalized mixed models this is the value of the variance function for the`glm`

family.`resid`

:The residuals,

`y - \mu`

, weighted by the`sqrtrWt`

slot (when its length is`>0`

).`sqrtXWt`

:The square root of the weights applied to the model matrices

`X`

and`Z`

. This may be of length zero (0), indicating unit weights.`sqrtrWt`

:The square root of the weights applied to the residuals to obtain the weighted residual sum of squares. This may be of length zero (0), indicating unit weights.

`RZX`

:The dense solution (class

`"matrix"`

) to`L RZX = ST'Z'X = AX`

.`RX`

:The upper Cholesky factor (class

`"matrix"`

) of the downdated`X'X`

.

The `"summary.cpglmm"`

class *contains* the `"cpglmm"`

class and has the following additional slots:

`methTitle`

:character string specifying a method title

`logLik`

:the same as

`logLik(object)`

.`ngrps`

:the number of levels per grouping factor in the

`flist`

slot.`sigma`

:the scale factor for the variance-covariance estimates

`coefs`

:the matrix of estimates, standard errors, etc. for the fixed-effects coefficients

`REmat`

:the formatted Random-Effects matrix

`AICtab`

:a named vector of values of AIC, BIC, log-likelihood and deviance

The `"bcplm"`

class extends `"cplm"`

directly, and has the following additional slots:

`dims`

:a named integer vector of dimensions.

`sims.list`

:an object of class

`"mcmc.list"`

. It is a list of`n.chains`

`mcmc`

objects, each`mcmc`

object storing the simulation result from a Markov chain. See`mcmc`

and`mcmc.convert`

. Since this is an`"mcmc.list"`

object, most methods defined in the`coda`

package can be directly applied to it.`Zt`

:the transpose of model matrix for the random effects, stored as a compressed column-oriented sparse matrix (class

`"dgCMatrix"`

).`flist`

:the list of grouping factors for the random effects.

`prop.var`

:a named list of proposal variance-covariance matrix used in the Metropolis-Hasting update.

The `"gini"`

class has the following slots:

`call`

:the matched call.

`gini`

:a matrix of the Gini indices. The row names are corresponding to the base while the column names are corresponding to the scores.

`sd`

:a matrix of standard errors for each computed Gini index.

`lorenz`

:a list of matrices that determine the graph of the ordered Lorenz curve associated with each base and score combination. For each base, there is an associated matrix.

### Extends

Class `"cpglm"`

extends class `"cplm"`

, directly.

Class `"cpglmm"`

extends class `"cplm"`

, directly;

Class `"summary.cpglmm"`

extends class `"cpglmm"`

, directly;
class `"cplm"`

, by class `"cpglmm"`

, distance 2.

Class `"bcplm"`

extends class `"cplm"`

, directly.

### Methods

The following methods are defined for the class `"cplm"`

, which are also applicable to all of the derived classes:

- $
`signature(x = "cplm")`

: extract a slot of`x`

with a specified slot name, just as in list.- [[
`signature(x = "cplm", i = "numeric", j = "missing")`

: extract the i-th slot of a`"cpglm"`

object, just as in list.- [[
`signature(x = "cplm", i = "character", j = "missing")`

: extract the slots of a`"cpglm"`

object with names in`i`

, just as in list.- [
`signature(x = "cplm", i = "numeric", j = "missing", drop="missing")`

: extract the i-th slot of a`"cpglm"`

object, just as in list.`i`

could be a vector.- [
`signature(x = "cplm", i = "character", j = "missing", drop="missing")`

: extract the slots of a`"cpglm"`

object with names in`i`

, just as in list.`i`

could be a vector.- names
`signature(x = "cplm")`

: return the slot names.- terms
`signature(x = "cplm")`

: extract the`terms`

object from the model frame. See`terms`

.- formula
`signature(x = "cplm")`

: extract the`formula`

slot. See`formula`

.- model.matrix
`signature(object = "cplm")`

: extract the design matrix.- show
`signature(object = "cplm")`

: method for`show`

.- vcov
`signature(object = "cplm")`

: extract the variance-covariance matrix of a`"cplm"`

object.

The following methods are defined for the `"cpglm"`

class:

- coef
`signature(object = "cpglm")`

: extract the estimated coefficients.- fitted
`signature(object = "cpglm")`

: return the fitted values.- residuals
`signature(object = "cpglm")`

: extract residuals from a`cpglm`

object. You can also specify a`type`

argument to indicate the type of residuals to be computed. See`glm.summaries`

.- resid
`signature(object = "cpglm")`

: same as`residuals`

.- AIC
`signature(object = "cpglm",k="missing")`

: extract the AIC information from the`"cpglm"`

object. See`AIC`

.- deviance
`signature(object = "cpglm")`

: extract the deviance from the`"cpglm"`

object. See`deviance`

.- summary
`signature(object = "cpglm")`

: the same as`glm.summaries`

except that both the dispersion and the index parameter are estimated using maximum likelihood estimation.- predict
`signature(object = "cpglm")`

: generate predictions for new data sets

The following are written for `"cpglmm"`

:

`signature(x = "cpglmm")`

: print the object- summary
`signature(object = "cpglmm")`

: summary results- predict
`signature(object = "cpglmm")`

: generate predictions for new data sets- VarCorr
`signature(x = "cpglmm")`

: estimation for the variance components- vcov
`signature(object = "cpglmm")`

: variance-covariance matrix for fixed effects

The following methods are available for the class `"bcplm"`

:

- plot
`signature(x = "bcplm", y = "missing")`

: summarize the`"bcplm"`

object with a trace of the sampled output and a density estimate for each variable in the chain. See`plot.mcmc`

.- summary
`signature(object = "bcplm")`

: produce two sets of summary statistics. See`summary.mcmc`

.- VarCorr
`signature(x = "bcplm")`

: estimation for the variance components if the random effects are present- fixef
`signature(object = "bcplm")`

: extract fixed effects. Additional arguments include:`sd = FALSE`

: extract standard errors;`quantiles = NULL`

: compute empirical quantiles. These additional statistics are stored as attributes in the returned results.

The following methods are defined for the `"gini"`

class:

- plot
`signature(x = "gini", y = "missing")`

: plot the ordered Lorenz curve from each model comparison. If`overlay = TRUE`

(the default), different curves are plotted on the same graph for each base.- show
`signature(object = "gini")`

: print the computed Gini indices and standard errors.

### Author(s)

Wayne Zhang actuary_zhang@hotmail.com

### See Also

See also `cpglm`

, `cpglmm`

, `bcplm`

, `glm`

.

*cplm*version 0.7-12 Index]