knitr::opts_chunk$set(
  cache = TRUE,
  eval = FALSE,
  echo = TRUE)
# packages
library(tidyverse)
library(metasim)
library(kableExtra)
library(dplyr)
library(latex2exp)

# set winners
conflicted::conflict_prefer("filter", "dplyr")
conflicted::conflict_prefer("group_rows", "kableExtra")

simulate

ss <- metasims(single_study = TRUE, trial_fn = singletrial)

ma <- metasims()
ss %>% plot()
ss %>% caption()
ss %>% plot(caption = "test")
ss %>% plot(caption = caption(.))
ss %>% plot(caption = TeX(caption(.)))

single-study simulation figure

ss %>% plot()

before

trials <- 10
unequal_effect_ratio <- 1.2
k <- c(3, 7)
tau_sq_true <- seq(0, 0.4, by = 0.2)
sim_parameter <- function(sim, arg){

  sim %>% 
    purrr::pluck("arguments") %>% 
    dplyr::filter(argument == arg) %>% 
    purrr::pluck("value")
}
# parameters 
(unequal_effect_ratio <- sim %>% sim_parameter("unequal_effect_ratio") %>% 
   as.numeric())

trials <- sim %>% sim_parameter("trials") %>% as.numeric()

Caption drafts

only for meta-analysis

(k <- sim %>% sim_parameter("k") %>% parse(text = .) %>% eval())

(tau_sq_true <- sim %>% sim_parameter("tau_sq_true") %>% parse(text = .) %>% eval())

distributions caption

b) Data for the control and intervention arms were sampled from distributions: the normal distribution, with parameters 2 and 0.3, the exponential distribution, with parameters 2, the Pareto distribution, with parameters 3 and 3, the Pareto distribution, with parameters 2 and 1, the Pareto distribution, with parameters 0.5 and 1, the log-normal distribution, with parameters 1 and 0.3.

plot caption

a) These simulation results are summarised by the proportion, coverage, of r trials confidence intervals that contain the true measure $\nu$, or log-ratio $\log(\rho)$ of control $\nu_C$ and intervention $\nu_I$ measures, with $\rho := \nu_I/\nu_C$.

Caption for the simulation

The case where the control median $\nu_C$ is equal to the intervention median $\nu_I$ is considered, $\rho= 1$, as is an unequal ratio, $\rho =$ r unequal_effect_ratio.

Data for the control and intervention arms sampled from distributions in accompanying Distributions plot.

Summary statistics were calculated from the samples, for the estimator of the variance $\mathcal V(m)$ of the sample median.

meta-analysis only

For each of the r trials trials, $K$ studies' control and intervention arms were simulated. A meta-analysis was performed via metafor::rma with the Knapp-Hartung test for... todo:. The confidence interval that informs the coverage was extracted from the model results.

Simulations, r trials trials, were performed for each of $K =$ r k studies.

The cases where there where there is no variation between the studies, $\tau^2 = 0$, and some variation introduced by independent factors other than the measure of interest for a given study, $\tau^2 =$ r tau_sq_true[-1] are provided.

# todo tau2

single-study simulation

For each of the r trials trials, a confidence interval, $\theta \pm \Phi^{-1}(0.975)\mathcal \sqrt(V(\theta))$, was calculated, where $\theta$ estimates the true measure, or log-ratio of control and intervention measures.

experiments

results as is

sim %>% plot()

sim %>% caption()

sim %>% plot(caption = caption(sim))


softloud/metasim documentation built on July 15, 2019, 8:02 p.m.