mlr.bias.constructor {MatchLinReg} | R Documentation |
Generating the treatment effect bias constructor vector
Description
Generaring the vector that, multiplied by Z.o%*%gamma.o
(contribution of omitted covariates to outcome), produces the treatment effect bias - due to model misspecification in the form of covariate omission - when using linear regression for causal inference.
Usage
mlr.bias.constructor(tr, Z.i = NULL, details = FALSE, idx = 1:length(tr))
Arguments
tr |
Binary treatment indicator vector (1=treatment, 0=control), whose coefficient in the linear regression model is TE. |
Z.i |
Matrix of adjustment covariates included in linear regression. We must have |
details |
Boolean flag, indicating whether intermediate objects used in generating the constrcutor vector must be returned or not. This only works if at least one adjustment covariate is included in the regression ( |
idx |
Index of observations to be used, with possible duplication, e.g. as indexes of matched subset. |
Value
A vector of same length as tr
is returned. If details = TRUE
and Z.i
is not NULL
, then the following objects are attached as attributes:
p |
Vector of length |
q |
Vector of length |
u.i |
Vector of length |
A |
Weighted, within-group covariance matrix of included covariates. It is a square matrix of dimension |
iA |
Inverse of |
Author(s)
Alireza S. Mahani, Mansour T.A. Sharabiani
References
Link to a draft paper, documenting the supporting mathematical framework, will be provided in the next release.
Examples
# number of included adjustment covariates
K <- 10
# number of observations in treatment group
Nt <- 100
# number of observations in control group
Nc <- 100
N <- Nt + Nc
# treatment indicator variable
tr <- c(rep(1, Nt), rep(0, Nc))
# matrix of included (adjustment) covariates
Z.i <- matrix(runif(K*N), ncol = K)
ret <- mlr.bias.constructor(tr = tr, Z.i = Z.i)
# comparing with brute-force approach
X.i <- cbind(tr, 1, Z.i)
ret2 <- (solve(t(X.i) %*% X.i, t(X.i)))[1, ]
cat("check 1:", all.equal(ret2, ret), "\n")
# sampling with replacement
idx <- sample(1:N, size = round(0.75*N), replace = TRUE)
ret3 <- mlr.bias.constructor(tr = tr, Z.i = Z.i, idx = idx)
ret4 <- (solve(t(X.i[idx, ]) %*% X.i[idx, ], t(X.i[idx, ])))[1, ]
cat("check 2:", all.equal(ret3, ret4), "\n")