priorPredictive: Prior Predictive Samples

View source: R/priorPredictive.R

priorPredictiveR Documentation

Prior Predictive Samples

Description

Samples full data sets (i.e., individual response frequencies) or group-level MPT parameters based on prior distribution for group-level parameters.

Usage

priorPredictive(
  prior,
  eqnfile,
  restrictions,
  numItems,
  level = "data",
  N = 1,
  M = 100,
  nCPU = 4
)

Arguments

prior

a named list defining the priors. For the traitMPT, the default is list(mu = "dnorm(0,1)", xi="dunif(0,10)", V=diag(S), df=S+1), where S is the number of free parameters. For the betaMPT, the default is list(alpha ="dgamma(1,.1)", beta = "dgamma(1,.1)"). Note that the normal distribution "dnorm(mu,prec)" is parameterized as in JAGS by the mean and precision (= 1/variance).

eqnfile

The (relative or full) path to the file that specifies the MPT model (standard .eqn syntax). Note that category labels must start with a letter (different to multiTree) and match the column names of data. Alternatively, the EQN-equations can be provided within R as a character value (cf. readEQN). Note that the first line of an .eqn-file is reserved for comments and always ignored.

restrictions

Specifies which parameters should be (a) constant (e.g., "a=b=.5") or (b) constrained to be identical (e.g., "Do=Dn") or (c) treated as fixed effects (i.e., identical for all participants; "a=b=FE"). Either given as the path to a text file with restrictions per row or as a list of restrictions, e.g., list("D1=D2","g=0.5"). Note that numbers in .eqn-equations (e.g., d*(1-g)*.50) are directly interpreted as equality constraints.

numItems

vector with the number of items per MPT tree (either named or assigned to alphabetically ordered tree labels)

level

either "data" (returns individual frequencies) or "parameter" (returns group-level MPT parameters; M and numItems are ignored)

N

number of participants per replication

M

number of prior predictive samples (i.e., data sets with N participants).

nCPU

number of CPUs used for parallel sampling. For large models and many participants, this may require a lot of memory.

Value

a list of M matrices with individual frequencies (rows=participants, columns=MPT categories). A single matrix is returned if M=1 or level="parameter".

Examples

eqnfile <- system.file("MPTmodels/2htm.eqn",
  package = "TreeBUGS"
)
### beta-MPT:
prior <- list(
  alpha = "dgamma(1,.1)",
  beta = "dgamma(1,.1)"
)

### prior-predictive frequencies:
priorPredictive(prior, eqnfile,
  restrictions = list("g=.5", "Do=Dn"),
  numItems = c(50, 50), N = 10, M = 1, nCPU = 1
)

### prior samples of group-level parameters:
priorPredictive(prior, eqnfile,
  level = "parameter",
  restrictions = list("g=.5", "Do=Dn"),
  M = 5, nCPU = 1
)

### latent-trait MPT
priorPredictive(
  prior = list(
    mu = "dnorm(0,1)", xi = "dunif(0,10)",
    df = 3, V = diag(2)
  ),
  eqnfile, restrictions = list("g=.5"),
  numItems = c(50, 50), N = 10, M = 1, nCPU = 1
)


denis-arnold/TreeBUGS documentation built on May 13, 2024, 6:34 p.m.