View source: R/utility_functions.R
detrend | R Documentation |
Detrends the input data by the predicted values based on the slope parameters within each group
specified by id. The result is equal to the transformed data used for estimation in
feis
.
detrend( data, slopes, id = NULL, intercept = TRUE, na.action = c("na.exlude", "na.omit"), tol = .Machine$double.eps, predicted = FALSE, ... )
data |
a |
slopes |
a |
id |
a |
intercept |
logical. If |
na.action |
character, either |
tol |
the tolerance for detecting linear dependencies in the residual maker transformation
(see |
predicted |
logical. If |
... |
further arguments. |
detrend
performs within-group "residual maker" transformation on the origin data.
Within each group, the predicted values of the columns in data are computed based on the
slope columns plus an individual intercept if intercept = TRUE
(the default).
Subsequently the predicted values are subtracted from the origin data. The transformed
data can, for instance, be used to obtain coefficients of a fixed effects individual slopes
estimator via lm
\insertCiteBruderl.2015.387,Ruttenauer.2020,Wooldridge.2010.384feisr.
Estimation requires at least q+1
observations per unit, where q
is the number of slope
parameters (including a constant).
detrend
automatically selects only those groups from the current data set which have
at least q+1
observations, and returns NA for all groups with n_i
< q+1
.
NA
values in the input data are handled by list-wise deletion based on the data to be
detrended and the slopes.
An object of class "data.frame
" or "numeric
(if only one data column),
containing the detrended data with row.names
equal
to the row.names
of the origin data. If input is an unnamed vector, names are 1:length.
feis
data("mwp", package = "feisr") # Detrend entire data.frame mwp_det <- detrend(data = mwp, slopes = c("exp", "expq"), id = "id") # Detrend single variable lnw_det <- detrend(data = mwp$lnw, slopes = mwp[, c("exp", "expq")], id = mwp$id)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.