ref.grid
object from a fitted model.recover.data(object, ...)
## S3 method for class 'call':
recover.data(object, trms, na.action,
data = NULL, params = NULL, ...)
lsm.basis(object, trms, xlev, grid, ...)
All.vars(expr, retain = c("\\$", "\\[\\[", "\\]\\]"), ...)
terms
component of object
factor
call in the model formula.data.frame
containing predictor values at which predictions are needed.NULL
if noneNULL
. However, if non-null, this is used in place of the reconstructed dataset. It must have all of the predictors used in the model, and any factor levels must match those used in fitting the model.knots
specifying the knots to use in a spline model.gsub
)recover.data
should return a data.frame
containing all the variables in the original data that appear as predictors in the model. Several attributes need to be included as well; see the code for lsmeans:::recover.data.lm
.
lsm.basis
should return a list
with the following elements:grid
, having the same number of rows as grid
and the number of columns equal to the length of bhat
.NA
s that result from rank deficiencies.NA
if there is no rank deficiency.bhat
.(k, dfargs)
that returns the degrees of freedom associated with sum(k * bhat)
.list
containing additional arguments needed for dffun
.All.vars
is an enhancement of all.vars
, whereby the operators specified in retain
are left intact. Thus, All.vars(foo$y ~ bar[[2]])
returns "foo$y", "bar[[2]]"
, whereas all.vars
returns "foo", "y", "bar"
misc$estHook
, misc$vcovHook
and misc$postGridHook
. If just the name of the hook function is provided as a character string, then it is retrieved using get
.
The estHook
function should have arguments (object, do.se, tol, ...) where object
is the ref.grid
or lsmobj
object, do.se
is a logical flag for whether to return the standard error, and tol
is the tolerance for assessing estimability. It should return a matrix with 3 columns: the estimates, standard errors (NA
when do.se==FALSE
), and degrees of freedom (NA
for asymptotic). The number of rows should be the same as object@linfct. The vcovHook
function should have arguments (object, tol, ...) as described. It should return the covariance matrix for the estimates. Finally, postGridHook
, if present, is called at the very end of ref.grid
; it takes one argument, the constructed object
, and should return a suitably modifiedref.grid
object.ref.grid
function needs to reconstruct the data used in fitting the model, and then obtain a matrix of linear functions of the regression coefficients for a given grid of predictor values. These tasks are performed by calls to recover.data
and lsm.basis
respectively.
To extend recover.data
can be done by its method for class "call"
, providing the terms
component and na.action
data as additional arguments. Writing an lsm.basis
method is more involved, but the existing methods (e.g., lsmeans:::lsm.basis.lm
) can serve as models. See the ``Value'' section below for details on what it needs to return. Also, certain recover.data
and lsm.basis
methods are exported from bhat
needs to be X
and V
must be constructed consistently.
In models where a non-full-rank result is possible (often you can tell by seeing if there is a singular.ok
argument in the model-fitting function), summary
and predict
check the estimability of each prediction, using the nonest.basis
function in the models
. Some packages may provide additional models
, ref.grid
, ref.grid-class
require(lsmeans)
# Fit a 2-factor model with two empty cells
warpsing.lm <- lm(breaks ~ wool*tension,
data = warpbreaks, subset = -(16:40))
lsmeans:::recover.data.lm(warpsing.lm, data = NULL)
grid = with(warpbreaks,
expand.grid(wool = levels(wool), tension = levels(tension)))
lsmeans:::lsm.basis.lm(warpsing.lm, delete.response(terms(warpsing.lm)),
warpsing.lm$xlevels, grid)
# Compare results of all.vars and All.vars
form = log(cows$weight) ~ factor(bulls[[3]]) * herd$breed
all.vars(form)
All.vars(form)
all.vars(form, functions = TRUE) ## same as all.names(form, unique = TRUE)
All.vars(form, functions = TRUE)
Run the code above in your browser using DataLab