Description Usage Arguments Value Examples
decompose the skewness or the variance of an outcome vector into independent components, either using one or many variables.
1 2 3 4 5 6 7 |
y |
an outcome vector (necessary only when decomposing by one variable). |
X |
when decomposing by one variable, a matrix or data frame containing the variable
for the decomposition. when decomposing by more than one variable, a matrix or
data frame containing the linear components of y, calculated by
|
wgt |
an optional vector of weights. |
moment |
the moment on which the decomposition method is applied. either "variance" (second moment) or "skewness" (third moment). |
year |
an optional vector of years. if provided, the decomposition is calculated by year. otherwise, the decomposition is calculated for the whole sample. |
A "vs_decomp" object. This object is a list containing the estimated components and their standard errors.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #generate data
n <- 100
men <- rbinom(n, 1, 0.5)
black <- rbinom(n, 1, 0.5)
year <- c(rep(2019, n/2), rep(2020, n/2))
rwage <- function(x){
m <- x[1]; b <- x[2]; y <- x[3];
exp(rnorm(1, mean = 1*m + 1*b, sd = 1 + 2020 - y))
}
dat <- data.frame(men, black, year)
dat$wage <- apply(dat, 1, rwage)
#skewness decomposition by one variable:
variable <- as.matrix(dat$men)
decomp_by_gender <- vs_decomp(y = dat$wage, X = variable,
moment = "skew", year = dat$year)
summary(decomp_by_gender)
plot(decomp_by_gender)
#skewness decomposition by more than one variable (=linear skewness decomposition):
#first we need to decompose yearly wages into their linear components
#(check ?linear_projection for more details):
wage_linear_comp <- linear_projection(y = "wage",
X.list = list("men", "black"),
data = dat, year = dat$year)
#using the linear components, we can calculate skewness decomposition:
decomp_by_mult_var <- vs_decomp(X = wage_linear_comp,
year = dat$year)
#up to 3 components can be summarized or plotted:
colnames(decomp_by_mult_var$components)
#let's take "3cov(epsilon^2,men)" and "3cov(epsilon^2,black)"
summary(decomp_by_mult_var, sum.comp = c(7, 8))
plot(decomp_by_mult_var, plot.comp = c(7, 8))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.