sampWiener | R Documentation |
Draws random samples from the (truncated) first-passage time distribution of the Wiener diffusion model with up to 7 parameters.
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 )
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 |
sw |
Inter-trial variability of relative starting point. Numeric value. Range of uniform distribution |
st0 |
Inter-trial variability of non-decision time. Numeric value. Range of uniform distribution |
response |
Response boundary. Character string, either |
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 |
n.threads |
Optional numeric or logic value. Number of threads to use. If not provided ( |
ars_list |
Optional list for method "ars". For |
ARS_STORE |
Optional flag for method "ars". If |
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).
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.
Raphael Hartmann
Drugowitsch, J. (2016). Fast and accurate Monte Carlo sampling of first-passage times from Wiener diffusion models. Scientific Reports, 6(1). doi: 10.1038/srep20490
Gilks, W. R., & Wild, P. (1992). Adaptive Rejection Sampling for Gibbs Sampling. Applied Statistics, 41(2), 337. 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. doi: 10.1016/j.jmp.2021.102550
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.