adjust_object: Loglikelihood adjustment of fitted model objects

Description Usage Arguments Details Value References See Also Examples

Description

Performs adjustments, for model misspecification or the the presence of cluster dependence, of the loglikelihood associated with fitted model objects, following Chandler and Bate (2007). Certain classes of model objects are supported automatically. User-supplied objects can also be supported: the requirements for these objects are explained in Details. The loglikelihood adjustment generic alogLik uses a call to adjust_object. adjust_object may be called directly, but it is better to use alogLik.

Usage

1
2
adjust_object(x, cluster = NULL, use_sandwich = TRUE,
  use_vcov = TRUE, ...)

Arguments

x

A fitted model object with certain associated S3 methods. See Details.

cluster

A vector or factor indicating from which cluster the respective loglikelihood contributions from loglik originate. This must have the same length as the vector returned by the logLikVec method for object like x. If cluster is not supplied then it is assumed that each observation forms its own cluster.

If the sandwich package (Zeleis, 2006) is used to estimate the quantities required to adjust the loglikelihood (i.e. use_sanswich = TRUE) then cluster determines whether the variance matrix V of the score vector is estimated using meat (cluster is NULL) or meatCL (cluster is not NULL). See use_sandwich and Details.

use_sandwich

A logical scalar. Should we use the sandwich package (Zeleis, 2006) to estimate the variance V of the score function to be passed as the argument V to adjust_loglik? Otherwise, V is based on numerical derivatives, estimated using the numDeriv package. See Details for more information.

The main purpose of use_sandwich is to enable a check that equivalent results are obtained using the sandwich package and the numerical derivatives.

use_vcov

A logical scalar. Should we use the vcov S3 method for x (if this exists) to estimate the Hessian of the independence loglikelihood to be passed as the argument H to adjust_loglik? Otherwise, H is estimated inside adjust_loglik using optimHess.

...

Further arguments to be passed to the functions in the sandwich package meat, if cluster = NULL, or meatCL, otherwise.

Details

Supported classes, and the functions from which they are returned are:

Objects of other classes are supported provided that they have certain S3 methods. The class of the object x must have the following S3 methods:

and may have the following S3 methods

If a vcov method is not available then the variance-covariance matrix is estimated inside adjust_loglik. If an estfun method is not available then the matrix is estimated using jacobian.

Loglikelihood adjustment is performed using the adjust_loglik function in the chandwich package. The relevant arguments to adjust_loglik, namely loglik, mle, H and V, are created based on the class of the object x. If use_sandwich = TRUE then H is inferred using bread in the sandwich package and, similarly, V is inferred using either meat, if cluster = NULL and meatCL, otherwise.

If cluster is NULL then arguments of meatCL present in ... will be ignored. Similarly, if cluster is not NULL then arguments of meat present in ... will be ignored.

Value

An object of class inheriting from "oola", which inherits from the class "chandwich". See adjust_loglik. The attribute "name" of the returned object is the elements of class(x) concatenated into a character scalar and separated by _.

References

Chandler, R. E. and Bate, S. (2007). Inference for clustered data using the independence loglikelihood. Biometrika, 94(1), 167-183. http://dx.doi.org/10.1093/biomet/asm015

Zeleis (2006) Object-Oriented Computation and Sandwich Estimators. Journal of Statistical Software, 16, 1-16. http://dx.doi.org/10.18637/jss.v016.i09

See Also

summary.chandwich, plot.chandwich, confint.chandwich, anova.chandwich, coef.chandwich, vcov.chandwich and logLik.chandwich for S3 methods for objects of class "chandwich".

adjust_loglik to adjust a user-supplied loglikelihood.

bread, meat, meatCL and sandwich in the sandwich package.

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# ========== Generalized Linear Models (GLMs) ==========

# Poisson

# Example from the help file for stats::glm()
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
d.AD <- data.frame(treatment, outcome, counts)
glm.D93 <- glm(counts ~ outcome + treatment, family = poisson, data = d.AD)
adj_pois <- adjust_object(glm.D93)

# Binomial

# An example from Section 5.2 of sandwich vignette at
# https://cran.r-project.org/web/packages/sandwich/vignettes/sandwich-OOP.pdf

got_AER <- requireNamespace("AER", quietly = TRUE)
if (got_AER) {
  data("Affairs", package = "AER")
  fm_probit <- glm(I(affairs > 0) ~ age + yearsmarried + religiousness +
                   occupation + rating, data = Affairs,
                   family = binomial(link = "probit"))
  adj_binom <- adjust_object(fm_probit)
}

# An example where the response data are a (two-column) matrix
# (number of successes, number of failures)
lrfit <- glm(cbind(using, notUsing) ~ age + education + wantsMore,
             family = binomial, data = cuse)
adj_binom_2 <- adjust_object(lrfit)

# An example of a use of alogLik.default based on the evd::fgev() function
# In the background are S3 method functions for objects inheriting from
# class "gev": loglikVec.gev(), coef.gev(), nobs.gev(), vcov.gev()

# We need the evd package
got_evd <- requireNamespace("evd", quietly = TRUE)

if (got_evd) {
  library(evd)
  # An example from the evd::fgev documentation
  uvdata <- rgev(100, loc = 0.13, scale = 1.1, shape = 0.2)
  M1 <- fgev(uvdata, nsloc = (-49:50)/100)
  adj_fgev <- alogLik(M1)
  summary(adj_fgev)
}

paulnorthrop/oola documentation built on May 12, 2019, 10:52 a.m.