runFLPS {flps}R Documentation

Conduct fully latent principal stratification

Description

Conduct fully latent principal stratification

Usage

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

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.

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

  • nclass A number specifying the number of latent classes.

  • multilevel A logical indicating if a multilevel structure is present.

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

  • group_id A string for grouping variable for multilevel structure.

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


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)
   )



[Package flps version 1.1.0 Index]