1% Generated by roxygen2: do not edit by hand 2% Please edit documentation in R/tool_model.extract.R 3\name{pmodel.response} 4\alias{pmodel.response} 5\alias{pmodel.response.plm} 6\alias{pmodel.response.data.frame} 7\alias{pmodel.response.formula} 8\title{A function to extract the model.response} 9\usage{ 10pmodel.response(object, ...) 11 12\method{pmodel.response}{plm}(object, ...) 13 14\method{pmodel.response}{data.frame}(object, ...) 15 16\method{pmodel.response}{formula}(object, data, ...) 17} 18\arguments{ 19\item{object}{an object of class \code{"plm"}, or a formula of 20class \code{"pFormula"},} 21 22\item{\dots}{further arguments.} 23 24\item{data}{a \code{data.frame}} 25} 26\value{ 27A pseries except if model responses' of a \code{"between"} 28or "fd" model as these models "compress" the data (the number 29of observations used in estimation is smaller than the original 30data due to the specific transformation). A numeric is returned 31for the "between" and "fd" model. 32} 33\description{ 34pmodel.response has several methods to conveniently extract the 35response of several objects. 36} 37\details{ 38The model response is extracted from a \code{pdata.frame} (where the 39response must reside in the first column; this is the case for a 40model frame), a \code{pFormula} + \code{data} or a \code{plm} object, and the 41transformation specified by \code{effect} and \code{model} is applied to 42it.\cr Constructing the model frame first ensures proper NA 43handling and the response being placed in the first column, see 44also \strong{Examples} for usage. 45} 46\examples{ 47 48# First, make a pdata.frame 49data("Grunfeld", package = "plm") 50pGrunfeld <- pdata.frame(Grunfeld) 51 52# then make a model frame from a pFormula and a pdata.frame 53 54 55form <- inv ~ value + capital 56mf <- model.frame(pGrunfeld, form) 57# construct (transformed) response of the within model 58resp <- pmodel.response(form, data = mf, model = "within", effect = "individual") 59# retrieve (transformed) response directly from model frame 60resp_mf <- pmodel.response(mf, model = "within", effect = "individual") 61 62# retrieve (transformed) response from a plm object, i.e., an estimated model 63fe_model <- plm(form, data = pGrunfeld, model = "within") 64pmodel.response(fe_model) 65 66# same as constructed before 67all.equal(resp, pmodel.response(fe_model), check.attributes = FALSE) # TRUE 68 69} 70\seealso{ 71\code{plm}'s \code{\link[=model.matrix]{model.matrix()}} for (transformed) 72model matrix and the corresponding \code{\link[=model.frame]{model.frame()}} 73method to construct a model frame. 74} 75\author{ 76Yves Croissant 77} 78\keyword{manip} 79