Learn R Programming

CBPS (version 0.8)

balance.CBPS: Optimal Covariate Balance

Description

Returns the mean and standardized mean associated with each treatment group, before and after weighting.

Usage

## S3 method for class 'CBPS':
balance(object, ...)

Arguments

object
A CBPS object.
...
Additional arguments to be passed to balance.

Value

  • Returns a list of two matrices, "original" (before weighting) and "balanced" (after weighting).

Details

Each of the matrices' rows are the covariates and whose columns are the weighted mean, and standardized mean associated with each treatment group. The standardized mean is the weighted mean divided by the standard deviation of the covariate for the whole population.

Examples

Run this code
###
### Example: Optimal Covariate Balance
###
# Run for 4-treatment case
set.seed(1)
# Generate random X and underlying coefficients for probability.  
# Determine probs and treatments.
X<-cbind(rep(1,1000), mvrnorm(1000,c(0,0,0), 
		 Sigma=matrix(c(5,.5,-.03,.5,1,-.27,-.03,-.27,1),3,3)))
beta<-matrix(rnorm(12),4,3)
baseline.prob<-apply(X%*%beta,1,function(x) (1+sum(exp(x)))^-1)
prob<-cbind(baseline.prob, exp(X%*%beta[,1])*baseline.prob, 
			exp(X%*%beta[,2])*baseline.prob, 
			exp(X%*%beta[,3])*baseline.prob)
treat.latent<-runif(1000)
treat<-ifelse(treat.latent < prob[,1], 1, 
			  ifelse(treat.latent < (prob[,1] + prob[,2]), 2, 
			  ifelse(treat.latent < (prob[,1] + prob[,2] + prob[,3]), 
			  3, 4)))
X<-X[,-1]
fit4<-CBPS(treat ~ X, ATT = FALSE)
balance(fit4)

Run the code above in your browser using DataLab