stratacont: Stratacont()

Description Usage Arguments Details Examples

Description

This is the primary stratification function for continuous outcome variables.It locates naturally occurring strata in the data, weights them and returns an improved regression coefficient for the treatment variable which is adjusted for both confounding and interaction terms. Returns a matrix containig naturally occurring strata.

Usage

1
stratacont(Treatment,Outcome,Matrix)

Arguments

Treatment

Column number of variable to be used as treatment.

Outcome

Column number of variable to be used as outcome.

Matrix

Name of matrix or data.frame where data is stored.

Details

This is the primary stratification function for continuous outcome variables.It locates naturally occurring strata in the data, weights them and returns an improved regression coefficient for the treatment variable which is adjusted for both confounding and interaction terms.

Examples

 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
## We will first begin by simulating data in 5 covariates and a continuous outcome
## with significant interaction terms and correlations amongst covariates (to simulate an
## experiment with a strongly non-linear underlying model).
## First, we will create a matrix with the input variables. The inout variables will all be
## categorical variables.
m=matrix(nrow=5000,ncol=6)
for ( i in 1:ncol(m)){
m[,i]=rbinom(5000,1,0.5)
}


## Next, we will simulate the output variable and include interaction terms
for(i in 1:nrow(m)){
a=(2*m[i,5] + 0.5*m[i,1] + 4*m[i,2] + 2.3*m[i,3] + 5*m[i,4] +
2.3*m[i,3]*m[i,2] +3.5*m[i,1]*m[i,2] + 2.1*m[i,1]*m[i,3] +
5*m[i,1]*m[i,2]*m[i,3] + 6*m[i,1]*m[i,4] +3*m[i,2]*m[i,4] +
2*m[i,3]*m[i,4] + 3.4*m[i,1]*m[i,2]*m[i,3]*m[i,4] +
5*m[i,1]*m[i,2]*m[i,4] + 4*m[i,2]*m[i,3]*m[i,4])
m[i,6]=rnorm(1,a,1)
}
## We are interested in determining the coefficient of covariate 5 which is 2.
## Tmost straightforward
## way of doing this is to use simple linear regression as follows
m=as.data.frame(m)
k=lm(m[,6]~.,data=m[,(1:5)])
## The value of the coefficient of variable 5 found by the regression can be retrieved using
k$coeff[6]

## We can now use the stratacont() function to find a more accurate estimation of the coefficient
g=stratacont(5,6,m)
## Note that as the model includes more covariates, the accuracy of the stratification
## techniques is far superior.


Search within the StratifiedBalancing package
Search all R packages, documentation and source code

Questions? Problems? Suggestions? or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.