Created
June 15, 2017 04:58
-
-
Save jake-westfall/930f319a2f6152d8b4d8b9a3129013b6 to your computer and use it in GitHub Desktop.
Simple illustration of getting maximum likelihood estimates of Wiener diffusion model (and profile likelihood confidence intervals) in R using RWiener and bbmle packages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("RWiener") | |
library("bbmle") | |
# alpha = boundary separation parameter. | |
# tau = non-decision time parameter. | |
# beta = bias parameter. | |
# delta = drift rate parameter | |
dat <- rwiener(200, alpha=2, tau=.3, beta=.5, delta=1) | |
str(dat) | |
wiener_plot(dat) | |
# wiener_plot adjusts margin options... set them back to default | |
par(mar=c(5,4,4,2)+.1) | |
# fit model | |
mll <- function(alpha, tau, beta, delta){ | |
-wiener_likelihood(x=c(alpha, tau, beta, delta), dat=dat) | |
} | |
system.time({ | |
mod <- mle2(mll, start=list(alpha=2, tau=.3, beta=.5, delta=1)) | |
}) # 4.3 seconds | |
# inspect model | |
summary(mod) | |
system.time({ | |
prof <- profile(mod) | |
}) # 91 seconds | |
confint(prof) | |
plot(prof) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment