cpglmm: Compound Poisson Generalized Linear Mixed Models

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/cpglmm.R

Description

Laplace approximation and adaptive Gauss-Hermite quadrature methods for compound Poisson mixed and additive models.

Usage

1
2
3
4
cpglmm(formula, link = "log", data, weights, offset, subset, 
    na.action, inits = NULL,  contrasts = NULL, 
    control = list(), basisGenerators = c("tp", "bsp", "sp2d"),
    optimizer = "nlminb", doFit = TRUE, nAGQ = 1)

Arguments

formula

a two-sided linear formula object describing the model structure, with the response on the left of a ~ operator and the terms, separated by + operators, on the right. The vertical bar character "|" separates an expression for a model matrix and a grouping factor. The right side can also include basis generators. See lme4 and basisGenerators below.

link

a specification for the model link function. This can be either a literal character string or a numeric number. If it is a character string, it must be one of "log", "identity", "sqrt" or "inverse". If it is numeric, it is the same as the link.power argument in the tweedie function. The default is link="log".

data

an optional data frame, list or environment (or object coercible by as.data.frame to a data frame) containing the variables in the model.

subset, weights, na.action, offset, contrasts

further model specification arguments as in cpglm; see there for details.

inits

a named list with three components 'beta', 'phi', 'p', 'Sigma' that supply the initial values used in the optimization. If not supplied, the function will generate initial values automatically, which are based on a GLM with the supplied model structure.

control

a list of parameters for controlling the fitting process. See cpglm. The parameter PQL.init is not used.

basisGenerators

a character vector of names of functions that generate spline bases. This is used when smoothing effects are to be included in the model. See tp for details.

optimizer

a character string that determines which optimization routine is to be used. Possible choices are "nlminb" (the default, see nlminb), "bobyqa" (bobyqa) and "L-BFGS-B" (optim).

doFit

if FALSE, the constructed "cpglmm" object is returned before the model is fitted.

nAGQ

a positive integer - the number of points per axis for evaluating the adaptive Gauss-Hermite approximation to the log-likelihood. This defaults to 1, corresponding to the Laplacian approximation. Values greater than 1 produce greater accuracy in the evaluation of the log-likelihood at the expense of speed.

Details

Estimation of compound Poisson mixed models in existing software has been limited to the Penalized Quasi-Likelihood [PQL] approach (e.g., see glmmPQL). While straightforward and fast, this method is not equipped to estimate the unknown variance function, i.e., the index parameter. In contrast, the function cpglmm implements true likelihood-based inferential procedures, i.e., the Laplace approximation and the Adaptive Gauss-Hermite Quadrature (for single grouping factor), so that all parameters in the model can be estimated using maximum likelihood estimation.

This implementation is based on the older lme4 package (the 0.9* version), with changes made on updating of the mean, the variance function and the marginal loglikelihood. For the Laplace method, the contribution of the dispersion parameter to the approximated loglikelihood is explicitly accounted for, which should be more accurate and more consistent with the quadrature estimate. Indeed, both the dispersion parameter and the index parameter are included as a part of the optimization process. In computing the marginal loglikelihood, the density of the compound Poisson distribution is approximated using numerical methods provided in the tweedie package. For details of the Laplace approximation and the Gauss-Hermite quadrature method for generalized linear mixed models, see the documentation associated with lme4.

In addition, similar to the package amer (already retired from CRAN), we provide convenient interfaces for fitting additive models using penalized splines. See the 'example' section for one such application.

Value

cpglmm returns an object of class cpglmm. See cpglmm-class for details of the return values as well as various method available for this class.

Author(s)

Yanwei (Wayne)) Zhang [email protected]

References

Zhang Y (2013). Likelihood-based and Bayesian Methods for Tweedie Compound Poisson Linear Mixed Models, Statistics and Computing, 23, 743-757. https://github.com/actuaryzhang/cplm/files/144051/TweediePaper.pdf

Bates D, Maechler M, Bolker B and Walker S (2015). lme4: Linear mixed-effects models using Eigen and S4..

See Also

