R/post_processing.R
make_post_prop_long.Rd
This function processes posterior draws from a Stan model to compute mean and highest density credible intervals (HDI) for mixing proportions. It reshapes the data into a long format for comparison with observed values.
make_post_prop_long(modfit, mu_tab, data_streams_list, n, ...)
A fitted Stan model object containing posterior draws.
Typically produced by function run_mixmustr_models
.
A data frame containing the mean tracer
signatures for each source. The first column should be named source
, and
the remaining columns should contain numeric tracer values.
A list containing the input
data streams for the model. It should include two
data frames named df_stream_1
anddf_stream_2
. See
details for the expected structure of these.
A numeric or character value representing the variant identifier for the model.
Further arguments passed to reshape_ref_data
.
A data frame in long format with the following columns:
Integer. The observation index.
Character. The source identifier (e.g., sampled sources or "Unsampled").
Numeric. The mean posterior predicted value for the mixing proportion.
Numeric. The lower bound of the 95% HDI for the predicted value.
Numeric. The upper bound of the 95% HDI for the predicted value.
Numeric. The observed mixing proportion for the corresponding source.
Character. The variant identifier for the dataset.
The function extracts posterior draws of mixing proportions from the fitted Stan model (modfit
) and computes the mean and HDI for each source. It then aligns these predictions with observed values from the input data streams (data_streams_list
) and reshapes the data into a long format for further analysis or visualization.
The Variant:
column is used to distinguish between different models.
if (FALSE) { # \dontrun{
library(MixMustR)
# mixmustr_models[6, ] runs quickest
model_fits <- run_mixmustr_models(
mixmustr_models[6, ], synthetic_df_convergent, tracer_parameters,
sigma_ln_rho = 0.1, iter = 1e4, warmup = 5e3, chains = 4, cores = 4
)
make_post_prop_long(model_fits[[1]]$model, tracer_parameters$mus,
synthetic_df_convergent, target = "df_stream_2", n = 1)
} # }