library(metapsyData)
library(metapsyTools)

d <- getData("depression-selfguided-psyctr",
                version = "24.0.2")
dat <- d$data


# Run combined MA for depression outcome data
filterPoolingData(dat, outcome_domain  == "depression") %>%
  runMetaAnalysis(which.run = "combined",
                  rho.within.study = 0.5,
                  which.combine = "arms") %>%
  {.$model.combined$data$N =
    .$model.combined$data$n_arm1 +
    .$model.combined$data$n_arm2;
    .$model.combined$data} -> depression

# Run combined MA for QoL outcome data
filterPoolingData(dat, outcome_domain  == "QoL") %>%
  runMetaAnalysis(which.run = "combined",
                  rho.within.study = 0.5,
                  which.combine = "arms") %>%
  {.$model.combined$data$N =
    .$model.combined$data$n_arm1 +
    .$model.combined$data$n_arm2;
    .$model.combined$data} -> qol


# Combine and save
list(depression = depression,
     qol = qol,
     metadata = d$returnMetadata()) -> SelfGuidedDB

save(SelfGuidedDB,
     file="www/data/SelfGuidedDB.rda")