The users are recommended to see cpglm for a general introduction to the compound Poisson distribution, lme4 for syntax and usage of mixed-effect models and cpglmm-class for detailed explanation of the return value.

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
## Not run: 
# use Stock and Spacing as main effects and Plant as random effect
(f1 <- cpglmm(RLD ~ Stock + Spacing +  (1|Plant), data = FineRoot))
            
coef(f1); fixef(f1); ranef(f1)  #coefficients
VarCorr(f1)  #variance components

# add another random effect
(f2 <- update(f1, . ~ . + (1|Zone)))
# test the additional random effect
anova(f1,f2)

# try a different optimizer 
(f3 <- cpglmm(RLD ~  Stock + Spacing +  (1|Plant), 
            data = FineRoot, optimizer = "bobyqa", 
            control = list(trace = 2)))

# adaptive G-H quadrature  
(f4 <- cpglmm(RLD ~  Stock + Spacing +  (1|Plant), 
            data = FineRoot, nAGQ = 3))

# a model with smoothing effects
(f5 <- cpglmm(increLoss ~ tp(lag, k = 4) + (1|year) , 
            data = ClaimTriangle))

## End(Not run)

Example output

Loading required package: coda
Loading required package: Matrix
Loading required package: splines
Compound Poisson linear mixed model fit by the Laplace approximation 
Formula: RLD ~ Stock + Spacing + (1 | Plant) 
   Data: FineRoot 
    AIC    BIC logLik deviance
 -107.8 -82.37  59.89   -119.8
Random effects:
 Groups   Name        Variance   Std.Dev.
 Plant    (Intercept) 0.00027062 0.016451
 Residual             0.39316061 0.627025
Number of obs: 511, groups: Plant, 8

Fixed effects:
            Estimate Std. Error t value
(Intercept)  -2.2611     0.1308 -17.293
StockMM106    0.2996     0.2514   1.192
StockMark    -0.5629     0.2000  -2.815
Spacing5x3   -0.4225     0.1921  -2.200

Estimated dispersion parameter: 0.3932
Estimated index parameter: 1.4359
$Plant
  (Intercept) StockMM106  StockMark Spacing5x3
1   -2.259335  0.2996391 -0.5628589 -0.4224784
2   -2.262893  0.2996391 -0.5628589 -0.4224784
3   -2.263261  0.2996391 -0.5628589 -0.4224784
4   -2.258967  0.2996391 -0.5628589 -0.4224784
5   -2.262658  0.2996391 -0.5628589 -0.4224784
6   -2.259570  0.2996391 -0.5628589 -0.4224784
7   -2.261525  0.2996391 -0.5628589 -0.4224784
8   -2.260703  0.2996391 -0.5628589 -0.4224784

attr(,"class")
[1] "coef.mer"
(Intercept)  StockMM106   StockMark  Spacing5x3 
 -2.2611147   0.2996391  -0.5628589  -0.4224784 
$Plant
    (Intercept)
1  0.0017793521
2 -0.0017778915
3 -0.0021468317
4  0.0021477285
5 -0.0015428653
6  0.0015450724
7 -0.0004104674
8  0.0004116661

attr(,"class")
[1] "ranef.mer"
$Plant
             (Intercept)
(Intercept) 0.0002706214
attr(,"stddev")
(Intercept) 
 0.01645057 
attr(,"correlation")
            (Intercept)
(Intercept)           1

attr(,"sc")
[1] 0.6270252
Compound Poisson linear mixed model fit by the Laplace approximation 
Formula: RLD ~ Stock + Spacing + (1 | Plant) + (1 | Zone) 
   Data: FineRoot 
    AIC    BIC logLik deviance
 -145.6 -115.9  79.79   -159.6
Random effects:
 Groups   Name        Variance Std.Dev.
 Plant    (Intercept) 0.012061 0.10982 
 Zone     (Intercept) 0.171305 0.41389 
 Residual             0.347853 0.58979 
Number of obs: 511, groups: Plant, 8; Zone, 2

Fixed effects:
            Estimate Std. Error t value
(Intercept)  -2.3767     0.3282  -7.241
StockMM106    0.2909     0.2894   1.005
StockMark    -0.6667     0.2230  -2.990
Spacing5x3   -0.2882     0.2195  -1.313

