Run the mixture model with MCMC.

```
hb_mcmc_mixture(
data,
response = "response",
study = "study",
study_reference = max(data[[study]]),
group = "group",
group_reference = min(data[[group]]),
patient = "patient",
covariates = grep("^covariate", colnames(data), value = TRUE),
s_delta = 30,
s_beta = 30,
s_sigma = 30,
m_omega = c(0, 0),
s_omega = c(30, 30),
p_omega = 1/length(m_omega),
n_chains = 4,
n_adapt = 2000,
n_warmup = 4000,
n_iterations = 20000,
quiet = TRUE
)
```

- data
Tidy data frame with one row per patient, indicator columns for the response variable, study, group, and patient, and covariates. All columns must be atomic vectors (e.g. not lists). The data for the mixture and simple models should have just one study, and the others should have data from more than one study. The simple model can be used to get the historical data components of

`m_omega`

and`s_omega`

for the mixture model.- response
Character of length 1, name of the column in

`data`

with the response/outcome variable.`data[[response]]`

must be a continuous variable, and it*should*be the change from baseline of a clinical endpoint of interest, as opposed to just the raw response. Treatment differences are computed directly from this scale, please supply change from baseline unless you are absolutely certain that treatment differences computed directly from this quantity are clinically meaningful.- study
Character of length 1, name of the column in

`data`

with the study ID.- study_reference
Atomic of length 1, element of the

`study`

column that indicates the current study. (The other studies are historical studies.)- group
Character of length 1, name of the column in

`data`

with the group ID.- group_reference
Atomic of length 1, element of the

`group`

column that indicates the control group. (The other groups may be treatment groups.)- patient
Character of length 1, name of the column in

`data`

with the patient ID.- covariates
Character vector of column names in

`data`

with the columns with baseline covariates. These can be continuous, categorical, or binary. Regardless,`historicalborrow`

derives the appropriate model matrix.- s_delta
Numeric of length 1, prior standard deviation of the study-by-group effect parameters

`delta`

.- s_beta
Numeric of length 1, prior standard deviation of the fixed effects

`beta`

.- s_sigma
Numeric of length 1, prior upper bound of the residual standard deviations.

- m_omega
Numeric with length equal to the number of supposed studies (but only the current study is in the data).

`m_omega`

is the prior control group mean of each study. The last element corresponds to the current study, and the others are for historical studies.- s_omega
Numeric with length equal to the number of supposed studies (but only the current study is in the data).

`s_omega`

is the prior control group standard deviation of each study. The last element corresponds to the current study, and the others are for historical studies.- p_omega
Numeric with length equal to the number of supposed studies (but only the current study is in the data).

`p_omega`

is the prior control group mixture proportion of each study. The last element corresponds to the current study, and the others are for historical studies.- n_chains
Number of MCMC chains to run.

- n_adapt
Number of adaptation iterations to run.

- n_warmup
Number of warmup iterations per chain to run.

- n_iterations
Number of saved MCMC iterations per chain to run.

- quiet
Logical of length 1,

`TRUE`

to suppress R console output.

A tidy data frame of parameter samples from the
posterior distribution. Columns `.chain`

, `.iteration`

,
and `.draw`

have the meanings documented in the
`posterior`

package.

The study-specific components of the mixture prior are all fixed
in advance. Mixture components are normal distributions
with means in `m_omega`

and standard deviations in `s_omega`

.
These vectors are ordered with historical studies first
and the current study last.
These mixture components can be computed using
`hb_mcmc_mixture_hyperparameters()`

on a full set of data
(all the historical studies and the current study together).
Then the `m_omega`

and `s_omega`

columns of the output
can be plugged directly into `hb_mcmc_mixture()`

.
See the examples for a demonstration.

Other mcmc:
`hb_convergence()`

,
`hb_mcmc_hierarchical()`

,
`hb_mcmc_independent()`

,
`hb_mcmc_mixture_hyperparameters()`

,
`hb_mcmc_pool()`

```
data_all_studies <- hb_sim_independent(n_continuous = 2)$data
data_all_studies$study <- paste0("study", data_all_studies$study)
hyperparameters <- hb_mcmc_mixture_hyperparameters(
data = data_all_studies,
response = "response",
study = "study",
study_reference = "study5",
group = "group",
group_reference = 1,
patient = "patient",
n_chains = 1,
n_adapt = 100,
n_warmup = 50,
n_iterations = 50
)
print(hyperparameters)
#> # A tibble: 5 × 4
#> study study_index m_omega s_omega
#> <chr> <int> <dbl> <dbl>
#> 1 study1 1 -0.118 0.165
#> 2 study2 2 0.130 0.166
#> 3 study3 3 -1.38 0.0881
#> 4 study4 4 0.288 0.0717
#> 5 study5 5 0 30
data_current_study <- dplyr::filter(data_all_studies, study == max(study))
hb_mcmc_mixture(
data = data_current_study,
response = "response",
study = "study",
study_reference = "study5",
group = "group",
group_reference = 1,
patient = "patient",
m_omega = hyperparameters$m_omega, # use hyperparams from historical data
s_omega = hyperparameters$s_omega, # use hyperparams from historical data
p_omega = rep(1 / nrow(hyperparameters), nrow(hyperparameters)),
n_chains = 1,
n_adapt = 100,
n_warmup = 50,
n_iterations = 50
)
#> # A tibble: 50 × 19
#> alpha `beta[1]` `beta[2]` `delta[1]` delta…¹ omega…² omega…³ omega…⁴ omega…⁵
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 -0.513 0.611 -1.03 -1.06 -1.38 -0.513 -0.0124 -1.48 0.274
#> 2 -0.378 0.612 -1.01 -1.07 -1.46 -0.378 0.245 -1.41 0.343
#> 3 -0.403 0.586 -1.03 -1.01 -1.44 -0.403 0.354 -1.50 0.215
#> 4 -0.434 0.590 -1.03 -1.14 -1.45 -0.434 0.253 -1.48 0.272
#> 5 -0.464 0.519 -1.02 -1.04 -1.44 -0.464 0.139 -1.37 0.291
#> 6 -0.464 0.612 -1.02 -1.06 -1.47 -0.464 0.165 -1.32 0.302
#> 7 -0.466 0.570 -1.02 -1.05 -1.48 -0.466 0.214 -1.44 0.0661
#> 8 -0.475 0.574 -1.01 -1.12 -1.44 -0.475 -0.0518 -1.34 0.275
#> 9 -0.564 0.625 -1.00 -1.01 -1.44 -0.564 0.191 -1.40 0.211
#> 10 -0.426 0.595 -1.03 -1.07 -1.37 -0.426 0.106 -1.28 0.356
#> # … with 40 more rows, 10 more variables: `omega[5]` <dbl>, `post_p[1]` <dbl>,
#> # `post_p[2]` <dbl>, `post_p[3]` <dbl>, `post_p[4]` <dbl>, `post_p[5]` <dbl>,
#> # sigma <dbl>, .chain <int>, .iteration <int>, .draw <int>, and abbreviated
#> # variable names ¹`delta[2]`, ²`omega[1]`, ³`omega[2]`, ⁴`omega[3]`,
#> # ⁵`omega[4]`
```