create_standata_exposure: Create List for Fitting Exposure Model via STAN

Description Usage Arguments Details Value See Also Examples

View source: R/functions_exposure_model.R

Description

Creates a list object that follows the structure required by the exposure models that are implemented in STAN.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
create_standata_exposure(
  data = NULL,
  group = data$group,
  conc = data$conc,
  unit_id = data$unit_id,
  clust_id = data$clust_id,
  time = data$time,
  Mt = NULL,
  log_transform = FALSE,
  return_addition = FALSE
)

Arguments

data

Optional data frame containing data in a long format.

group

Vector of group assignments. See Details.

conc

Vector of exposure concentrations.

unit_id

Vector identifying the distinct unit (e.g. person, household) for each observation.

clust_id

Vector identifying cluster membership for each observation.

time

Vector of times corresponding to conc values.

Mt

Matrix of splines values for time to include in the model. Defaults to NULL, and can be added later via add_spline_time. See create_spline for creating this matrix.

log_transform

Should the concentration value be log-transformed?

return_addition

See 'Value'.

Details

This function takes as input a 'long' data frame and extracts from it the information needed for fitting the exposure model in STAN.

The values of group, unit_id, and clust_id are converted to factor and then coerced to integer. The ordering of groups (units, clusters) in the output object will depend on the default ordering introduced by factor.

Value

A list of class standata_exposure that contains the following:

If return_addition=TRUE, then a two-element list is returned. The first element is the standata_exposure object described above. The second element is a modified version of data, with the variables group_of_obs, cluster_of_obs, hh_of_obs, and times added (or overwritten).

See Also

sample_exposure_model, create_spline, add_spline_time, create_standata_outcome

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Create simulated data
exp_data <- create_standata_exposure(group=rep(1, 10),
                                     conc=rnorm(10),
                                     unit_id=rep(0:1, 5),
                                     time=runif(10))
# Add default priors
exp_data <- add_priors(exp_data,
                       sigmaI=c(0, 0.1))
# Fit the model
exp_mod_fit <- sample_exposure_model(exp_data)

jpkeller/bercs documentation built on March 24, 2021, 5:36 a.m.