Performs adjustments of a user-supplied independence loglikelihood
function using a robust sandwich estimator of the parameter covariance
matrix, based on the methodology in Chandler and Bate (2007)
The chandwich
package performs adjustments of an independence loglikelihood using a robust sandwich estimator of the parameter covariance matrix, based on the methodology in Chandler and Bate (2007). This can be used for cluster correlated data when interest lies in the parameters of the marginal distributions or for performing inferences that are robust to certain types of model misspecification. Functions for profiling the adjusted loglikelihoods are also provided, as are functions for calculating and plotting confidence intervals, for single model parameters, and confidence regions, for pairs of model parameters. Nested models can be compared using an adjusted likelihood ratio test.
The main function in the chandwich package is adjust_loglik
. It finds the maximum likelihood estimate (MLE) of model parameters based on an independence loglikelihood in which cluster dependence in the data is ignored. The independence loglikelihood is adjusted in a way that ensures that the Hessian of the adjusted loglikelihood conicides with a robust sandwich estimate of the parameter covariance at the MLE. Three adjustments are available: one in which the independence loglikelihood itself is scaled (vertical scaling) and two others where the scaling is in the parameter vector (horizontal scaling).
The rats
data contain information about an experiment in which, for each of 71 groups of rats, the total number of rats in the group and the numbers of rats who develop a tumor is recorded. We model these data using a binomial distribution, treating each group of rats as a separate cluster. The argument binom_loglik
to adjust_loglik
is a function that returns a vector of the loglikelihood contributions from each group of rats. In one-dimensional examples like this the two adjustments using horizontal scaling are identical, but this will not generally hold in more than one dimension.
binom_loglik <- function(prob, data) {if (prob < 0 || prob > 1) {return(-Inf)}return(dbinom(data[, "y"], data[, "n"], prob, log = TRUE))}rat_res <- adjust_loglik(loglik = binom_loglik, data = rats)plot(rat_res, type = 1:4, legend_pos = "bottom", lwd = 2, col = 1:4)
To get the current released version from CRAN:
install.packages("chandwich")
See vignette("chandwich-vignette", package = "chandwich")
for an overview of the package.
adjust_loglik
has an additional arguments mle
, H
and V
that allow the user the option to supply the MLE, the Hessian of the independence loglikelihood (H) and the variance of the vector of cluster-specific contributions to the score vector (V), each evaluated at the MLE, rather than estimating these within adjust_loglik
.
An anova S3 method for class "chandwich" has been added. This compares two or more nested models using adjusted likelihood ratio tests of successive pairs of models, using compare_models()
.
A confint S3 method for class "chandwich" has been added. This is based on a fairly trivial call to conf_intervals()
.
S3 methods coef
, vcov
and logLik
for class "chandwich" have been added.
A bug in compare_models()
has been fixed. The bug resulted an error in cases where the argument larger
corresponded to a simplication of the full model in which element i of the parameter was fixed but some element i+n, for n > 0, was not fixed.
Estimated unadjusted (VC) and adjusted (adjVC) variance-covariance matrices of the free model parameters are now available in the object returned by adjust_loglik()
.
The documentation of the argument approx
to compare_models()
has been edited to make it clearer that if smaller
is not supplied then approx = FALSE
will be used regardless of any value supplied for approx
in the call to compare_models()
.
If parameter names are supplied to adjust_loglik()
(via par_names
) but fixed_pars
is numeric then the names of the parameters in fixed_pars
are now also inferred in the case where a larger model is not supplied via larger
. This means that the output from compare_models()
will now use the parameter name, rather than the parameter number.
If a numeric fixed_pars
is supplied to compare_models()
then the names of the parameters in fixed_pars
are inferred, if they are available in the supplied object larger
.
The summary method for class "evpost" is now set up according to Section 8.1 of the R FAQ at (https://cran.r-project.org/doc/FAQ/R-FAQ.html).
In the Introducing chandwich vignette a typo in the definition of HA has been corrected. The expression given is for the inverse of HA, not for HA.