sampWiener: Random sampling from the Wiener diffusion model

View source: R/sampWiener.R

sampWienerR Documentation

Random sampling from the Wiener diffusion model

Description

Draws random samples from the (truncated) first-passage time distribution of the Wiener diffusion model with up to 7 parameters.

Usage

sampWiener(
  N,
  a,
  v,
  w,
  t0 = 0,
  sv = 0,
  sw = 0,
  st0 = 0,
  response = "both",
  bound = Inf,
  method = "ars",
  precision = NULL,
  n.threads = 1,
  ars_list = NULL,
  ARS_STORE = FALSE
)

rWDM(
  N,
  a,
  v,
  w,
  t0 = 0,
  sv = 0,
  sw = 0,
  st0 = 0,
  response = "both",
  bound = Inf,
  method = "ars",
  precision = NULL,
  n.threads = 1,
  ars_list = NULL,
  ARS_STORE = FALSE
)

Arguments

N

Number of samples. Numeric value (integer).

a

Upper barrier. Numeric value.

v

Drift rate. Numeric value.

w

Relative starting point. Numeric value.

t0

Non-decision time. Numeric value.

sv

Inter-trial variability of drift rate. Numeric value. Standard deviation of a normal distribution N(v, sv).

sw

Inter-trial variability of relative starting point. Numeric value. Range of uniform distribution U(w-0.5*sw, w+0.5*sw).

st0

Inter-trial variability of non-decision time. Numeric value. Range of uniform distribution U(t0, t0+st0).

response

Response boundary. Character string, either "upper", "lower", or "both". Alternatively a numeric value, 2=upper, 1=lower, or 0=both. Default is "both".

bound

Boundary for the first-passage time. Numeric value. Default is Inf.

method

Sampling method. Either "ars", "rs", "its", or "p-ars". The method "ars" stands for adaptive rejection sampling, "rs" stands for rejection sampling, "its" stands for inverse transform sampling, and "p-ars" stands for pseudo adaptive rejection sampling. Default is "ars".

precision

Optional numeric value. Precision of the infinite series approximation. Numeric value. Default is NULL, which takes default value 1e-12.

n.threads

Optional numeric or logic value. Number of threads to use. If not provided (FALSE or 1) parallelization is not used. If set to TRUE then all available threads are used.

ars_list

Optional list for method "ars". For response "lower" or "upper" a list with upper hull, lower hull etc. is needed. For response "both" a list with two lists must be provided. The corresponding list is produced when using the "ars" method and the argument ARS_STORE = TRUE. Do not make the list yourself and do not mix the lists for the corresponding boundaries.

ARS_STORE

Optional flag for method "ars". If TRUE saves upper hull, lower hull and some more values, which are updated at each rejection step, as a list. The list can then be used with the "ars" method in the argument ars_list to make the new sampling faster. If the first-passage times were sampled only from one boundary then the list will contain upper hull, etc. and if they were sampled from both boundaries then the list consists of two lists, each containing upper hull, etc. for the respective boundary.

Details

The following methods can be used:

  • "ars": adaptive rejection sampling method. This method builds on Gilks and Wild (1992) as well as Hartmann and Klauer (in press). The former provides a method for an adaptive rejection sampling method which assumes that the density is log-concave. This method is fastest for cases where sv = 0. This is the only method where the integral needs to be calculated. The advantage, though, is that after each rejection the upper and lower hull functions will be adapted (or updated), which leads to fewer and fewer rejections in the proceeding sampling steps.

  • "rs": rejection sampling method by Drugowitsch (2016). This method uses different proposal distributions in different conditions.

  • "its": inverse transform (a.k.a. probability integral transform) sampling method. A random sample u is sampled from a uniform distribution and the corresponding first-passage time, for which CDF(t) = u, is approximated.

  • "p-ars": pseudo-adaptive rejection sampling. A variation of "ars". In this method the hull functions will be adapted until the current sample is drawn, but the information from this adaptation will be discarded for the next sample.

