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

Arguments

modfit

A fitted Stan model object containing posterior draws. Typically produced by function run_mixmustr_models.

mu_tab

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.

data_streams_list

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.

n

A numeric or character value representing the variant identifier for the model.

...

Further arguments passed to reshape_ref_data.

Value

A data frame in long format with the following columns:

N

Integer. The observation index.

source

Character. The source identifier (e.g., sampled sources or "Unsampled").

Predicted

Numeric. The mean posterior predicted value for the mixing proportion.

ymin

Numeric. The lower bound of the 95% HDI for the predicted value.

ymax

Numeric. The upper bound of the 95% HDI for the predicted value.

Observed

Numeric. The observed mixing proportion for the corresponding source.

Variant:

Character. The variant identifier for the dataset.

Details

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.

Examples

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