Importing samples.csv into R

205 views
Skip to first unread message

Noah

unread,
Nov 30, 2012, 3:41:51 PM11/30/12
to stan-...@googlegroups.com
Hi,

I ran stan from the command line and it generated a nice CSV file of samples.  I'd like to import that into R for plotting, analysis, inference on new data, etc.

1) Just using read.csv() in R fails.  Something in the format of the stan output CSV is non-standar.

2) Is there a built in function in rstan to tell the rstan package that this is the proper object?

Thanks!

Ben Goodrich

unread,
Nov 30, 2012, 3:56:02 PM11/30/12
to stan-...@googlegroups.com
On Friday, November 30, 2012 3:41:51 PM UTC-5, Noah wrote:
I ran stan from the command line and it generated a nice CSV file of samples.  I'd like to import that into R for plotting, analysis, inference on new data, etc.

1) Just using read.csv() in R fails.  Something in the format of the stan output CSV is non-standar.

It has metadata at the top. You need to call read.csv() with comment.char = "#" or with skip set equal to the appropriate number of lines to skip.

2) Is there a built in function in rstan to tell the rstan package that this is the proper object?

There is in RStan v1.0.4 but that is not released yet. You could maybe grab the function from

https://code.google.com/p/stan/source/browse/rstan/rstan/R/stan_csv.R

Ben

Noah

unread,
Dec 2, 2012, 1:06:11 PM12/2/12
to stan-...@googlegroups.com
Thanks,

That works perfectly

Xavier Fernández i Marín

unread,
Dec 3, 2012, 12:48:00 AM12/3/12
to stan-...@googlegroups.com
Noah vas escriure el dia dv, 30 nov 2012:

[...]

> 2) Is there a built in function in rstan to tell the rstan package that
> this is the proper object?

In addition to stan.csv() than Ben already mentioned, the ggmcmc() package
has (also in the development version) a way to import directly csv files
from stan running from the command line. In addition to importing the
samples, ggmcmc can also help in convergence diagnostics.

http://xavier-fim.net/packages/ggmcmc/

For the stan csv import, see the development version (this feature will be
included in ggmcmc_0.3 to be released soon):
https://github.com/xfim/ggmcmc

HTH,

--
- Xavier -
Reply all
Reply to author
Forward
0 new messages