Learn R Programming

emmeans (version 1.10.5)

qdrg: Quick and dirty reference grid

Description

This function may make it possible to compute a reference grid for a model object that is otherwise not supported.

Usage

qdrg(formula, data, coef, vcov, df, mcmc, object, subset, weights, contrasts,
  link, qr, ordinal, ...)

Value

An emmGrid object constructed from the arguments

Arguments

formula

Formula for the fixed effects

data

Dataset containing the variables in the model

coef

Fixed-effect regression coefficients (must conform to formula)

vcov

Variance-covariance matrix of the fixed effects

df

Error degrees of freedom

mcmc

Posterior sample of fixed-effect coefficients

object

Optional model object. This rarely works!; but if provided, we try to set other arguments based on an expectation that `object` has a similar structure to `lm` objects. See Details.

subset

Subset of data used in fitting the model

weights

Weights used in fitting the model

contrasts

List of contrasts specified in fitting the model

link

Link function (character or list) used, if a generalized linear model. (Note: response transformations are auto-detected from formula)

qr

QR decomposition of the model matrix; used only if there are NAs in coef.

ordinal

list with elements dim and mode. ordinal$dim (integer) is the number of levels in an ordinal response. If ordinal is provided, the intercept terms are modified appropriate to predicting an ordinal response, as described in vignette("models"), Section O, using ordinal$mode as the mode argument (if not provided, "latent" is assumed). (All modes are supported except `scale`) For this to work, we expect the first ordinal$dim - 1 elements of coef to be the estimated threshold parameters, followed by the coefficients for the linear predictor.

...

Optional arguments passed to ref_grid

Rank deficiencies

Different model-fitting packages take different approaches when the model matrix is singular, but qdrg tries to reconcile them by comparing the linear functions created by formula to coefs and vcov. We may then use the estimability package to determine what quantities are estimable. For reconciling to work properly, coef should be named and vcov should have dimnames. To disable this name-matching action, remove the names from coef, e.g., by calling unname(). No reconciliation is attempted in multivariate-response cases. For more details on estimability, see the documentation in the estimability package.

Details

Usually, you need to provide either object; or formula, coef, vcov, data, and perhaps other parameters. It is usually fairly straightforward to figure out how to get these from the model object; see the documentation for the model class that was fitted. Sometimes one or more of these quantities contains extra parameters, and if so, you may need to subset them to make everything conformable. For a given formula and data, you can find out what is needed via colnames(model.matrix(formula, data)). (However, for an ordinal model, we expect the first ordinal.dim - 1 coefficients to replace (Intercept). And for a multivariate model, we expect coef to be a matrix with these row names, and vcov to have as many rows and columns as the total number of elements of coef.)

If your model object follows fairly closely the conventions of an lm or glmobject, you may be able to get by providing the model as object, and perhaps some other parameters to override the defaults. When object is specified, it is used as detailed below to try to obtain the other arguments. The user should ensure that the defaults shown below do indeed work. The default values for the arguments are as follows:

  • formula: formula(object)

  • data: recover_data.lm(object) is tried, and if an error is thrown, we also check object$data.

  • coef: coef(object)

  • vcov: vcov(object)

  • df: Set to Inf if not available in df.residual(object)

  • mcmc: object$sample

  • subset: NULL (so that all observations in data are used)

  • contrasts: object$contrasts

The functions qdrg and emmobj are close cousins, in that they both produce emmGrid objects. When starting with summary statistics for an existing grid, emmobj is more useful, while qdrg is more useful when starting from a fitted model.

See Also

emmobj for an alternative way to construct an emmGrid.

Examples

Run this code
# In these examples, use emm_example(..., list = TRUE) # to see just the code

if (require(biglm, quietly = TRUE)) 
    emm_example("qdrg-biglm")
    
if(require(coda, quietly = TRUE) && require(lme4, quietly = TRUE)) 
    emm_example("qdrg-coda")
    
if(require(ordinal, quietly = TRUE)) 
    emm_example("qdrg-ordinal")

Run the code above in your browser using DataLab