make_stan_data: Creates the list of data structures required by the stan...

Description Usage Arguments Details Value Examples

View source: R/make_stan_data.R

Description

make_stan_data creates the list of data structures required by the stan function when fitting the model generated by make_stan_model.

Usage

1
2
3
4
5
6
7
8
9
make_stan_data(
  adata,
  fixed,
  random = list(),
  criteria_scale = 2,
  gamma_link = "softmax",
  model = "sdt",
  delta_link = "log"
)

Arguments

adata

an aggregated data object created by aggregate_responses function.

fixed

a list specifying gamma and delta fixed effects and priors. See also 'Details'.

random

an optional list specifying gamma and delta random effects and priors. The default is list(), which corresponds to a non-hierarchical SDT model. See also 'Details'.

criteria_scale

a scaling factor corresponding to mapping distribution's standard deviation, applies only to the softmax gamma link function. The default is 2. See also 'Details'.

gamma_link

either 'softmax' (described in the paper), 'log_distance' or 'log_ratio' (See the Readme file in the github repository)

model

can be either 'sdt' (the default), 'uvsdt', 'metad', 'ordinal', or 'uvordinal'

Details

fixed must be a list of model formulae. It may also contain prior parameter values, if non-default priors on fixed effects are required. This list is composed of the following elements:

delta

is a model formula that defines the delta fixed effects model matrix, e.g., delta = ~ condition

gamma

is a model formula that defines the gamma fixed effects model matrix.

delta_mu

is na optional vector specifying means of independent normal priors on delta fixed effects. This must be of the same length as the number of delta fixed effects or of length 1, in which case the same value will be used for every delta fixed effect. The default value is acc_to_delta(.75)

delta_sd

is na optional vector specifying standard deviations of independent normal priors on delta fixed effects. This must be of the same length as the number of delta fixed effects or of length 1, in which case the same value will be used for every delta fixed effect. The default value is .5 * (acc_to_delta(.99) - acc_to_delta(.51))

gamma_mu

is na optional vector specifying means of independent normal priors on gamma fixed effects. The default value is 0. This must be of the same length as the number of gamma fixed effects or of length 1, in which case the same value will be used for every gamma fixed effect. Note that when there is more than one criterion the number of gamma fixed effects is equal to the number I of columns of gamma fixed effects model matrix times the number of criteria K-1. Internally, the gamma_mu vector is stored as a K-1xI matrix in column major order: element (K-1)*j+i of the gamma_mu vector (where 0 < j and 0 < i < K-1) represents fixed effect corresponding to the i-th column of the gamma fixed effects model matrix and the j-th criterion. In other words, the indices for the fixed effects change faster than the indices for the criteria.

gamma_sd

is na optional vector specifying standard deviations of independent normal priors on gamma fixed effects. This must be of the same length as the number of gamma fixed effects or of length 1, in which case the same value will be used for every gamma fixed effect. See gamma_mu above for details on how the elements of the gamma_sd vector correspond to elements of the gamma fixed effects parameter matrix. The default value depends on the chosen gamma link function. For the 'softmax' function it is log(100), which means that a priori areas under the gamma-to-criterion mapping distribution curve delineated by the criteria are expected to vary by a factor of 100 or less but varying by a factor of exp(2*log(100)) = 10000 is highly unlikely. For the 'log_distance' and the 'log_ratio' gamma link functions the default value is 2.

random is on optional list of lists of model formulae and optional prior parameter values, if non-default priors on random effects are required. Each list specifies delta and gamma random effects of one grouping factor. Note that the same grouping factor (e.g., subject id) can be reused in different random effects specification lists to force the corresponding random effects to be uncorrelated, which will lower the number of free parameters but may result in interval estimate bias if the correlations exist and are non- negligible:

group

is a model formula specifying the random grouping factor, e.g., group = ~ subject indicates that the random effects specified in this list are associated with the subject grouping factor.

delta

is a model formula that defines the delta random effects model matrix. This must define a submodel of the delta fixed effects model, e.g., if delta depends on f1 but not on f2 in the model and f1 is a within-subject variable then delta = ~ f1 or delta = ~ -1 + f1 is a valid delta random effects specification but e.g., delta = ~ f2 is not.

gamma

is a model formula that defines the gamma random effects model matrix. This must define a submodel of the gamma fixed effects model (see delta above for some examples.)

delta_nu

is an optional vector of lkj prior parameters for delta random effects. This must be of the same length as the number of delta random effects or of length 1, in which case the same value will be used for every delta random effect. The default is 1 which corresponds to uniform prior on random effects' correlation matrices. The greater the value of this parameter the more emphasis is put on zer off-diagonal correlations, which represents the a priori assumption that the correlations are low or near zero.

delta_sd_scale

is an optional vector of half-Cauchy prior parameters for delta random effects. This must be of the same length as the number of delta random effects or of length 1, in which case the same value will be used for every delta random effect. The default value is .5 * (acc_to_delta(.99) - acc_to_delta(.51))

gamma_nu

is an optional vector of lkj prior parameters for gamma random effects. This must be of the same length as the number of gamma random effects or of length 1, in which case the same value will be used for every gamma random effect. The default is 1 which corresponds to uniform prior on random effects' correlation matrices. The greater the value of this parameter the more emphasis is put on zer off-diagonal correlations. See gamma_mu above for details on how the elements of the gamma vector correspond to the elements of the gamma parameter matrix.

gamma_sd_scale

is an optional vector of half-Cauchy prior parameters for gamma random effects. This must be of the same length as the number of gamma random effects or of length 1, in which case the same value will be used for every gamma random effect. The default value is log(100). See gamma_mu above for details on how the elements of the gamma vector correspond to elements of the gamma parameter matrix.

Value

a list with response and stimulus data, model matrices, prior parameter values, and other data required by the stan model generated using make_stan_model.

Examples

1
2
3
4
5
6
7
data(gabor)
gabor$r = combined_response(gabor$stim, gabor$rating, gabor$acc)
adata = aggregate_responses(gabor, 'stim', 'r', c('duration', 'id', 'order'))
fixed = list(delta = ~ -1 + duration:order, gamma = ~ order)
random = list(list(group = ~ id, delta = ~ -1 + duration, gamma = ~ 1))
sdata = make_stan_data(adata, fixed, random)
sdata

boryspaulewicz/bhsdtr documentation built on March 8, 2020, 8:24 a.m.