Learn R Programming

plm (version 1.6-5)

pmodel.response: A function to extract the model.response

Description

pmodel.response has several methods to conveniently extract the response of several objects.

Usage

pmodel.response(object, ...) "pmodel.response"(object, model = c("pooling","within","Between", "between","mean","random","fd"), effect = c("individual","time","twoways"), lhs = NULL, theta = NULL, ...) "pmodel.response"(object, data, model = c("pooling","within","Between", "between","mean","random","fd"), effect = c("individual","time","twoways"), lhs = NULL, theta = NULL, ...) "pmodel.response"(object, ...)

Arguments

object
an object of class "plm", or a formula of class "pFormula",
data
a pdata.frame, which is a model frame (if not, it is tried to construct the model frame from the data, see Details),
effect
the effects introduced in the model, one of "individual", "time" or "twoways",
model
one of "pooling", "within", "between", "random", "fd" and "ht",
theta
the parameter for the transformation if model = "random",
lhs
inherited from package Formula (see there),
...
further arguments.

Value

A numeric vector.

Details

The model response is extracted from a pdata.frame (where the response must reside in the first column; this is the case for a model frame), a pFormula + data or a plm object, and the transformation specified by effect and model is applied to it. Constructing the model frame first ensures proper NA handling and the response being placed in the first column, see also Examples for usage.

See Also

plm's model.matrix for (transformed) model matrix and the corresponding model.frame method to construct a model frame.

Examples

Run this code
# First, make a pdata.frame
data(Grunfeld)
pGrunfeld <- pdata.frame(Grunfeld)

# then make a model frame from a pFormula and a pdata.frame
pform <- pFormula(inv ~ value + capital)
mf <- model.frame(pform, data = pGrunfeld)

# construct (transformed) response of the within model
resp <- pmodel.response(pform, data = mf, model = "within")

# retrieve (transformed) response directly from model frame
resp_mf <- pmodel.response(mf, model = "within")

# retrieve (transformed) response from a plm object, i.e. an estimated model
fe_model <- plm(pform, data = pGrunfeld, model = "within")
pmodel.response(fe_model)

# same as constructed before
all.equal(resp, pmodel.response(fe_model), check.attributes = FALSE) # TRUE

Run the code above in your browser using DataLab