init: Initialise values for the random effects

Description Usage Arguments Details Value Examples

View source: R/init.R

Description

Initialise the random effects for each subject using MCMC.

Usage

1
2
3
4
5
6
7
init(
  pmwgs,
  start_mu = NULL,
  start_sig = NULL,
  display_progress = TRUE,
  particles = 1000
)

Arguments

pmwgs

The sampler object that provides the parameters.

start_mu

An array of starting values for the group means

start_sig

An array of starting values for the group covariance matrix

display_progress

Display a progress bar during sampling

particles

The number of particles to generate in initialisation

Details

Before sampling can start the Particle Metropolis within Gibbs sampler needs initial values for the random effects. The init function generates these values using a Monte Carlo algorithm. One alternative methods would be setting the initial values randomly.

Optionally takes starting values for the model parameters and the variance / covariance matrix. All arrays must match the appropriate shape.

For example, with 5 parameters and 10 subjects, the model parameter start means must be a vector of length 5 and the covariance matrix must be an array of 5 x 5.

Alternatively the if argument values for the starting points are left at the default (NULL) then starting points will be sampled from the prior for group level values (model parameters and covariance matrix)

Value

The sampler object but with initial values set for theta_mu, theta_sig, alpha and other values for the first sample.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
lba_ll <- function(x, data) {
  x <- exp(x)
  if (any(data$rt < x["t0"])) {
    return(-1e10)
  }
  sum(
    log(
      rtdists::dLBA(
        rt = data$rt,
        response = data$correct,
        A = x["A"],
        b = x["A"] + x[c("b1", "b2", "b3")][data$condition],
        t0 = x["t0"],
        mean_v = x[c("v1", "v2")],
        sd_v = c(1, 1),
        silent = TRUE
      )
    )
  )
}
sampler <- pmwgs(
  forstmann,
  c("b1", "b2", "b3", "A", "v1", "v2", "t0"),
  lba_ll
)
sampler <- init(sampler)

pmwg documentation built on Feb. 17, 2021, 9:07 a.m.