Title: | Fully-Latent Principal Stratification |
---|---|
Description: | Simulation and analysis of Fully-Latent Principal Stratification (FLPS) with measurement models. Lee, Adam, Kang, & Whittaker (2023). <doi:10.1007/978-3-031-27781-8_25>. This package is supported by the Institute of Education Sciences, U.S. Department of Education, through Grant R305D210036. |
Authors: | Sooyong Lee [aut, cre], Adam Sales [aut], Hyeon-Ah Kang [aut], Tiffany Whittaker [aut] |
Maintainer: | Sooyong Lee <[email protected]> |
License: | GPL-3 |
Version: | 1.1.0 |
Built: | 2024-11-17 04:57:07 UTC |
Source: | https://github.com/sooyongl/flps |
The FLPS package conducts Bayesian analysis for fully latent principal stratification via rstan.
_PACKAGE
The 'flps' package.
Sooyong Lee [email protected]
Sales, A. C., & Pane, J. F. (2019). The role of mastery learning in an intelligent tutoring system: Principal stratification on a latent variable. The Annals of Applied Statistics, 13(1), 420-443. Lee, S., Adam, S., Kang, H.-A., & Whittaker, T. A. (2022). Fully latent principal stratification: Combining ps with model-based measurement models. In The annual meeting of the psychometric society (pp. 287–298).
A data set containing binary items information. Example data regenerated from CTA1
binary
binary
A data frame with variables:
School ID
Student ID
0 = boys; 1 = girls
0 = White; 1 = Others
Pre test scores
Standardized scores
Cluster-mean of sex
Cluster-mean of race
Cluster-mean of Pre test scores
Cluster-mean of of Standardized scores
Treatment assignment; 0 = control, 1 = treatment
Outcome
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
CTA1
data(binary) summary(binary)
data(binary) summary(binary)
A data set containing continuous items information. Example data regenerated from CTA1
continuous
continuous
A data frame with variables:
School ID
Student ID
0 = boys; 1 = girls
0 = White; 1 = Others
Pre test scores
Standardized scores
Cluster-mean of sex
Cluster-mean of race
Cluster-mean of Pre test scores
Cluster-mean of of Standardized scores
Treatment assignment; 0 = control, 1 = treatment
Outcome
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
CTA1
data(continuous) summary(continuous)
data(continuous) summary(continuous)
A generated data set for rasch FLPS to mimic CTA1 data.
example0
example0
A data frame with variables:
Outcome
Treatment assignment; 0 = control, 1 = treatment
0 = boys; 1 = girls
0 = White; 1 = Others
Pre test scores
Standardized scores
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
A generated data set containing binary items information.
example1
example1
A data frame with variables:
Outcome
Treatment assignment; 0 = control, 1 = treatment
Continuous covariate 1
Continuous covariate 2
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
Binary item
A generated data set containing continuous items information.
example2
example2
A data frame with variables:
Outcome
Treatment assignment; 0 = control, 1 = treatment
Continuous covariate 1
Continuous covariate 2
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
A generated data set for multidimensional FLPS.
example3
example3
A data frame with variables:
Outcome
Treatment assignment; 0 = control, 1 = treatment
Continuous covariate 1
Continuous covariate 2
Continuous covariate 2
Continuous covariate 2
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Continuous item
Make plots related to FLPS models
flps_plot(object, type = "causal", ...)
flps_plot(object, type = "causal", ...)
object |
a |
type |
a character indicating the type of plots |
... |
Additional features related to plots |
A ggplot
object that can be further customized
using the ggplot2 package.
A data set containing graded response items information. Example data regenerated from CTA1
graded
graded
A data frame with variables:
School ID
Student ID
0 = boys; 1 = girls
0 = White; 1 = Others
Pre test scores
Standardized scores
Cluster-mean of sex
Cluster-mean of race
Cluster-mean of Pre test scores
Cluster-mean of of Standardized scores
Treatment assignment; 0 = control, 1 = treatment
Outcome
Graded response item
Graded response item
Graded response item
Graded response item
Graded response item
Graded response item
Graded response item
Graded response item
Graded response item
Graded response item
Graded response item
Graded response item
Graded response item
Graded response item
Graded response item
Graded response item
Graded response item
Graded response item
Graded response item
Graded response item
CTA1
data(graded) summary(graded)
data(graded) summary(graded)
Import compiled Stan object
importModel(lv_type, multilevel = FALSE, lv_randomeffect = FALSE)
importModel(lv_type, multilevel = FALSE, lv_randomeffect = FALSE)
lv_type |
a character indicating the type of FLPS model. |
multilevel |
a logical indicating multilevel Stan model. |
lv_randomeffect |
A logical indicating whether to estimate random effects for latent variables. |
a Stan compiled stanmodel object generated by modelBuilder
makeInpData
is a function for generating a data based on
the given information.
makeInpData( N, R2Y, R2eta, omega, tau0, tau1, betaL, betaY, linear = TRUE, ydist = "n", lambda, nitem, nfac = 1, lvmodel, fcovmat, item.missing = TRUE, misspec = FALSE, cov.res = 0, relsize = 0.6 )
makeInpData( N, R2Y, R2eta, omega, tau0, tau1, betaL, betaY, linear = TRUE, ydist = "n", lambda, nitem, nfac = 1, lvmodel, fcovmat, item.missing = TRUE, misspec = FALSE, cov.res = 0, relsize = 0.6 )
N |
a numeric indicating sample size. |
R2Y |
a numeric indicating predictive power of covariates. |
R2eta |
a numeric indicating Predictive power of latent variable |
omega |
a numeric indicating the size of effect of latent factor on the outcome. |
tau0 |
a numeric indicating the size of difference in the outcome between the treatment and the control. |
tau1 |
a numeric indicating the principal effect |
betaL |
a numeric vector indicating the effects of covariates on the latent factor |
betaY |
a numeric vector indicating the effects of covariates on the outcome |
linear |
a logical whether the relationship between the outcome and covariates is linear (default is |
ydist |
a character indicating the outcome distribution (default is |
lambda |
a numeric indicating the mean of Worked problems/person. (extent to which covariates predict eta). |
nitem |
a numeric indicating the number of maximum measurement items given to students. |
nfac |
a numeric indicating the number of latent factors |
lvmodel |
a character specifying a type of latent variable model. |
fcovmat |
a matrix indicating the variance-covariance matrix of latent factors when nfac > 1 |
item.missing |
a logical to make the measurement item data missing for
the control group (default is |
misspec |
a logical to allow cross-loadings across latent factors
when nfac > 1 (default is |
cov.res |
a logical to allow for residual correlations
(only for CFA model) (default is |
relsize |
a numeric indicating the degree to which the latent factor explain the variances of continuous items (only for CFA model) (default is |
a list containing all the data related to population values and running FLPS.
sdat <- makeInpData( N = 200, # sample size R2Y = 0.2, # r^2 of outcome R2eta = 0.5, # r^2 of eta by one covariates omega = 0.2, # the effect of eta tau0 = 0.13, # direct effect tau1 = -0.06,# interaction effect between Z and eta betaL = 0.2, betaY = 0.4, lambda = 0.8, # the proportion of administered items nitem = 10, # the total number of items nfac = 1, # the number of latent factors lvmodel = '2pl' )
sdat <- makeInpData( N = 200, # sample size R2Y = 0.2, # r^2 of outcome R2eta = 0.5, # r^2 of eta by one covariates omega = 0.2, # the effect of eta tau0 = 0.13, # direct effect tau1 = -0.06,# interaction effect between Z and eta betaL = 0.2, betaY = 0.4, lambda = 0.8, # the proportion of administered items nitem = 10, # the total number of items nfac = 1, # the number of latent factors lvmodel = '2pl' )
makeInpData
is a function for generating a data based on
the given information.
makeSimData( N, R2Y, R2eta, omega, tau0, tau1, betaL, betaY, linear = TRUE, ydist = "n", lambda, nitem, nfac, lvmodel, fcovmat, item.missing = TRUE, misspec = FALSE, cov.res = 0, relsize = 0.6 )
makeSimData( N, R2Y, R2eta, omega, tau0, tau1, betaL, betaY, linear = TRUE, ydist = "n", lambda, nitem, nfac, lvmodel, fcovmat, item.missing = TRUE, misspec = FALSE, cov.res = 0, relsize = 0.6 )
N |
a numeric indicating sample size. |
R2Y |
a numeric indicating predictive power of covariates. |
R2eta |
a numeric indicating Predictive power of latent variable |
omega |
a numeric indicating the size of effect of latent factor on the outcome. |
tau0 |
a numeric indicating the size of difference in the outcome between the treatment and the control. |
tau1 |
a numeric indicating the principal effect |
betaL |
a numeric vector indicating the effects of covariates on the latent factor |
betaY |
a numeric vector indicating the effects of covariates on the outcome |
linear |
a logical whether the relationship between the outcome and covariates is linear (default is |
ydist |
a character indicating the outcome distribution (default is |
lambda |
a numeric indicating the mean of Worked problems/person. (extent to which covariates predict eta). |
nitem |
a numeric indicating the number of maximum measurement items given to students. |
nfac |
a numeric indicating the number of latent factors |
lvmodel |
a character specifying a type of latent variable model. |
fcovmat |
a matrix indicating the variance-covariance matrix of latent factors when nfac > 1 |
item.missing |
a logical to make the measurement item data missing for
the control group (default is |
misspec |
a logical to allow cross-loadings across latent factors
when nfac > 1 (default is |
cov.res |
a logical to allow for residual correlations
(only for CFA model) (default is |
relsize |
a numeric indicating the degree to which the latent factor explain the variances of continuous items (only for CFA model) (default is |
a list containing all the data related to population values and running FLPS.
sdat <- makeSimData( N = 200, # sample size R2Y = 0.2, # r^2 of outcome R2eta = 0.5, # r^2 of eta by one covariates omega = 0.2, # the effect of eta tau0 = 0.13, # direct effect tau1 = -0.06,# interaction effect between Z and eta betaL = 0.2, betaY = 0.4, lambda = 0.8, # the proportion of administered items nitem = 10, # the total number of items nfac = 1, # the number of latent factors lvmodel = '2pl' )
sdat <- makeSimData( N = 200, # sample size R2Y = 0.2, # r^2 of outcome R2eta = 0.5, # r^2 of eta by one covariates omega = 0.2, # the effect of eta tau0 = 0.13, # direct effect tau1 = -0.06,# interaction effect between Z and eta betaL = 0.2, betaY = 0.4, lambda = 0.8, # the proportion of administered items nitem = 10, # the total number of items nfac = 1, # the number of latent factors lvmodel = '2pl' )
Generate compiled Stan object to facilitate the analysis
modelBuilder(lv_type, multilevel = FALSE, lv_randomeffect = FALSE)
modelBuilder(lv_type, multilevel = FALSE, lv_randomeffect = FALSE)
lv_type |
A character string specifying the type of FLPS model |
multilevel |
a logical indicating multilevel Stan model. |
lv_randomeffect |
A logical indicating whether to estimate random effects for latent variables. |
There's no return, but the compiled objects are saved in the package root directory.
Plot
## S3 method for class 'flps' plot(x, type = NULL, pars = c("tau0", "tau1"), ...)
## S3 method for class 'flps' plot(x, type = NULL, pars = c("tau0", "tau1"), ...)
x |
an object of class |
type |
a string for the type of plot |
pars |
a character vector indicating the target parameters |
... |
additional options for |
A ggplot
object that can be further customized
using the ggplot2 package.
Print results
## S3 method for class 'flps' print(x, ...)
## S3 method for class 'flps' print(x, ...)
x |
an object of class |
... |
additional options for future development |
Summary of FLPS model are printed.
Print summary of results
## S3 method for class 'summary.flps' print(x, type = "structures", ...)
## S3 method for class 'summary.flps' print(x, type = "structures", ...)
x |
an object of class |
type |
a string for the part of FLPS model
|
... |
additional options for future development |
Summary of FLPS model are printed.
Conduct fully latent principal stratification
runFLPS( inp_data = NULL, compiled_stan = NULL, outcome = NULL, trt = NULL, covariate = NULL, lv_model = NULL, lv_type = NULL, priors_input = NULL, stan_options = list(), ... )
runFLPS( inp_data = NULL, compiled_stan = NULL, outcome = NULL, trt = NULL, covariate = NULL, lv_model = NULL, lv_type = NULL, priors_input = NULL, stan_options = list(), ... )
inp_data |
A matrix or data frame containing the input data. |
compiled_stan |
An object of S4 class stanmodel produced by the
|
outcome |
A character string specifying the outcome variable's name. |
trt |
A character string specifying the treatment or control group variable's name. |
covariate |
A character string specifying the covariate variable names. |
lv_model |
A description of the latent variable model using syntax akin to the lavaan package. Key operators include:
|
lv_type |
A character string indicating the type of latent variable models. |
priors_input |
A list specifying the priors or defaults to N(0, 5) if not provided.
Relevant parameters:
|
stan_options |
A list of options for [rstan::stan()], specified as 'name = value'. |
... |
Additional parameters for the latent variable models
|
An object of class flps
encompassing a stanfit
object.
Components include:
call |
Function call with arguments. |
inp_data |
The input data frame provided. |
flps_model |
The Stan syntax used in [rstan::stan()]. |
flps_data |
Data list used for [rstan::stan()]. |
flps_fit |
Resulting |
time |
A numeric; Time taken for computation |
[rstan::stan()]
inp_data <- flps::makeInpData( N = 200, R2Y = 0.2, R2eta = 0.5, omega = 0.2, tau0 = 0.23, tau1 = -0.16, betaL = 0.1, betaY = 0.2, lambda = 0.8, nitem = 10, nfac = 1, lvmodel = 'rasch' ) res <- runFLPS( inp_data = inp_data, outcome = "Y", trt = "Z", covariate = c("X1"), lv_type = "rasch", lv_model = "F =~ v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10", stan_options = list(iter = 1000, warmup = 500, cores = 1, chains = 2) )
inp_data <- flps::makeInpData( N = 200, R2Y = 0.2, R2eta = 0.5, omega = 0.2, tau0 = 0.23, tau1 = -0.16, betaL = 0.1, betaY = 0.2, lambda = 0.8, nitem = 10, nfac = 1, lvmodel = 'rasch' ) res <- runFLPS( inp_data = inp_data, outcome = "Y", trt = "Z", covariate = c("X1"), lv_type = "rasch", lv_model = "F =~ v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10", stan_options = list(iter = 1000, warmup = 500, cores = 1, chains = 2) )
Summarize the results
## S3 method for class 'flps' summary(object, type = "structures", ...)
## S3 method for class 'flps' summary(object, type = "structures", ...)
object |
an object of class |
type |
a string for the part of FLPS model
|
... |
additional options for future development |
Summary of FLPS model are printed.