Package 'CircularDDM'

Title: Circular Drift-Diffusion Model
Description: Circular drift-diffusion model for continuous reports.
Authors: Yi-Shin Lin [aut, cre], Andrew Heathcote [aut], Peter Kvam [aut]
Maintainer: Yi-Shin Lin <[email protected]>
License: GPL-2
Version: 0.1.0
Built: 2025-02-23 04:01:10 UTC
Source: https://github.com/cran/CircularDDM

Help Index


Find First k Positive Zeros for the Bessel Functions

Description

Find first k positive zeros of the Bessel function J(n,x) or Y(n,x) using Halley's method.

Usage

besselzero(nu, k, kind)

Arguments

nu

The order of the corresponding Bessel function.

k

an integer for first k positive zeros.

kind

0, 1, or 2. A switch selects besselI, besselJ or besselY

Value

a vector

References

besselzero.m

Examples

nu <- seq(0, 5, length.out=10)
output <- matrix(numeric(5*length(nu)), nrow=5)
  for(i in 1:length(nu)) {
    output[,i] <- besselzero(nu[i], 5, 1)
  }
output

output <- matrix(numeric(5*length(nu)), nrow=5)
for(i in 1:length(nu)) {
    output[,i] <- besselzero(nu[i], 5, 2)
}
output

Circular Drift-diffusion Model

Description

Circular drift-diffusion model for continuous report.

Author(s)

Yi-Shin Lin <[email protected]>
Andrew Heathcote <[email protected]>
Peter Kvam <[email protected]>

References

Smith, P. L. (2016). Diffusion Theory of Decision Making in Continuous Report, Psychological Review, 123(4), 425–451.


The Circular Drift-diffusion Distribution

Description

Density function and random generation for the circular drift-diffusion model with theta vector equal to pVec. dcddm is the equation (23) on page 433 in Smith (2016).

Usage

dcddm(x, pVec, k = 141L)

rcddm(n, pVec, p = 0.15)

Arguments

x

a matrix storing a first column as RT and a second column of continuous responses/reports/outcomes. Each row is a trial.

pVec

a parameter vector with the order [a, vx, vy, t0, s], or [thresh, mu1, mu2, ndt, sigmasq]. The order matters.

k

a precision for calculating the infinite series in dcddm. The larger the k is, the larger the memory space is required. Default is 141.

n

number of observations.

p

a precision for random walk step in rcddm. Default is 0.15 second

Value

dcddm gives a log-likelihood vector. rddm generates random deviates, returning a n x 3 matrix with the columns: RTs, choices and then angles.

References

Smith, P. L. (2016). Diffusion Theory of Decision Making in Continuous Report, Psychological Review, 123 (4), 425–451.

Examples

## dcddm example
x <- cbind(
RT= c(1.2595272, 0.8693937, 0.8009044, 1.0018933, 2.3640007, 1.0521304),
R = c(1.9217430, 1.7844653, 0.2662521, 2.1569724, 1.7277440, 0.8607271)
)
pVec <- c(a=2.45, vx=1.5, vy=1.25, t0=.1, s=1)
dcddm(x, pVec)

## rcddm example
pVec <- c(a=2, vx=1.5, vy=1.25, t0=.25, s=1)
den  <- rcddm(1e3, pVec);
hist(den[,1], breaks = "fd", xlab="Response Time",  main="Density")
hist(den[,3], breaks = "fd", xlab="Response Angle", main="Density")

Log-Likelihood for Circular First Passage Time

Description

Calculate circular log-likelihood of the first passage time, using equation (22) on p 432.

Usage

logLik_dt(x, pVec, k = 141L)

Arguments

x

a matrix storing a first column as RT and a second column of continuous responses/reports/outcomes. Each row is a trial.

pVec

a parameter vector with the order [a, vx, vy, t0, s], a stands for response threshold, vx is the drift rate along x axis, vy is the drift rate along y axis, t0 is the non-decision time, and s is the within-trial standard deviation.

k

a precision for bessel function. The larger the k is, the larger the memory space is required. Default is 141.

Value

a vector

References

Smith, P. L. (2016). Diffusion Theory of Decision Making in Continuous Report, Psychological Review, 123 (4), 425–451.

Examples

x <- cbind(
RT=c(1.2595272, 0.8693937, 0.8009044, 1.0018933, 2.3640007, 1.0521304),
R =c(1.9217430, 1.7844653, 0.2662521, 2.1569724, 1.7277440, 0.8607271)
)
pVec <- c(a=2.45, vx=1.5, vy=1.25, t0=.1, s=1)
den  <- logLik_dt(x, pVec=pVec);
den

Log-Likelihood for Continuous Reports

Description

Calculate log-likelihood of the continuous reports, using part part in equation (23) on p 433.

Usage

logLik_resp(x, pVec)

Arguments

x

a matrix storing a first column as RT and a second column of continuous responses/reports/outcomes. Each row is a trial.

pVec

a parameter vector with the order [a, vx, vy, t0, s], or [thresh, mu1, mu2, ndt, sigmasq], using alternative names.

Value

a vector

References

Smith, P. L. (2016). Diffusion Theory of Decision Making in Continuous Report, Psychological Review, 123 (4), 425–451.

Examples

x <- cbind(
RT=c(1.2595272, 0.8693937, 0.8009044, 1.0018933, 2.3640007, 1.0521304),
R =c(1.9217430, 1.7844653, 0.2662521, 2.1569724, 1.7277440, 0.8607271)
)
pVec <- c(a=2.45, vx=1.5, vy=1.25, t0=.1, s=1)
den  <- logLik_resp(x, pVec=pVec); den

Generate random deviates for the von Mises distribution

Description

Generate random deviates for the von Mises distribution.

Usage

rvm(n, mu, k)

Arguments

n

number of observations.

mu

mean direction of the distribution.

k

non-negative numeric value for the concentration parameter of the distribution

Details

A random variable for circular normal distribution has the form:

f(theta;mu,kappa)=1/(2piI0(kappa))exp(kappacos(thetamu))f(theta; mu, kappa) = 1 / (2 * pi * I0(kappa)) * exp(kappa * cos(theta-mu))

theta is withins 0 and 2 * pi.

I0(kappa) in the normalizing constant is the modified Bessel function of the first kind and order zero.

Value

a vector

Examples

n  <- 100
mu <- 0
k  <- 10
vm3_de <- rvm(n, mu, k)       ## in degree unit
vm3_pi <- vm3_de %% (2 * pi)  ## in radian unit