library(rstan)
library(RWiener)
# generate data using RWiener package
set.seed(0)
dat <- rwiener(n = 1000, alpha = 1, tau = 0.2, beta = 0.5, delta = 0.5)
standata <- list(y = ifelse(dat$resp == "upper", dat$q, -1 * dat$q),
N = length(dat$resp))
wiener_model <- "
data {
int<lower=0> N;
real y[N];
}
parameters {
real<lower=0> a;
real<lower=0> t;
real<lower=0,upper=1> b;
real v;
}
model {
v ~ normal(0, 2);
for (n in 1:N) {
y[n] ~ wiener(1, 0.2, 0.5, v);
}
}"
fit <- stan(model_code = wiener_model, data = standata)
Rejecting initial value:
Error evaluating the log probability at the initial value.
Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Exception thrown at line 16:
stan::math::wiener_log(%1%): Random variable is -0.395369, but must be > 0!
If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
> sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.4 (Yosemite)
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RWiener_1.2-0 rstan_2.7.0-2 Rcpp_0.12.0 magrittr_1.5 devtools_1.8.0
loaded via a namespace (and not attached):
[1] codetools_0.2-14 digest_0.6.8 R6_2.1.0 stats4_3.2.1 git2r_0.10.1 httr_1.0.0
[7] stringi_0.5-5 curl_0.9.1 xml2_0.1.1 tools_3.2.1 stringr_1.0.0.9000 inline_0.3.14
[13] rversions_1.0.2 memoise_0.2.1
set.seed(0)
dat <- rwiener(n = 5000, alpha = 1, tau = 0.2, beta = 0.75, delta = 0.5)
standata <- list(y = dat$q,
resp = ifelse(dat$resp == "upper", 1, 0),
N = length(dat$resp))
data {
int<lower=0> N;
real y[N];
int<lower=0, upper=1> resp[N];
}
parameters {
real<lower=0> a;
real<lower=0> t;
real<lower=0, upper=1> b;
real v;
}
model {
v ~ normal(0, 2);
a ~ gamma(3, 3);
t ~ gamma(4, 10);
b ~ beta(5, 5);
for (n in 1:N) {
if (resp[n] == 1) {
y[n] ~ wiener(a, t, b, v);
}
else {
y[n] ~ wiener(a, t, 1-b, -v);
}
}
}
library(rstan)
library(RWiener)
set.seed(0)
dat <- rwiener(n = 5000, alpha = 1, tau = 0.2, beta = 0.75, delta = 0.5)
## stan model ----
wiener_model <- "
data {
int<lower=0> N;
real y[N];
int<lower=0, upper=1> resp[N];
}
parameters {
real<lower=0> a;
real<lower=0> t;
real<lower=0, upper=1> b;
real v;
}
model {
v ~ normal(0, 2);
a ~ gamma(3, 3);
t ~ gamma(4, 10);
b ~ beta(5, 5);
for (n in 1:N) {
if (resp[n] == 1) {
y[n] ~ wiener(a, t, b, v);
}
else {
y[n] ~ wiener(a, t, 1-b, -v);
}
}
}"
## stan data ----
standata <- list(y = dat$q,
resp = ifelse(dat$resp == "upper", 1, 0),
N = length(dat$resp))
fit <- stan(model_code = wiener_model, data = standata)
I think the problem here was that Andrew looked at the documentation in
wiener_log.hpp file which wrongly describes the possibility of lower
boundary by negating y (random variable) which was originally what the
patch of Joachim Vandekerckhove did.
I changed this (thus forcing y to be strictly positive) because there
was no computational advantage in doing so and thought it would be
potentially dangerous for users. I realize I should have discussed such
change with stan-dev at the time.
The Stan manual, however, correctly describes the current behavior
(although it does deserves a better explanation), and I didn't put it
there that y must positive because it is already in the category
"Non-negative Continuous Distributions".
I changed this (thus forcing y to be strictly positive) because there
was no computational advantage in doing so and thought it would be
potentially dangerous for users.
--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/-6wJfA-t2cQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
In the JAGS code, these bivariate outcomes were captured in a single number
by using the sign. So .313 indicates an rt of 313 ms that ended up at
the upper bound, and -.400 indicates an rt of 400 ms that ended up at
the lower bound.
Well, the model is very popular in RT research, from which field it originated. I would use the coding that most users are comfortable with.
Cheers,
EJ
--
There really is a single canonical solution; at least as far as the diffusion model is concerned. It's a bivariate model so the likelihood should be bivariate. I certainly understand that people are uncomfortable with the negative-RTs hack, and it's not good coding practice. But neither is implementing a bivariate distribution as two conditional univariate distributions.
Since there is a concern with breaking backward compatibility, I second Bob's suggestion of introducing a new distribution, suggest we explicitly label it bivariate and call it the "double Wiener distribution" and I can provide code to implement ~dwiener() if someone can help me translate it to the correct C prototypes and whatnot.
I think that will satisfy everyone involved.
Joachim