Please kindly help and feel free to let me know any suggestions that could make the chains move around. Thank you!!
parameters{
real Z_a[A];
}
transformed parameters {
real X_a[A];
X_a[1] <- X_lower + inv_logit(sigma_eps * Z_a[1]) * (X_upper - X_lower);
for (i in 2:A) {
X_a[i] <- X_lower + inv_logit(rho * X_a[i-1] * sigma_eps * Z_a[i]) * (X_upper - X_lower);
}
}
parameters {
Z_a ~ normal(0,1);
logy_a ~ normal(X_a, 0.5);
}
--
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/w6Tcdbar9zk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thank you so much for your suggestion! I just tried it using the updated model (attached). But I still need some help.1. Z_a mix well, but X_a still don't mix. Please see attached trace plot.2. In order to get the chain mix, I have to increase adapt_alpha instead of using the default. This is a very simple model with few parameters just to illustrate my problem. I was wandering if the number of parameter increases significantly, the chains won't mix well even if I set adapt_alpha very close to 1.
--
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.
logy_a <- rnorm(A, mean = 0, sd = 0.05)
logy_a ~ normal(X_a, 0.5);
############ R code starts ############
library(rstan)
A <- 400
rho <- 0.9
sigma_eps <- 0.03
set.seed(1234)
logy_a <- rnorm(A, mean = 0, sd = 0.05)
y_a <- exp(logy_a)
X_lower <- log(0.5)
X_upper <- log(2)
test_data <- list(A = A, logy_a = logy_a,
rho = rho, sigma_eps = sigma_eps,
X_lower = X_lower, X_upper = X_upper)
test_model3 <- "
data {
int<lower=1> A;
real<lower=0, upper=1> rho;
real<lower=0> sigma_eps;
real logy_a[A];
real X_lower;
real X_upper;
}//end of data
parameters{
real Z_a[A];
}
transformed parameters {
real<lower=X_lower, upper=X_upper> X_a[A];
real<lower=0> sigma_eps_stat;
sigma_eps_stat <- sqrt(sigma_eps^2 / (1 - rho^2));
X_a[1] <- X_lower + inv_logit(sigma_eps_stat * Z_a[1]) * (X_upper - X_lower);
for (i in 2:A) {
X_a[i] <- X_lower +
inv_logit(rho * X_a[i-1] + sigma_eps * Z_a[i]) * (X_upper - X_lower);
}
}
model {
Z_a ~ normal(0,1);
logy_a ~ normal(X_a, 0.5);
}
"
fit_test3 <- sampling(stan_model(model_code = test_model3),
data = test_data,
init = 0,
control = list(adapt_delta = 0.999,#default=0.8
max_treedepth = 12),
iter = 1000, chains = 2, warmup = 2)
traceplot(fit_test3, par = c(paste0("X_a[", c(10, 211, 352), "]"),
paste0("Z_a[", c(10, 211, 352), "]")))
############ R code ends ############
I think your parameter array (vector) is Z_a, since its defined as parameter in the parameter section and
X_a is an input.
Sorry, but an AR(1) model normal has constant, and a rho, phi, or whatever you call that correlates to the past X_t-1
and if you want a sigma.
you defined A parameters, since A=400, its 400+ parameters.
Did you have had a look in the manual.
There is an AR(1) model example, that is working well.
Why should the chain move? Isn't it you defined something like a table lookup?
Definitely — Ben have you seen a trade off in performance betweenthis and the standard parameterization when the data becomes moredense? I can fit simple models using the standard parameterizationno problem but I have definitely run into problems with larger models.
On Nov 3, 2015, at 10:52 PM, Andrew Gelman <gel...@stat.columbia.edu> wrote:
Worth putting this in the manual, I think.A
On Nov 3, 2015, at 10:00 AM, Ben Goodrich <goodri...@gmail.com> wrote:
On Tuesday, November 3, 2015 at 9:10:36 AM UTC-5, CFQ wrote:Please kindly help and feel free to let me know any suggestions that could make the chains move around. Thank you!!
You basically have to Matt trick AR(1) processes for unknown parameters in Stan to get reasonable sampling. Like this:parameters{
real Z_a[A];
}
transformed parameters {
real X_a[A];
X_a[1] <-X_lower + inv_logit(sigma_eps * Z_a[1]) * (X_upper - X_lower);
for (i in 2:A) {
X_a[i] <- X_lower + inv_logit(rho * X_a[i-1] * sigma_eps * Z_a[i]) * (X_upper - X_lower);
}
}
parameters {
Z_a ~ normal(0,1);
logy_a ~ normal(X_a, 0.5);
}
Ben--
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+unsubscribe@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
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+unsubscribe@googlegroups.com.