dimw {kbal} | R Documentation |
Difference in Means and Difference in Weighted Means
Description
Calculates the simple difference in means or weighted difference in means between the control or sample population and the treated or target population.
Usage
dimw(X, w, target)
Arguments
X |
matrix of data where rows are observations and columns are covariates. |
w |
numeric vector of weights for each observation. |
target |
numeric vector of length equal to the total number of units where population/treated units take a value of 1 and sample/control units take a value of 0. |
Value
dim |
the simple, unweighted difference in means. |
dimw |
the weighted difference in means. |
Examples
#let's say we want to get the unweighted DIM and the weighted DIM using weights from the kbal
#function with the lalonde data:
#load and clean data a bit
set.seed(123)
data("lalonde")
# Select a random subset of 500 rows
lalonde_sample <- sample(1:nrow(lalonde), 500, replace = FALSE)
lalonde <- lalonde[lalonde_sample, ]
xvars=c("age","black","educ","hisp","married","re74","re75","nodegr","u74","u75")
#get the kbal weights
kbalout= kbal(allx=lalonde[,xvars],
sampledinpop=FALSE,
treatment=lalonde$nsw)
#now use dimw to get the DIMs
dimw(X = lalonde[,xvars], w = kbalout$w, target = lalonde$nsw)
[Package kbal version 0.1.1 Index]