Description Usage Arguments Details Value References See Also Examples
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
.
1 2 | adjust_object(x, cluster = NULL, use_sandwich = TRUE,
use_vcov = TRUE, ...)
|
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 If the sandwich package
(Zeleis, 2006)
is used to estimate the quantities required to adjust the loglikelihood
(i.e. |
use_sandwich |
A logical scalar. Should we use the The main purpose of |
use_vcov |
A logical scalar. Should we use the |
... |
Further arguments to be passed to the functions in the
sandwich package |
Supported classes, and the functions from which they are returned are:
"lm": lm
in the
stats
package,
"glm": glm
in the
stats
package
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:
logLikVec:
returns a vector of the contributions to the
independence loglikelihood from individual observations;
coef:
returns a vector of model coefficients, see
coef
;
nobs:
returns the number of (non-missing) observations
used in a model fit, see nobs
;
and may have the following S3 methods
vcov:
returns the estimated variance-covariance matrix of
the (main) parameters of a fitted model, see
vcov
;
estfun:
returns an n x k matrix, in which each
column gives the derivative of the loglikelihood at each of n
observation with respect to the k parameters of the model, see
estfun
.
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.
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 _
.
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
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.
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)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.