Note: The speed of the methods do not depend on t0 or st0.

ars_store, one of the returned list objects if method "ars" and ARS_STORE = TRUE, consists of twelve vectors and three scalars:

  • hstore_x: vector of alpha values – change of variable alpha = (log(t)-start)/scale, where t is the first-passage time – relevant for the upper and lower hull functions.

  • hstore_h: vector of log-density of change of variable A = (log(T)-start)/scale at the alpha points hstore_x

  • hstore_dh: vector of partial derivative of log-density of A with respect to alpha.

  • upperstore_z: vector of alpha values at which the piece-wise linear upper hull transitions from one linear segment to the next.

  • upperstore_slope: same as hstore_dh. Gives the slope of the piece-wise linear functions for the upper hull.

  • upperstore_absc: same as hstore_h. Gives the evaluation of the function h() at hstore_x, where the piece-wise linear function touches h().

  • upperstore_center: same as hstore_x. Gives the alpha values, where the piece-wise linear function touches h().

  • lowerstore_z: same as hstore_x but with an additional leading element (=-Inf) in the vector.

  • lowerstore_slope: vector of zeros since not needed.

  • lowerstore_absc: vector of zeros since not needed.

  • lowerstore_center:: vector of zeros since not needed.

  • startstore: scalar representing the "start" value for the change of variable A = (log(T)-start)/scale.

  • scalestore: scalar representing the "scale" value for the change of variable A = (log(T)-start)/scale.

  • normstore: scalar. Gives the value of h() at alpha = 0.

  • sstore: vector of values at log(s_k(hstore_x)), where s_k() is the function defined in equation 3 in Gilks and Wild (1992).

Value

A list of the class Diffusion_samp containing

  • q: first-passage time sample(s),

  • response: response(s) "lower" and/or "upper",

  • call: the function call,

  • ars_store: if ARS_STORE = TRUE is used with the method "ars" then either a list with upper hull, etc. is stored (either from the upper or lower boundary) or a list of two lists with corresponding upper hull, etc. is stored (from both boundaries) and can be used as function argument to (ars_list) for further sampling with the same parameters.

Author(s)

Raphael Hartmann

References

Drugowitsch, J. (2016). Fast and accurate Monte Carlo sampling of first-passage times from Wiener diffusion models. Scientific Reports, 6(1). \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1038/srep20490")}

Gilks, W. R., & Wild, P. (1992). Adaptive Rejection Sampling for Gibbs Sampling. Applied Statistics, 41(2), 337. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.2307/2347565")}

Hartmann, R., & Klauer, K. C. (2021). Partial derivatives for the first-passage time distribution in Wiener diffusion models. Journal of Mathematical Psychology, 103, 102550. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.jmp.2021.102550")}

Examples


sample_list1 <- sampWiener(N = 100000, a = 1, v = .3, w = .5)
hist(sample_list1$q, 200)

sample_list2 <- sampWiener(N = 100000, a = 1, v = .3, w = .5, ARS_STORE = TRUE)
hist(sample_list2$q, 200)
sample_list2$ars_store

sample_list3 <- sampWiener(N = 100000, a = 1, v = .3, w = .5, ars_list = sample_list2$ars_store)
hist(sample_list3$q, 200)


sample_list1 <- rWDM(N = 100000, a = 1, v = .3, w = .5)
hist(sample_list1$q, 200)

sample_list2 <- rWDM(N = 100000, a = 1, v = .3, w = .5, ARS_STORE = TRUE)
hist(sample_list2$q, 200)
sample_list2$ars_store

sample_list3 <- rWDM(N = 100000, a = 1, v = .3, w = .5, ars_list = sample_list2$ars_store)
hist(sample_list3$q, 200)

WienR documentation built on July 9, 2023, 5:16 p.m.

Related to sampWiener in WienR...