Description Usage Arguments Value Examples
View source: R/linear_decomposition.R
estimates the linear model y = β*X + ε and returns its linear components, grouped according to X.list.
1 2 3 4 5 6 7 8 |
y |
a character specifying the name of the outcome variable (e.g. "wage"). Note that this variable is standardized before it's projected onto X. |
X.list |
a list containing the names of all the variables needed for the linear projection, grouped according to the components will later be used in the skewness decomposition. For example: for X.list = list("x1", c("x2", "x3")) the following components are returned: β1X1, (β2X2+ β3X3), ε. Currently interactions aren't supported, so the user should insert them manually. |
data |
a data frame with all the variables specified in X.list and y. |
wgt |
an optional vector of weights. |
year |
an optional vector of years. if provided, the projection is done for each year separately. |
comp.names |
an optional vector specifying name for each component. |
a matrix with the (centered) components specified by X.list + residuals. Note that each row is summed (up to a constant) to the standardized version of y, and each column to 0 (both by year).
1 2 3 4 5 6 7 8 9 10 11 12 13 | #gen data
n <- 1000
X <- matrix(rnorm(n*3), ncol = 3)
colnames(X) <- c("x1", "x2", "x3")
beta <- c(1,2,3)
wage <- X %*% beta + rnorm(n)
dat <- as.data.frame(cbind(wage, X))
colnames(dat)[1] <- "wage"
res <- linear_projection("wage", X.list = list("x1", c("x2", "x3")), data = dat)
#each row is summed (up to a constant) to the standardized wage:
stand_wage <- (wage - mean(wage)) / sd(wage)
diff <- apply(res, 1, sum) - stand_wage
summary(diff)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.