R: Balance for Continuous Covariate: Random Strata as part of a...
bal.ms.psa
R Documentation
Balance for Continuous Covariate: Random Strata as part of a PSA
Description
Function provides a measure (based on the trimmed mean) of the balance achieved between control and treatment
groups for a continuous covariate from user defined strata. This statistic is compared to the same measure
for randomly permuted strata.
Usage
bal.ms.psa(continuous, treatment = NULL, strata = NULL,
trim = 0, B = 1000, main = NULL)
Arguments
continuous
Quantitative covariate that is being balanced within strata in a PSA.
If continuous has three columns, then the second and third are assumed to
be the treatment and strata respectively. Missing values are not allowed.
treatment
Binary variable of same length as continuous; generally 0 for 'control,' 1 for 'treatment.'
strata
Integer variable; a vector of same length as continuous indicating the
derived strata from estimated propensity scores.
trim
Fraction (0 to 0.5) of observations to be trimmed from each end of stratum-treatment
level before the mean is computed. See mean.
B
Numeric; number of randomly generated iterations of the balance
measure are created for the comparison distribution.
main
Title passed to histogram.
Details
This function measures the balance achieved across K strata for a continuous covariate.
If μ_{ik} is the covariate trimmed (as specified by user) mean of cases in stratum k, treatment i,
then the statistic is the sum over all K of |μ_{0k} - μ_{1k}| . A permutation distribution
is generated by randomly assigning cases to strata, thus generating B permuted stratifications and the associated B permutation statistics.
The permutation stratifications are generated under a fixed marginals model to retain comparability with the original stratification.
A histogram of the permutation statistics is produced with the original statistic referenced as a red dot.
Value
In addition to the histogram, a list with the following components is returned:
balance.orig
Balance measure of user defined strata.
rank.orig
Rank of original balance measure in comparison
with the B randomly generated values.
#Balance stat should be close to zero
meas<-rnorm(500)
continuous<-c(meas,meas+rnorm(500,0,.1))
treatment<-c(rep(0,500),rep(1,500))
strata<-rep(c(rep(1,100),rep(2,100),rep(3,100),rep(4,100),rep(5,100)),2)
bal.ms.psa(continuous,treatment,strata)
#Balance stat should be close to .4
meas<-rnorm(500)
continuous<-c(meas, meas[1:250] + runif(250,0,.2),
meas[251:500]-runif(250,0,.2))
treatment<-c(rep(0,500),rep(1,500))
strata<-rep(c(rep(1,100), rep(2,100), rep(3,100),
rep(4,100),rep(5,100)),2)
bal.ms.psa(continuous, treatment, strata, B=200)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(PSAgraphics)
Loading required package: rpart
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/PSAgraphics/bal.ms.psa.Rd_%03d_medium.png", width=480, height=480)
> ### Name: bal.ms.psa
> ### Title: Balance for Continuous Covariate: Random Strata as part of a PSA
> ### Aliases: bal.ms.psa
> ### Keywords: htest
>
> ### ** Examples
> #Balance stat should be close to zero
> meas<-rnorm(500)
> continuous<-c(meas,meas+rnorm(500,0,.1))
> treatment<-c(rep(0,500),rep(1,500))
> strata<-rep(c(rep(1,100),rep(2,100),rep(3,100),rep(4,100),rep(5,100)),2)
> bal.ms.psa(continuous,treatment,strata)
$balance.orig
[1] 0.008945753
$rank.orig
[1] 1
>
>
> #Balance stat should be close to .4
> meas<-rnorm(500)
> continuous<-c(meas, meas[1:250] + runif(250,0,.2),
+ meas[251:500]-runif(250,0,.2))
> treatment<-c(rep(0,500),rep(1,500))
> strata<-rep(c(rep(1,100), rep(2,100), rep(3,100),
+ rep(4,100),rep(5,100)),2)
> bal.ms.psa(continuous, treatment, strata, B=200)
$balance.orig
[1] 0.08306724
$rank.orig
[1] 59
>
>
>
>
>
> dev.off()
null device
1
>