Generated quantities block in rstan

How do I get the results from generated quantities block to r?
I only get information about the parameters, using eg. print or as.matrix or extract.
I can then do some calculations with them in R, but should it be be possible to get the results of generated quantities also? My version of rstan is 2.17.3.

Hi Lotte!

extract for example should give you the values of the generated quantities. You might find a few ideas on how people get the values into R from this topic.

If you do not get the generated quantities this way, I guess there is something strange going on.

Max

Hi!
Yes, I haven´t got that working. Like for example, found from the advices, list_of_draws=extract(stanfit) gives only the parameters. Checked it with print(names(list_of_draws)). I myself don´t have matlab, but a friend did got the model generated quantities extracted with it. I am quite beginner, though.

Lotte

It should also provide the generated quantities so this is a misunderstanding or a bug. Can you provide a minimal reproducible example?

I am not sure, can it be published in internet yet, as I still work with it, and I have only done the r-script part and other one has mainly done the stan-code. Should I use e-mail, or then try change something or invent some not real names of parameters or datas. I will think that tomorrow, thank you!
Lotte

No, I’m looking for a minimal example that has nothing to do with your secret project but that reproduces your problem:
http://adv-r.had.co.nz/Reproducibility.html

It should be a short R script you can post in the message here.

Hi,

I finally manged to solve the problem, after thinking it for long. Sorry to bother you!

It was that I had put the pars= argument, when I was fitting the model and because I had told that the parameters were what the parameters were, it did not give anything from the generated quanitities block.

Now it does give everything when I fit the model without pars argument. So I had made a mistake when looking examples from some other scripts.

Good to know what the reproducible example means also,

Lotte

2 Likes

Glad you found it!

As people far and wide will tell you by the time you finish writing one you will usually have found your problem and maybe the solution :)

4 Likes

Ain’t that the truth!!

1 Like

This effect is so well known, it has a name — rubber duck debugging. The Pragmatic Programmer, which according to Wikipedia introduced the term, is a really wonderful intro to general programming methodology.

Programmers are really good at marketing. In the sciences it’s just called troubleshooting.