runFLPS.Rd
Conduct fully latent principal stratification
runFLPS(
inp_data = NULL,
compiled_stan = NULL,
outcome = NULL,
trt = NULL,
covariate = NULL,
lv_model = NULL,
lv_type = NULL,
multilevel = FALSE,
lv_randomeffect = FALSE,
priors_input = NULL,
stan_options = list(),
...
)
A matrix or data frame containing the input data.
An object of S4 class stanmodel produced by the
modelBuilder
function.
A character string specifying the outcome variable's name.
A character string specifying the treatment or control group variable's name.
A character string specifying the covariate variable names.
A description of the latent variable model using syntax akin to the lavaan package. Key operators include:
=~
: Denotes associations between factors and indicators (e.g., F1 =~ v1 + v2 + v3). All indicators associated with the corresponding factor should be
written in the same line with +
.
+
: Specifies a series of indicators.
A character string indicating the type of latent variable models.
A logical indicating if a multilevel structure is present.
A logical indicating whether to estimate random effects for latent variables.
A list specifying the priors or defaults to N(0, 5) if not provided.
Relevant parameters: tau0
(group difference), tau1
(principal effects),
and omega
(effect of latent factors on outcome).
Ensure that the lengths of tau1
and omega
match the number of factors.
Examples:
list(tau0 = c(0, 1), tau1 = c(0.5, 1))
: Mean and variance for normal priors.
list(tau1 = list(c(0.5, 1), c(-0.4, 1)))
: For two factors.
A list of options for [rstan::stan()], specified as 'name = value'.
Additional parameters for the latent variable models, such as nclass = 2
.
An object of class flps
encompassing a stanfit
object.
Components include:
Function call with arguments.
The input data frame provided.
The Stan syntax used in [rstan::stan()].
Data list used for [rstan::stan()].
Resulting stanfit
object.
A numeric; Time taken for computation
[rstan::stan()]
# \donttest{
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)
)
#> It will take a while....
#> Compiling Stan code...
#>
#> SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 1).
#> Chain 1:
#> Chain 1: Gradient evaluation took 0.001305 seconds
#> Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 13.05 seconds.
#> Chain 1: Adjust your expectations accordingly!
#> Chain 1:
#> Chain 1:
#> Chain 1: Iteration: 1 / 1000 [ 0%] (Warmup)
#> Chain 1: Iteration: 100 / 1000 [ 10%] (Warmup)
#> Chain 1: Iteration: 200 / 1000 [ 20%] (Warmup)
#> Chain 1: Iteration: 300 / 1000 [ 30%] (Warmup)
#> Chain 1: Iteration: 400 / 1000 [ 40%] (Warmup)
#> Chain 1: Iteration: 500 / 1000 [ 50%] (Warmup)
#> Chain 1: Iteration: 501 / 1000 [ 50%] (Sampling)
#> Chain 1: Iteration: 600 / 1000 [ 60%] (Sampling)
#> Chain 1: Iteration: 700 / 1000 [ 70%] (Sampling)
#> Chain 1: Iteration: 800 / 1000 [ 80%] (Sampling)
#> Chain 1: Iteration: 900 / 1000 [ 90%] (Sampling)
#> Chain 1: Iteration: 1000 / 1000 [100%] (Sampling)
#> Chain 1:
#> Chain 1: Elapsed Time: 23.357 seconds (Warm-up)
#> Chain 1: 9.724 seconds (Sampling)
#> Chain 1: 33.081 seconds (Total)
#> Chain 1:
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#bulk-ess
# }