Exporting samples.csv in RStan

367 views
Skip to first unread message

Peter Li

unread,
Oct 4, 2013, 10:58:01 AM10/4/13
to stan...@googlegroups.com, Peter Li
Is there a way to export the samples.csv from RStan? Also, is there a place where all the functions in R are listed?


Thanks,
Peter

Ben Goodrich

unread,
Oct 4, 2013, 2:24:02 PM10/4/13
to stan...@googlegroups.com, Peter Li
Not sure what you mean by export. The doc for the sample_file in the stan() function says

A character string of file name for specifying where to write samples for all parameters and other saved quantities. If not provided, files are not created. When the folder specified is not writable, tempdir() is used. When there are multiple chains, an underscore and chain number are appended to the file name
There are thousands of functions in R even before you get into the optional R packages. If you just mean all the functions in rstan, you can do

> ls("package:rstan")
 
[1] "constrain_pars"      "extract"             "get_adaptation_info" "get_cppcode"        
 
[5] "get_cppo"            "get_cppo_mode"       "get_cxxflags"        "get_inits"          
 
[9] "get_logposterior"    "get_num_upars"       "get_posterior_mean"  "get_sampler_params"
[13] "get_seed"            "get_seeds"           "get_stancode"        "get_stanmodel"      
[17] "grad_log_prob"       "log_prob"            "makeconf_path"       "monitor"            
[21] "optimizing"          "plot"                "read_rdump"          "read_stan_csv"      
[25] "rstan_options"       "sampling"            "set_cppo"            "sflist2stanfit"    
[29] "show"                "stan"                "stanc"               "stan_demo"          
[33] "stan_model"          "stan_rdump"          "stan_version"        "summary"            
[37] "traceplot"           "unconstrain_pars"  

Ben

Peter Li

unread,
Oct 5, 2013, 8:40:37 PM10/5/13
to Ben Goodrich, stan...@googlegroups.com
Ah, got it. Thanks. Also, do you know how I can specify inits in RStan? I tried setting inits equal to a list of all of the initial values that I wanted to use:

  radon_group_chr.sf1 <- sampling(radon_group_chr.sm, dataList.3, chains=1,init=dataList.4,sample_file=paste('radon_group_cp_',count,'.csv',sep=''))

 but I get the error:

Error in config_argss(chains = chains, iter = iter, warmup = warmup, thin = thin,  : 
  initial value list mismatchs number of chains
error specification of arguments; sampling not done

Bob Carpenter

unread,
Oct 6, 2013, 2:06:39 AM10/6/13
to stan...@googlegroups.com
You need to pass in the inits as a function. So pass in
init_fun, where you define:

init_fun = function() {
return(list(alpha=alpha_init,
beta=beta_init));
}

- Bob

On 10/5/13 8:40 PM, Peter Li wrote:
> Ah, got it. Thanks. Also, do you know how I can specify inits in RStan? I tried setting inits equal to a list of all of
> the initial values that I wanted to use:
>
> radon_group_chr.sf1 <- sampling(radon_group_chr.sm <http://radon_group_chr.sm>, dataList.3,
> --
> You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Jiqiang Guo

unread,
Oct 6, 2013, 8:20:36 AM10/6/13
to stan...@googlegroups.com

On Sat, Oct 5, 2013 at 8:40 PM, Peter Li <li.pe...@gmail.com> wrote:
Also, do you know how I can specify inits in RStan? I tried setting inits equal to a list of all of the initial values that I wanted to use:

  radon_group_chr.sf1 <- sampling(radon_group_chr.sm, dataList.3, chains=1,init=dataList.4,sample_file=paste('radon_group_cp_',count,'.csv',sep=''))

 but I get the error:

Error in config_argss(chains = chains, iter = iter, warmup = warmup, thin = thin,  : 
  initial value list mismatchs number of chains
error specification of arguments; sampling not done

It needs to be a list, each element of which needs to be a list of all the initial values.  Suppose you have parameter alpha in your model, then the inits argument can be fed say for 4 chains as follows:

inits = list(c1=list(alpha=1), c2=list(alpha=2), c3=list(alpha=3), c4=list(alpha=4)).

So I think in your example, you should do init = list(dataList.4).

--
Jiqiang 

Peter Li

unread,
Oct 6, 2013, 10:30:03 AM10/6/13
to stan...@googlegroups.com, stan...@googlegroups.com
Ah alright. Thanks a lot Bob and Jiqiang. 
--
Reply all
Reply to author
Forward
0 new messages