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(),
  ...
)

Arguments

inp_data

A matrix or data frame containing the input data.

compiled_stan

An object of S4 class stanmodel produced by the modelBuilder function.

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:

  • =~ : 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.

lv_type

A character string indicating the type of latent variable models.

multilevel

A logical indicating if a multilevel structure is present.

lv_randomeffect

A logical indicating whether to estimate random effects for latent variables.

priors_input

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.

stan_options

A list of options for [rstan::stan()], specified as 'name = value'.

...

Additional parameters for the latent variable models, such as nclass = 2.

Value

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 stanfit object.

time

A numeric; Time taken for computation

See also

[rstan::stan()]

Examples

# \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
# }