stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.03k stars 264 forks source link

Function to read command-line .csv files into simpler object than stan-fit #18

Closed bob-carpenter closed 7 years ago

bob-carpenter commented 10 years ago

It would be nice to be able to read command-line output into RStan for plotting and analysis. This would need to read multiple .csv files as produced by Stan command line.

This should also make it easy to read in data produced by JAGS or other programs so that we can use our own split-R-hat and n_eff calculations.

Basically, what I'm saying is that it'd be nice to be able to use a part of RStan like Coda. In fact, it might make sense breaking it out into a separate package and then have RStan depend on the Coda-like package.

This will probably require re-organizing the way that stan-fit is put together (I don't know the internals), so that an object just holding the samples can be isolated. Then functions like traceplots should be based on the contained object, since they shouldn't need access to the model. (One issue is where the names come from --- that may be from the model at this point, in which case they'll have to be finagled into the separate fit object.)

englepj commented 10 years ago

I'll second this (older) thread and commenting because it comes up in the top four in a search...

I have had issues with different machines since RCpp does not effectively load onto a machine I use workaday that has a space in its directory structure (which it does by default?). At any rate, standard IT installs create a situation whereby I cannot load rstan on a regularly usable machine.

Not STAN's fault that this is the case, of course, but it means that I can't export output to use on a regular machine easily.

Par Jason Engle

This seems to work in a pinch though:

stripstan <- function( object , pars=NULL , permuted=TRUE , ... ) {
  result <- list()
  if ( is.null(pars) )
    pseq <- 1:length(object@par_dims)
  else
    pseq <- pars
  for ( i in pseq ) {
    name <- names(object@par_dims)[i]
    result[[ name ]] <- extract( object , name , permuted=permuted , ... )[[1]]
  }
  result
}

x<-stripstan(fit)
bob-carpenter commented 10 years ago

I'm confused. If you can't load RStan, how do you get a stanfit object to strip?

There's currently a read_stan_csv function that does what my original request was for --- read CSV output from CmdStan into an RStan fit object (with null model object).

I think it would be a better package org if we had an object that didn't have a model slot, from which we could do all the posterior analysis. Then a Stan fit object could hold a reference to that object.

Also, I thought Rcpp had cleaned up the issue with spaces? Have you tried a recent version? R, being the perplexing piece of software that it is, says both that the default is to install in Program Files and then recommends not installing in a directory with spaces!

By the way, using three back quotes is the Git "markdown" way to typeset code --- makes it much easier to read in the GitHub interface. I'll clean up that last post.

englepj commented 10 years ago

I can run rstan, but have intermittent access to the server where I can run it. Most of my day is spent on another machine with pre-installed "R" (in "Program Files" with a space - which is the only reason I can think of why RCpp won't install...), so I workaround.

bob-carpenter commented 10 years ago

Have you tried installing Rcpp more recently? I believe they finally fixed the problem with spaces on Windows installs in 10.3. See:

http://cran.r-project.org/web/packages/Rcpp/news.html

On 2/17/14, 8:51 PM, englepj wrote:

I can run rstan, but have intermittent access to the server where I can run it. Most of my day is spent on another machine with pre-installed "R" (in "Program Files" with a space - which is the only reason I can think of why RCpp won't install...), so I workaround.

— Reply to this email directly or view it on GitHub https://github.com/stan-dev/rstan/issues/18#issuecomment-35317002.

jgabry commented 7 years ago

Closing this old issue since we now do have a way of reading cmd line csv files into R for plotting, etc.