Description Usage Arguments Details Value See Also Examples
View source: R/functions_exposure_model.R
Creates a list object that follows the structure required by the exposure models that are implemented in STAN.
1 2 3 4 5 6 7 8 9 10 11 |
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 |
Mt |
Matrix of splines values for time to include in the model. Defaults to NULL, and can be added later via |
log_transform |
Should the concentration value be log-transformed? |
return_addition |
See 'Value'. |
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
.
A list of class standata_exposure
that contains the following:
G
– Number of groups
K
– Number of clusters.
n
Number of households
N
– Number of observations
cluster_of_obs
– Integer providing cluster number of each observation
group_of_obs
– Integer providing group number of each observation
hh_of_obs
– Integer providing household number of each observation
w
– Concentration observations
times
– The date/time of each observation. This is not used directly in model fitting, but contained in the object to facilitate plotting and other summaries.
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).
sample_exposure_model
, create_spline
, add_spline_time
, create_standata_outcome
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.