4

I have a Stan model (called fit) and I'm getting some strange results. I know that I'm probably missing something, but I can't see where and what. In this case I want to look at the parameter sigma_h.

If I use as.matrix to get the samples from fit I get the following result:

posterior <- as.matrix(fit) 
trace_sigma_h <- posterior[,colnames(posterior) %in% "sigma_h"]
ts.plot(trace_sigma_h)

enter image description here

This is the same plot I get when using the rstan::traceplotfunction.

If I extract the samples from the fitobject and plots it I get

samples <- extract(fit,inc_warmup = FALSE)
ts.plot(samples$sigma_h) 

enter image description here

These plots are not the same. What am I missing? Is there a difference between just making the fitobject a matrix and extracting the samples?

Axeman
  • 32,068
  • 8
  • 81
  • 94
J.C.Wahl
  • 1,394
  • 8
  • 15
  • 1
    It seems that `extract` uses `permuted = TRUE`, and so I guess it coulb be shuffling the order? Does it look like like the first with `permuted = FALSE`? – Axeman Oct 27 '17 at 08:45
  • 3
    @Axeman and @J.C.Wahl: Yes entries from `extract` are shuffled by default (with a fixed seed). If you sort entries from both methods you can confirm that they are identical. – Maurits Evers Oct 27 '17 at 09:25
  • @Axeman and Maurits: Thanks for the response. You are both correct. Thank you very much. Is there a reason for shuffling the order? – J.C.Wahl Oct 27 '17 at 13:47
  • 1
    Reason might be a strong word, but it was intended to prevent people from doing something like just analyzing some function of the first 100 draws. – Ben Goodrich Oct 28 '17 at 03:51

0 Answers0