Estimated dispersion parameter: 0.3479
Estimated index parameter: 1.4204
Data: FineRoot
Models:
f1: RLD ~ Stock + Spacing + (1 | Plant)
f2: RLD ~ Stock + Spacing + (1 | Plant) + (1 | Zone)
   Df     AIC      BIC logLik  Chisq Chi Df Pr(>Chisq)    
f1  6 -107.78  -82.367 59.893                             
f2  7 -145.58 -115.924 79.789 39.794      1  2.823e-10 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
npt = 9 , n =  7 
rhobeg =  0.02 , rhoend =  2e-07 
start par. =  0.2043238 -2.261025 0.2997297 -0.5626087 -0.4225499 -0.4720556 1.5 fn =  -98.20888 
rho:   0.0020 eval:  10 fn:     -103.016 par:0.204324 -2.26102 0.299730 -0.562609 -0.422550 -0.472056  1.52000 
rho:  0.00020 eval: 158 fn:     -117.875 par:0.104870 -2.18960 0.372653 -0.544897 -0.572458 -0.818483  1.45806 
rho:  2.0e-05 eval: 522 fn:     -119.759 par:0.0727483 -2.26507 0.328183 -0.548313 -0.443925 -0.938617  1.43501 
rho:  2.0e-06 eval: 1044 fn:     -119.785 par:0.0226761 -2.26145 0.300465 -0.562134 -0.422852 -0.933404  1.43592 
rho:  2.0e-07 eval: 1532 fn:     -119.785 par:0.0260247 -2.26111 0.299611 -0.562876 -0.422461 -0.933538  1.43590 
At return
eval: 1693 fn:     -119.78546 par: 0.0262050 -2.26111 0.299641 -0.562857 -0.422481 -0.933537  1.43590
Compound Poisson linear mixed model fit by the Laplace approximation 
Formula: RLD ~ Stock + Spacing + (1 | Plant) 
   Data: FineRoot 
    AIC    BIC logLik deviance
 -107.8 -82.37  59.89   -119.8
Random effects:
 Groups   Name        Variance   Std.Dev.
 Plant    (Intercept) 0.00026998 0.016431
 Residual             0.39316077 0.627025
Number of obs: 511, groups: Plant, 8

Fixed effects:
            Estimate Std. Error t value
(Intercept)  -2.2611     0.1307 -17.294
StockMM106    0.2996     0.2514   1.192
StockMark    -0.5629     0.2000  -2.815
Spacing5x3   -0.4225     0.1921  -2.200

Estimated dispersion parameter: 0.3932
Estimated index parameter: 1.4359
Compound Poisson linear mixed model fit by the adaptive Gaussian Hermite approximation 
Formula: RLD ~ Stock + Spacing + (1 | Plant) 
   Data: FineRoot 
    AIC    BIC logLik deviance
 -116.9 -91.53  64.47   -128.9
Random effects:
 Groups   Name        Variance   Std.Dev.
 Plant    (Intercept) 0.00026934 0.016412
 Residual             0.39316051 0.627025
Number of obs: 511, groups: Plant, 8

Fixed effects:
            Estimate Std. Error t value
(Intercept)  -2.2611     0.1307 -17.294
StockMM106    0.2996     0.2514   1.192
StockMark    -0.5629     0.1999  -2.815
Spacing5x3   -0.4225     0.1921  -2.200

Estimated dispersion parameter: 0.3932
Estimated index parameter: 1.4359
Compound Poisson linear mixed model fit by the Laplace approximation 
Formula: increLoss ~ tp(lag, k = 4) + (1 | year) 
   Data: ClaimTriangle 
   AIC   BIC logLik deviance
 418.9 428.9 -204.4    408.9
Random effects:
 Groups   Name        Variance Std.Dev.
 year     (Intercept) 0.003659 0.06049 
 f.lag    tp          2.270132 1.50670 
 Residual             0.663144 0.81434 
Number of obs: 55, groups: year, 10; f.lag, 3

Fixed effects:
            Estimate Std. Error t value
(Intercept)  4.18376    0.10498   39.85
lag.fx1     -1.79851    0.09466  -19.00

Estimated dispersion parameter: 0.6631
Estimated index parameter: 1.2362

cplm documentation built on May 30, 2017, 5:18 a.m.