init | R Documentation |
Initialise the random effects for each subject using MCMC.
init(
pmwgs,
start_mu = NULL,
start_sig = NULL,
display_progress = TRUE,
particles = 100
)
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 |
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.
If the start_mu and start_sig arguments are left at the default (NULL) then start_mu will be sampled from a normal distribution with mean as the prior mean for eac variable and sd as the square of the variance from the prior covariance matrix. start_sig by default is sampled from an inverse wishart (IW) distribution. For a model with the number of parameters N the degrees of freedom of the IW distribution is set to N*3 and the scale matrix is the identity matrix of size NxN.
The sampler object but with initial values set for theta_mu
,
theta_sig
, alpha
and other values for the first sample.
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, particles=10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.