make_jagscode: Make JAGS Model Code

Description Usage Arguments Value Examples

View source: R/make_jagscode.R

Description

Make JAGS Model Code

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
make_jagscode(
  yi,
  vi,
  sei,
  es_id,
  study_id,
  mods = ~1,
  mods_scale2 = ~1,
  mods_scale3 = ~1,
  prior = NULL,
  iter = 5000,
  warmup = 1000,
  chains = 4,
  log_linear = TRUE,
  data
)

Arguments

yi

vector with the observed effect sizes (length k).

vi

vector with the sampling variances (length k). Provide either vi or sei.

sei

vector with the sampling variances (length k). Provide either vi or sei.

es_id

numeric vector with the effect size ids (i.e., 1:k). When provided, a two-level random-effects model is estimated. Whereas, when not specified, a fixed-effects model is estimated by default.

study_id

numeric vector with the study ids (length k). When provided, a three-level random-effects model is estimated (es_id is required). Note that the yi's are assumed to be nested within study_id.

mods

an object of class formula, including moderator(s) for the effect size. By default, an intercept only model is fitted (i.e., mods = ~ 1), resulting in the overall effect.

mods_scale2

an object of class formula, including moderator(s) for level two variance component (or "scale"). By default, an intercept only model is fitted (i.e., mods = ~ 1), resulting in the customary estimate (assumed constant across studies).

mods_scale3

an object of class formula, including moderator(s) for level three variance component (or "scale"). By default, an intercept only model is fitted (i.e., mods = ~ 1), resulting in the customary estimate (assumed constant across studies). See Details.

prior

one or more blsmetaprior objects created by assign_prior.

iter

numeric. The number of posterior samples per chain (defaults to 5000, excluding warmup).

warmup

numeric. The number of warmup samples, which are discarded (defaults to 1000).

chains

numeric. The number of chains (defaults to 4)

log_linear

logical. Should the variance components be modeled on the log-scale (defaults to TRUE)? This is applicable to the scale models with no moderators. See Details.

data

data frame containing the variables in the model.

Value

A character string with the model code.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
library(psymetadata)

prior <- 
  c(assign_prior(param = "(Intercept)", 
                 prior = "dnorm(0, 1)", dpar = "location"),
                 assign_prior(param = "(Intercept)", 
                 prior = "dnorm(0, 10)", 
                 dpar = "scale", level = "two")
                 )

make_jagscode(yi = yi, 
           vi = vi, 
           prior = prior,
           es_id = es_id,
           study_id = study_id,
           data = gnambs2020)

donaldRwilliams/blsmeta documentation built on Dec. 20, 2021, 12:12 a.m.