| model.extract {stats} | R Documentation |
Extract Components from a Model Frame
Description
Returns the response, offset, subset, weights or other
special components of a model frame passed as optional arguments to
model.frame.
Usage
model.extract(frame, component)
model.offset(x)
model.response(data, type = "any")
model.weights(x)
Arguments
frame, x, data |
a model frame, see |
component |
literal character string or name. The name of a
component to extract, such as |
type |
One of |
Details
model.extract is provided for compatibility with S, which does
not have the more specific functions. It is also useful to extract
e.g. the etastart and mustart components of a
glm fit.
model.extract(m, "offset") and model.extract(m, "response")
are equivalent to model.offset(m) and model.response(m)
respectively. model.offset sums any terms specified by
offset terms in the formula or by offset arguments
in the call producing the model frame: it does check that the offset
is numeric.
model.weights is slightly different from
model.extract(, "weights") in not naming the vector it returns.
Value
The specified component of the model frame, usually a vector.
model.response() now drops a possible "Asis" class
(stemming from I(.)).
model.offset returns NULL if no offset was specified.
See Also
Examples
a <- model.frame(cbind(ncases,ncontrols) ~ agegp + tobgp + alcgp, data = esoph)
model.extract(a, "response")
stopifnot(model.extract(a, "response") == model.response(a))
a <- model.frame(ncases/(ncases+ncontrols) ~ agegp + tobgp + alcgp,
data = esoph, weights = ncases+ncontrols)
model.response(a)
(mw <- model.extract(a, "weights"))
stopifnot(identical(unname(mw), model.weights(a)))
a <- model.frame(cbind(ncases,ncontrols) ~ agegp,
something = tobgp, data = esoph)
names(a)
stopifnot(model.extract(a, "something") == esoph$tobgp)