This function is the main funtion of the package and can be used to estimate
average and conditional effects of a treatment variable on an outcome variable,
taking into account any number of continuous and categorical covariates.
It automatically generates lavaan syntax for a multi-group structural equation
model, runs the model using lavaan, and extracts various average and conditional
effects of interest.
Dependent variable (character string). Can be the name of a manifest variable or of a latent variable.
x
Treatment variable (character string) treated as categorical variable.
k
Vector of manifest variables treated as categorical covariates (character vector).
z
Vector of continuous covariates (character vector). Names of both manifest and latent variables are allowed.
control
Value of x that is used as control group.
measurement
Measurement model. The measurement model is lavaan syntax (character string), that will be appended before the automatically generated lavaan input. It can be used to specify a measurement for a latent outcome variable and/or latent covariates. See also the example and generateMeasurementModel.
data
A data frame.
fixed.cell
logical. If FALSE (default), the group sizes are treated as stochastic rather than fixed.
fixed.z
logical. If FALSE (default), the continuous covariates are treated as stochastic rather than fixed. fixed.z
missing
Missing data handling. Will be passed on to sem.
se
Type of standard errors. Will be
passed on to sem.
bootstrap
Number of bootstrap draws, if bootstrapping is used. Will be
passed on to sem.
mimic
Will be passed on to sem.
syntax.only
logical. If TRUE, only syntax is returned and the model
will not be estimated.
interactions
character. Can be one of c("all","none","2-way","X:K","X:Z") and indicates the type of interaction used in the parameterization of the regression.
propscore
Vector of covariates (character vector) that will be used to compute (multiple) propensity scores based on a multinomial regression without interactions. Alternatively, the user can specify a formula with the treatment variable as dependent variable for more control over the propensity score model.
ids
Formula specifying cluster ID variables. Will be passed on to lavaan.survey. See svydesign for details.
weights
Formula to specify sampling weights. Currently only one weight variable is supported. Will be passed on to lavaan.survey. See svydesign for details. Note: Only use weights if you know what you are doing. For example, some conditional treatment effects may require different weights than average effects.
homoscedasticity
logical. If TRUE, residual variances of the dependent variable are assumed to be homogeneous across cells.
add
Character string that will be pasted at the end of the generated lavaan syntax. Can for example be used to add additional (in-) equality constraints or to compute user-defined conditional effects.
...
Further arguments passed to sem. Currently not used.
Value
Object of class effectlite.
Examples
## Example with one categorical covariate
m1 <- effectLite(y="y", x="x", k="z", control="0", data=nonortho)
print(m1)
## Example with one categorical and one continuous covariate
m1 <- effectLite(y="dv", x="x", k=c("k1"), z=c("z1"), control="control", data=example01)
print(m1)
## Example with latent outcome and latent covariate
measurement <- '
eta2 =~ 1*CPM12 + 1*CPM22
eta1 =~ 1*CPM11 + 1*CPM21
CPM11 + CPM12 ~ 0*1
CPM21 ~ c(m,m)*1
CPM22 ~ c(p,p)*1'
m1 <- effectLite(y="eta2", x="x", z=c("eta1"), control="0",
measurement=measurement, data=example02lv)
print(m1)
## Not run:
## Example with cluster variable and sampling weights
m1 <- effectLite(y="y", x="x", z="z", fixed.cell=TRUE, control="0",
syntax.only=F, data=example_multilevel,
ids=~cid, weights=~weights)
print(m1)
## End(Not run)
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(EffectLiteR)
Loading required package: lavaan
This is lavaan 0.5-20
lavaan is BETA software! Please report any bugs.
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/EffectLiteR/effectLite.Rd_%03d_medium.png", width=480, height=480)
> ### Name: effectLite
> ### Title: Estimate average and conditional effects
> ### Aliases: effectLite
>
> ### ** Examples
>
> ## Example with one categorical covariate
> m1 <- effectLite(y="y", x="x", k="z", control="0", data=nonortho)
> print(m1)
--------------------- Variables ---------------------
Outcome variable Y: y
Treatment variable X: x (Reference group: 0)
Categorical covariates K: z
Levels of Unfolded Categorical Covariate K
K z
0 0
1 1
2 2
--------------------- Regression Model ---------------------
E(Y|X,K) = g0(K) + g1(K)*I_X=1 + g2(K)*I_X=2
g0(K) = g000 + g010 * I_K=1 + g020 * I_K=2
g1(K) = g100 + g110 * I_K=1 + g120 * I_K=2
g2(K) = g200 + g210 * I_K=1 + g220 * I_K=2
Intercept Function g0(K)
Coefficient Estimate SE Est./SE p-value
g000 119.968 2.189 54.815 0.000
g010 -11.252 3.252 -3.460 0.001
g020 -60.088 4.716 -12.740 0.000
Effect Function g1(K) [x: 1 vs. 0]
Coefficient Estimate SE Est./SE p-value
g100 -16.549 5.143 -3.218 0.001
g110 6.230 5.961 1.045 0.296
g120 56.554 7.486 7.555 0.000
Effect Function g2(K) [x: 2 vs. 0]
Coefficient Estimate SE Est./SE p-value
g200 -28.943 6.267 -4.618 0.000
g210 15.181 7.198 2.109 0.035
g220 108.272 7.870 13.758 0.000
--------------------- Cell Counts ---------------------
Cells
X K Cell
1 0 0 00
2 0 1 01
3 0 2 02
4 1 0 10
5 1 1 11
6 1 2 12
7 2 0 20
8 2 1 21
9 2 2 22
Cell Counts
This table shows cell counts including missings.
See also output under lavaan results for number of observations
actually used in the analysis.
z 0 1 2
x
0 87 79 13
1 26 117 33
2 6 59 80
--------------------- Main Hypotheses ---------------------
Wald Chi-Square df p-value
No average effects 4.28 2 0.118
No covariate effects in control group 163 2 0
No treatment*covariate interaction 306 4 0
No treatment effects 351 6 0
--------------------- Adjusted Means ---------------------
Estimate SE Est./SE
Adj.Mean0 99.1 1.99 49.8
Adj.Mean1 100.0 1.69 59.1
Adj.Mean2 105.2 2.20 47.9
--------------------- Average Effects ---------------------
Estimate SE Est./SE p-value Effect Size
E[g1(K)] 0.88 2.60 0.338 0.7354 0.0345
E[g2(K)] 6.08 3.26 1.867 0.0618 0.2383
--------------------- Effects given a Treatment Condition ---------------------
Estimate SE Est./SE p-value Effect Size
E[g1(K)|X=0] -9.69 3.05 -3.177 1.49e-03 -0.3796
E[g2(K)|X=0] -14.38 4.00 -3.597 3.22e-04 -0.5632
E[g1(K)|X=1] -1.80 2.82 -0.640 5.22e-01 -0.0706
E[g2(K)|X=1] 1.45 3.91 0.371 7.11e-01 0.0568
E[g1(K)|X=2] 17.19 3.87 4.440 8.98e-06 0.6732
E[g2(K)|X=2] 36.97 4.93 7.495 6.62e-14 1.4480
--------------------- Effects given K=k ---------------------
Estimate SE Est./SE p-value Effect Size
E[g1(K)|K=0] -16.5 5.14 -3.22 1.29e-03 -0.648
E[g2(K)|K=0] -28.9 6.27 -4.62 3.87e-06 -1.134
E[g1(K)|K=1] -10.3 3.01 -3.42 6.18e-04 -0.404
E[g2(K)|K=1] -13.8 3.54 -3.89 1.02e-04 -0.539
E[g1(K)|K=2] 40.0 5.44 7.35 1.91e-13 1.567
E[g2(K)|K=2] 79.3 4.76 16.67 0.00e+00 3.107
>
> ## Example with one categorical and one continuous covariate
> m1 <- effectLite(y="dv", x="x", k=c("k1"), z=c("z1"), control="control", data=example01)
> print(m1)
--------------------- Variables ---------------------
Outcome variable Y: dv
Treatment variable X: x (Reference group: control)
Categorical covariates K: k1
Continuous covariates Z: z1
Levels of Unfolded Categorical Covariate K
K k1
0 male
1 female
--------------------- Regression Model ---------------------
E(Y|X,K,Z) = g0(K,Z) + g1(K,Z)*I_X=1 + g2(K,Z)*I_X=2
g0(K,Z) = g000 + g001 * Z1 + g010 * I_K=1 + g011 * I_K=1 * Z1
g1(K,Z) = g100 + g101 * Z1 + g110 * I_K=1 + g111 * I_K=1 * Z1
g2(K,Z) = g200 + g201 * Z1 + g210 * I_K=1 + g211 * I_K=1 * Z1
Intercept Function g0(K,Z)
Coefficient Estimate SE Est./SE p-value
g000 0.074 0.053 1.407 0.160
g001 0.096 0.055 1.741 0.082
g010 -0.098 0.074 -1.335 0.182
g011 -0.128 0.075 -1.695 0.090
Effect Function g1(K,Z) [x: treat1 vs. control]
Coefficient Estimate SE Est./SE p-value
g100 -0.153 0.079 -1.941 0.052
g101 -0.158 0.081 -1.964 0.050
g110 0.277 0.110 2.528 0.011
g111 0.239 0.110 2.167 0.030
Effect Function g2(K,Z) [x: treat2 vs. control]
Coefficient Estimate SE Est./SE p-value
g200 0.017 0.074 0.235 0.814
g201 -0.126 0.076 -1.673 0.094
g210 0.011 0.107 0.099 0.922
g211 0.162 0.109 1.481 0.139
--------------------- Cell Counts ---------------------
Cells
X K Cell
1 control 0 00
2 control 1 01
3 treat1 0 10
4 treat1 1 11
5 treat2 0 20
6 treat2 1 21
Cell Counts
This table shows cell counts including missings.
See also output under lavaan results for number of observations
actually used in the analysis.
k1 0 1
x
0 333 353
1 304 311
2 373 326
--------------------- Main Hypotheses ---------------------
Wald Chi-Square df p-value
No average effects 0.478 2 0.787
No covariate effects in control group 4.91 3 0.179
No treatment*covariate interaction 13.2 6 0.0397
No treatment effects 13.8 8 0.0865
--------------------- Adjusted Means ---------------------
Estimate SE Est./SE
Adj.Mean0 0.02544 0.0369 0.690
Adj.Mean1 0.00998 0.0406 0.246
Adj.Mean2 0.04830 0.0385 1.253
--------------------- Average Effects ---------------------
Estimate SE Est./SE p-value Effect Size
E[g1(K,Z)] -0.0155 0.0549 -0.281 0.779 -0.0160
E[g2(K,Z)] 0.0229 0.0533 0.429 0.668 0.0237
--------------------- Effects given a Treatment Condition ---------------------
Estimate SE Est./SE p-value Effect Size
E[g1(K,Z)|X=0] -0.000807 0.0553 -0.0146 0.988 -0.000837
E[g2(K,Z)|X=0] 0.029903 0.0535 0.5586 0.576 0.031022
E[g1(K,Z)|X=1] -0.019769 0.0554 -0.3571 0.721 -0.020509
E[g2(K,Z)|X=1] 0.018403 0.0537 0.3424 0.732 0.019092
E[g1(K,Z)|X=2] -0.026031 0.0556 -0.4680 0.640 -0.027005
E[g2(K,Z)|X=2] 0.019886 0.0535 0.3719 0.710 0.020630
--------------------- Effects given K=k ---------------------
Estimate SE Est./SE p-value Effect Size
E[g1(K,Z)|K=0] -0.1527 0.0790 -1.933 0.0532 -0.1584
E[g2(K,Z)|K=0] 0.0176 0.0739 0.239 0.8112 0.0183
E[g1(K,Z)|K=1] 0.1246 0.0761 1.638 0.1014 0.1293
E[g2(K,Z)|K=1] 0.0282 0.0770 0.366 0.7142 0.0292
--------------------- Effects given X=x, K=k ---------------------
Estimate SE Est./SE p-value Effect Size
E[g1(K,Z)|X=0, K=0] -0.1368 0.0795 -1.720 0.0854 -0.1419
E[g2(K,Z)|X=0, K=0] 0.0304 0.0742 0.409 0.6822 0.0315
E[g1(K,Z)|X=1, K=0] -0.1605 0.0796 -2.018 0.0436 -0.1665
E[g2(K,Z)|X=1, K=0] 0.0114 0.0743 0.153 0.8781 0.0118
E[g1(K,Z)|X=2, K=0] -0.1606 0.0795 -2.021 0.0433 -0.1666
E[g2(K,Z)|X=2, K=0] 0.0113 0.0743 0.153 0.8785 0.0118
E[g1(K,Z)|X=0, K=1] 0.1275 0.0763 1.672 0.0946 0.1322
E[g2(K,Z)|X=0, K=1] 0.0294 0.0769 0.383 0.7020 0.0305
E[g1(K,Z)|X=1, K=1] 0.1178 0.0762 1.545 0.1222 0.1222
E[g2(K,Z)|X=1, K=1] 0.0252 0.0776 0.325 0.7448 0.0262
E[g1(K,Z)|X=2, K=1] 0.1279 0.0763 1.677 0.0935 0.1327
E[g2(K,Z)|X=2, K=1] 0.0297 0.0769 0.385 0.7000 0.0308
>
> ## Example with latent outcome and latent covariate
> measurement <- '
+ eta2 =~ 1*CPM12 + 1*CPM22
+ eta1 =~ 1*CPM11 + 1*CPM21
+ CPM11 + CPM12 ~ 0*1
+ CPM21 ~ c(m,m)*1
+ CPM22 ~ c(p,p)*1'
>
> m1 <- effectLite(y="eta2", x="x", z=c("eta1"), control="0",
+ measurement=measurement, data=example02lv)
> print(m1)
--------------------- Variables ---------------------
Outcome variable Y: eta2
Treatment variable X: x (Reference group: 0)
Continuous covariates Z: eta1
--------------------- Regression Model ---------------------
E(Y|X,Z) = g0(Z) + g1(Z)*I_X=1
g0(Z) = g000 + g001 * Z1
g1(Z) = g100 + g101 * Z1
Intercept Function g0(Z)
Coefficient Estimate SE Est./SE p-value
g000 0.214 0.048 4.443 0
g001 0.711 0.026 27.719 0
Effect Function g1(Z) [x: 1 vs. 0]
Coefficient Estimate SE Est./SE p-value
g100 1.006 0.118 8.524 0
g101 0.479 0.040 12.067 0
--------------------- Cell Counts ---------------------
Cells
X
0
1
Cell Counts
This table shows cell counts including missings.
See also output under lavaan results for number of observations
actually used in the analysis.
x 0 1
163 137
--------------------- Main Hypotheses ---------------------
Wald Chi-Square df p-value
No average effects 377 1 0
No covariate effects in control group 768 1 0
No treatment*covariate interaction 146 1 0
No treatment effects 818 2 0
--------------------- Adjusted Means ---------------------
Estimate SE Est./SE
Adj.Mean0 1.54 0.0986 15.6
Adj.Mean1 3.45 0.1536 22.4
--------------------- Average Effects ---------------------
Estimate SE Est./SE p-value Effect Size
E[g1(Z)] 1.9 0.0979 19.4 0 1.59
--------------------- Effects given a Treatment Condition ---------------------
Estimate SE Est./SE p-value Effect Size
E[g1(Z)|X=0] 1.33 0.118 11.2 0 1.11
E[g1(Z)|X=1] 2.58 0.108 24.0 0 2.15
>
> ## Not run:
> ##D ## Example with cluster variable and sampling weights
> ##D m1 <- effectLite(y="y", x="x", z="z", fixed.cell=TRUE, control="0",
> ##D syntax.only=F, data=example_multilevel,
> ##D ids=~cid, weights=~weights)
> ##D print(m1)
> ## End(Not run)
>
>
>
>
>
> dev.off()
null device
1
>