Git Product home page Git Product logo

rstan's Introduction

RStan

CRAN_Status_Badge Downloads Research software impact R-CMD-check

RStan is the R interface to Stan.

Quick links

Getting Started

For installation instructions and other tips on getting started with RStan see

Several Stan users have also contributed translations of the RStan Getting Started page:

Source Repository

RStan's source code repository is hosted here on GitHub. Stan's source repository is defined as a submodule. See how to work with stan submodule in rstan repo.

Licensing

RStan is licensed under GPLv3. The Stan code packaged in RStan is licensed under new BSD.

rstan's People

Contributors

aaronjg avatar andrjohns avatar avehtari avatar betanalpha avatar bgoodri avatar bwiernik avatar davharris avatar ecmerkle avatar heavywatal avatar hsbadr avatar jgabry avatar jpritikin avatar lionel- avatar martinmodrak avatar matthewdhoffman avatar maverickg avatar mbrubake avatar mespe avatar paul-buerkner avatar reuning avatar rok-cesnovar avatar sakrejda avatar sbfnk avatar seantalts avatar ssp3nc3r avatar stevebronder avatar syclik avatar topipa avatar wds15 avatar weberse2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rstan's Issues

cannot install Rstan in windows 8

Hi!
I've been trying to install Rstan, but I always get this message:

install.packages('rstan', type = 'source')
trying URL 'http://wiki.rstan-repo.googlecode.com/git/src/contrib/rstan_2.2.0.tar.gz'
Content type 'application/x-gzip' length 4515994 bytes (4.3 Mb)
opened URL
downloaded 4.3 Mb

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

The downloaded source packages are in
‘C:\Users\Patrícia\AppData\Local\Temp\Rtmp2vgZ8C\downloaded_packages’
Warning messages:
1: running command '"C:/Program Files/R/R-3.0.3/bin/x64/R" CMD INSTALL -l "C:\Program Files\R\R-3.0.3\library" C:\Users\Patrícia\AppData\Local\Temp\Rtmp2vgZ8C/downloaded_packages/rstan_2.2.0.tar.gz' had status 1
2: In install.packages("rstan", type = "source") :
installation of package ‘rstan’ had non-zero exit status

And nothing is installed....
Anyone can help me?
Thanks a lot
Luís

add example of inits with functions and list of named lists

I don't care what the examples are.

Here is a simple example of the list of named lists approach for a model estimating a univariate normal:

  > fit <- stan('simple.stan', 
                init=list(list(mu=-10000,sigma=10), list(mu=20, sigma=0.1)), 
                chains=2);

Here's an example of using a function:

  > init_fun <- function() { list(mu=runif(1,-1000,1000), sigma=runif(1,0,10)) } 
  > fit <- stan('simple.stan', init=init_fun, chains=2)

Eight schools example fails on OS X 10.9

I've just installed Stan 2.0.1 and rstan 2, but am unable to run the eight schools example on the "Getting Started" page. I get the following:

> fit <- stan(model_code = schools_code, data = schools_dat, 
+             iter = 1000, chains = 4)

TRANSLATING MODEL 'schools_code' FROM Stan CODE TO C++ CODE NOW.
Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
  failed to parse Stan model 'schools_code' with error message:
EXPECTATION FAILURE LOCATION: file=input; line=21, column=1


 ^-- here


DIAGNOSTIC(S) FROM PARSER:
Parser expecting: "*/"

Running R 3.0.2 on OS X 10.9.

vectors of length 1 and matrices with only 1 column

I was playing around with doing regressions in Stan and came up with a problem.

Here’s my Stan code:

data {
int N;
int K;
int<lower=0,upper=1> y[N];
matrix[N,K] X;
}
parameters {
vector[K] b;
}
model {
y ~ bernoulli_logit(X*b);
}

And here’s my R code:

y <- rep (c(1,0),c(10,5))
N <- length (y)
K <- 1
X <- array (1, c(N,K))
data <- c("N","K","X","y”)

This all worked fine with K=2, but this is what happened with K=1:

model <- stan(file=model_name, data=data, chains = 0)

TRANSLATING MODEL 'logistic_0' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'logistic_0' NOW.
the number of chains is less than 1; sampling not done

OK, that’s fine. But then I tried to fit the model:

fit <- optimizing(object=get_stanmodel(model), data, hessian = TRUE)
STAN OPTIMIZATION COMMAND (BFGS)
init = random
save_iterations = 1
init_alpha = 0.001
tol_obj = 1e-08
tol_grad = 1e-08
tol_param = 1e-08
seed = 287624105
initial log joint probability = -16.1761
Iter log prob ||dx|| ||grad|| alpha # evals Notes
0 -12.4353 0.661911 4.59045 0.1 4
4 -9.54771 4.27152e-05 1.7734e-07 1 8
Optimization terminated normally: Convergence detected: change in objective function was below tolerance
Error: mismatch in number dimensions declared and found in context; processing stage=initialization; variable name=b; dims declared=(1); dims found=()

Bob and Ben say this bug stems from R's conflation of scalars and 1-dimensional arrays.

R2WinBUGS compatible output

From Sebastian Weber:

I would love to get an objects which has the same entries as defined here:

http://www.inside-r.org/packages/cran/R2WinBUGS/docs/bugs

for the case when codaPkg=FALSE, check the section "Value".

I know that I could use these helper functions extract and as.array, but the library I am currently intending to use stan instead of WinBUGS simply used the structure as returned by R2WinBUGS::bugs described above. There is no extra output, just the same stuff which rstan reports already in a different format. Nothing really complicated.

get_posterior_mean wrong names for parameters of array

Just leave a record.

> library(rstan)
Loading required package: Rcpp


Loading required package: inline

Attaching package: ‘inline’

The following object is masked from ‘package:Rcpp’:

    registerPlugin

Loading required package: stats4
rstan (Version 1.3.0, packaged: 2013-04-12 21:12:02 UTC, GitRev: f57455593d14)
> 
> 
> 
> 
> 
> 
> rstan:::git_head()
[1] "f57455593d1419ac8c73c17690de22d32f6689cd"
> 
> 
>  csv_fname <- 'teststanfit.csv'
>   model_code <- "
+     parameters {
+       real y[2];
+     }
+     transformed parameters {
+       real y2[2, 2];
+       y2[1, 1] <- y[1];
+       y2[1, 2] <- -y[1];
+       y2[2, 1] <- -y[2];
+       y2[2, 2] <- y[2];
+     }
+     model {
+       y ~ normal(0, 1);
+     }
+     generated quantities {
+       real y3[3, 2, 3];
+       y3[1,1,1] <- 1;   y3[1,1,2] <- 2;   y3[1,1,3] <- 3;
+       y3[1,2,1] <- 4;   y3[1,2,2] <- 5;   y3[1,2,3] <- 6;
+       y3[2,1,1] <- 7;   y3[2,1,2] <- 8;   y3[2,1,3] <- 9;
+       y3[2,2,1] <- 10;  y3[2,2,2] <- 11;  y3[2,2,3] <- 12;
+       y3[3,1,1] <- 13;  y3[3,1,2] <- 14;  y3[3,1,3] <- 15;
+       y3[3,2,1] <- 16;  y3[3,2,2] <- 17;  y3[3,2,3] <- 18;
+     }
+   "
>   fit <- stan(model_code = model_code,
+               iter = 100, chains = 1, thin = 3,
+               sample_file = csv_fname)

TRANSLATING MODEL 'model_code' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'model_code' NOW.
SAMPLING FOR MODEL 'model_code' NOW (CHAIN 1).
Iteration: 100 / 100 [100%]  (Sampling)
Sample of chain 1 is written to file teststanfit.csv.

> 
>   pmean <- get_posterior_mean(fit)[,1]
> pmean
       y[1]        y[2]     y2[1,1]     y2[2,1]     y2[1,2]     y2[2,2] 
-0.03728337  0.08703098 -0.03728337  0.03728337 -0.08703098  0.08703098 
  y3[1,1,1]   y3[2,1,1]   y3[3,1,1]   y3[1,2,1]   y3[2,2,1]   y3[3,2,1] 
 1.00000000  2.00000000  3.00000000  4.00000000  5.00000000  6.00000000 
  y3[1,1,2]   y3[2,1,2]   y3[3,1,2]   y3[1,2,2]   y3[2,2,2]   y3[3,2,2] 
 7.00000000  8.00000000  9.00000000 10.00000000 11.00000000 12.00000000 
  y3[1,1,3]   y3[2,1,3]   y3[3,1,3]   y3[1,2,3]   y3[2,2,3]   y3[3,2,3] 
13.00000000 14.00000000 15.00000000 16.00000000 17.00000000 18.00000000 
       lp__ 
-1.05929511 

In the above, the values are correct, but not the names.

RNG seed for optimizing not used

rstan (Version 2.1.0, packaged: 2014-01-23 04:23:10 UTC, GitRev: c682ad02e3cd)

> sm <- stan_model(model_code="parameters{real y;} model{y ~ normal(0,1);}") 

TRANSLATING MODEL 'anon_model' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'anon_model' NOW.

> optimizing(sm, seed = 123)
STAN OPTIMIZATION COMMAND (BFGS)
init = random
save_iterations = 1
init_alpha = 0.001
tol_obj = 1e-08
tol_grad = 1e-08
tol_param = 1e-08
seed = 1606408912
initial log joint probability = -0.844375
    Iter      log prob        ||dx||      ||grad||       alpha  # evals  Notes 
       0             0       1.29952             0           1        5   
Optimization terminated normally: Convergence detected: gradient norm is below tolerance

The real seed is 1606408912 instead of the specified seed, which is 123.

Update OSX Mavericks install instructions without command line tools

It's possible to use the Xcode compilers on Mavericks without installing the command line tools (which just copies them to standard directories). Simply preface the call to the compiler with xcrun:

CXX=g++ -arch x86_64 -ftemplate-depth-256 -stdlib=libstdc++

becomes

CXX=xcrun g++ -arch x86_64 -ftemplate-depth-256 -stdlib=libstdc++

or

CXX=xcrun clang -arch x86_64 -ftemplate-depth-256 -stdlib=libstdc++

RStan 2.0.0 lists duplicate dependencies

When I attempted to install RStan 2.0.0, I got the following error:

> install_url('https://github.com/stan-dev/rstan/releases/download/v2.0.0/rstan_2.0.0.tar.gz')
Installing rstan_2.0.0.tar.gz from https://github.com/stan-dev/rstan/releases/download/v2.0.0/rstan_2.0.0.tar.gz
Installing rstan
Installing dependencies for rstan:
Rcpp, inline, Rcpp
Installing package(s) into ‘/Library/Frameworks/R.framework/Versions/2.15/Resources/library’
(as ‘lib’ is unspecified)

  There are binary versions available (and will be installed) but the
  source versions are later:
Error in data.frame(binary = binvers, source = srcvers, row.names = bins,  : 
  duplicate row.names: Rcpp

Installing Rcpp manually first took care of it.

Line search error nitpick

A call to optimizing ends with this:

Optimization terminated with error: Line search failed to achieve a sufficient decrease, no more progress can be made

It's odd that this is an error - isn't this the whole point of optimization? If this is meant to somehow be distinct from convergence of the optimization, it would be helpful to make the distinction more clear.

My version:

rstan (Version 2.1.0, packaged: 2013-12-27 18:21:10 UTC, GitRev: 548aa7bbbb89)

allow data to be passed to init function

Suggestion from Jo(h)n Smith on stan-users:

Pass the data in as an argument to the initialization function.

I don't know how easy that will be to do and maintain backward compatibility.

If it's too hard, there are two workarounds:

  • just make sure the data is in scope for the function
  • write a higher-order function that takes the data as an argument and returns an init function

In fact, I like the second approach enough that it probably makes this feature request redundant. Maybe we could add an example to the doc and just close this issue.

clarify doc for stan() on whether Stan or R does random initialization

An issue came up from Ryan Brackney on stan-users about which seed controls the initialization if init="random" is specified in a call to stan().

Also, the "One of" to start the comment on init is confusing because it can actually be a positive double value other than 0, as you indicate later in the doc with init_r.

  • clarify whether R/Stan does random init
  • reword init doc to make it clearer that you can use a positive double value

Equal number of iteration and warmup iterations makes R hang when plotting the results.

It seems that plotting the result of a STAN model where the number of warmup iterations equaled the number of iteration causes R to hang, that is, it is not possible to stop the execution by using Ctrl-C. Looking at the documentation it is not clear to me if the warmup argument to stan specifies the number of warmup iterations in addition to the regular number of iteration or the number of the iter iterations that should be treated as warmup. If it is the latter then this might explain why R hangs. It would however be nicer if R did not hang but rather that plotting the result of the STAN model resulted in an error message.

The following code replicates the error on my computer:

library(rstan)
model_string <- "
data {
int<lower=0> N;
real y[N];
}

parameters {
real mu;
real<lower=0> sigma;
}
model{
y ~ normal(mu, sigma);
}"

mcmc_samples <- stan(model_code=model_string, data=list(N=10, y=rnorm(10)), pars=c("mu", "sigma"), chains=3, iter=10000, warmup=10000)
plot(mcmc_samples)

Info regarding my current R setup:

> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: i686-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=C                 LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats4    graphics  grDevices utils     datasets  stats     methods  
[8] base     

other attached packages:
[1] rstan_1.3.0     inline_0.3.11   Rcpp_0.10.3     reshape_0.8.4  
[5] plyr_1.8        stringr_0.6.2   lattice_0.20-15 ggplot2_0.9.3.1

loaded via a namespace (and not attached):
 [1] codetools_0.2-8    colorspace_1.2-2   dichromat_2.0-0    digest_0.6.3      
 [5] grid_3.0.1         gtable_0.1.2       labeling_0.1       MASS_7.3-26       
 [9] munsell_0.4        proto_0.3-10       RColorBrewer_1.0-5 reshape2_1.2.2    
[13] scales_0.2.3       tools_3.0.1  

optimizing not saving data to sample_file

sm = stan_model(model_code=schools_code)
optimizing(sm, data=schools_dat, sample_file='/tmp/tmp.PjOaMMo5QZ/opt.csv')

Doesn't save anything in opt.csv for me. Just checked out code and submodule today (2013-9-7).

Build RStan with modified stan version

I'm trying to build the RStan with a modified version of stan (I'm including the wiener distribution : stan-dev/stan#469), but for some reason the libstan.a file in the end of the install process in /usr/local/lib/R/site-library/rstan/ is the old one.

I followed the instructions to build/install RStan from here

https://github.com/stan-dev/rstan/wiki/How-to-work-with-the-stan-submodule-in-rstan-repo%3F
https://github.com/stan-dev/rstan/wiki/How-to-build-rstan-package%3F

and also read the makefiles / options, without succeeding in solving this problem.

If I build libstan in it's original stan folder

leo@conscience:~/rstan.repo.wiener/stan$ make -B bin/libstan.a

and then manually copy the file after RStan instalation

cp /home/leo/rstan.repo.wiener/stan/bin/libstan.a /usr/local/lib/R/site-library/rstan/libstan

everything works fine

I'm sure it's some stupid error / option in the build process, but I can't find it.

I can see the line

ar qc libstan.a agrad__rev__var_stack.o

in the build process, and some comments about libstan.a, but I can't find out what it means.

Can someone please help me?

Thanks in advance,
Leonardo.

Here is the output of the install / build process :

> install.packages('/home/leo/rstan.repo.wiener/rstan/rstan_2.1.2.tar.gz', repos = NULL, type="source")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
* installing *source* package ‘rstan’ ...
** package ‘rstan’ correctement décompressé et sommes MD5 vérifiées
** libs
** arch - 
g++ -I/usr/share/R/include      -I"/usr/local/lib/R/site-library/rstan/include//stansrc"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0/"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0//unsupported"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/boost_1.54.0" -I"/usr/local/lib/R/site-library/rstan/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"../inst/include/stansrc"   -isystem"../inst/include/stanlib/eigen_3.2.0"  -isystem"../inst/include/stanlib/eigen_3.2.0/unsupported"  -isystem"../inst/include/stanlib/boost_1.54.0" -I"../inst/include"  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -ftemplate-depth-256  -I"/usr/local/lib/R/site-library/Rcpp/include"   -fpic  -O3 -pipe      -c stanc.cpp -o stanc.o
g++ -I/usr/share/R/include      -I"/usr/local/lib/R/site-library/rstan/include//stansrc"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0/"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0//unsupported"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/boost_1.54.0" -I"/usr/local/lib/R/site-library/rstan/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"../inst/include/stansrc"   -isystem"../inst/include/stanlib/eigen_3.2.0"  -isystem"../inst/include/stanlib/eigen_3.2.0/unsupported"  -isystem"../inst/include/stanlib/boost_1.54.0" -I"../inst/include"  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -ftemplate-depth-256  -I"/usr/local/lib/R/site-library/Rcpp/include"   -fpic  -O3 -pipe      -c chains.cpp -o chains.o
g++ -I/usr/share/R/include      -I"/usr/local/lib/R/site-library/rstan/include//stansrc"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0/"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0//unsupported"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/boost_1.54.0" -I"/usr/local/lib/R/site-library/rstan/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"../inst/include/stansrc"   -isystem"../inst/include/stanlib/eigen_3.2.0"  -isystem"../inst/include/stanlib/eigen_3.2.0/unsupported"  -isystem"../inst/include/stanlib/boost_1.54.0" -I"../inst/include"  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -ftemplate-depth-256  -I"/usr/local/lib/R/site-library/Rcpp/include"   -fpic  -O3 -pipe      -c misc.cpp -o misc.o
g++ -I/usr/share/R/include      -I"/usr/local/lib/R/site-library/rstan/include//stansrc"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0/"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0//unsupported"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/boost_1.54.0" -I"/usr/local/lib/R/site-library/rstan/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"../inst/include/stansrc"   -isystem"../inst/include/stanlib/eigen_3.2.0"  -isystem"../inst/include/stanlib/eigen_3.2.0/unsupported"  -isystem"../inst/include/stanlib/boost_1.54.0" -I"../inst/include"  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -ftemplate-depth-256  -I"/usr/local/lib/R/site-library/Rcpp/include"   -fpic  -O3 -pipe      -c init.cpp -o init.o
g++ -I/usr/share/R/include      -I"/usr/local/lib/R/site-library/rstan/include//stansrc"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0/"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0//unsupported"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/boost_1.54.0" -I"/usr/local/lib/R/site-library/rstan/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"../inst/include/stansrc"   -isystem"../inst/include/stanlib/eigen_3.2.0"  -isystem"../inst/include/stanlib/eigen_3.2.0/unsupported"  -isystem"../inst/include/stanlib/boost_1.54.0" -I"../inst/include"  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -ftemplate-depth-256  -I"/usr/local/lib/R/site-library/Rcpp/include"   -fpic  -O3 -pipe      -c gm__ast_def.cpp -o gm__ast_def.o
g++ -I/usr/share/R/include      -I"/usr/local/lib/R/site-library/rstan/include//stansrc"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0/"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0//unsupported"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/boost_1.54.0" -I"/usr/local/lib/R/site-library/rstan/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"../inst/include/stansrc"   -isystem"../inst/include/stanlib/eigen_3.2.0"  -isystem"../inst/include/stanlib/eigen_3.2.0/unsupported"  -isystem"../inst/include/stanlib/boost_1.54.0" -I"../inst/include"  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -ftemplate-depth-256  -I"/usr/local/lib/R/site-library/Rcpp/include"   -fpic  -O3 -pipe      -c gm__grammars__expression_grammar_inst.cpp -o gm__grammars__expression_grammar_inst.o
g++ -I/usr/share/R/include      -I"/usr/local/lib/R/site-library/rstan/include//stansrc"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0/"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0//unsupported"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/boost_1.54.0" -I"/usr/local/lib/R/site-library/rstan/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"../inst/include/stansrc"   -isystem"../inst/include/stanlib/eigen_3.2.0"  -isystem"../inst/include/stanlib/eigen_3.2.0/unsupported"  -isystem"../inst/include/stanlib/boost_1.54.0" -I"../inst/include"  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -ftemplate-depth-256  -I"/usr/local/lib/R/site-library/Rcpp/include"   -fpic  -O3 -pipe      -c gm__grammars__program_grammar_inst.cpp -o gm__grammars__program_grammar_inst.o
g++ -I/usr/share/R/include      -I"/usr/local/lib/R/site-library/rstan/include//stansrc"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0/"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0//unsupported"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/boost_1.54.0" -I"/usr/local/lib/R/site-library/rstan/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"../inst/include/stansrc"   -isystem"../inst/include/stanlib/eigen_3.2.0"  -isystem"../inst/include/stanlib/eigen_3.2.0/unsupported"  -isystem"../inst/include/stanlib/boost_1.54.0" -I"../inst/include"  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -ftemplate-depth-256  -I"/usr/local/lib/R/site-library/Rcpp/include"   -fpic  -O3 -pipe      -c gm__grammars__statement_2_grammar_inst.cpp -o gm__grammars__statement_2_grammar_inst.o
g++ -I/usr/share/R/include      -I"/usr/local/lib/R/site-library/rstan/include//stansrc"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0/"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0//unsupported"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/boost_1.54.0" -I"/usr/local/lib/R/site-library/rstan/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"../inst/include/stansrc"   -isystem"../inst/include/stanlib/eigen_3.2.0"  -isystem"../inst/include/stanlib/eigen_3.2.0/unsupported"  -isystem"../inst/include/stanlib/boost_1.54.0" -I"../inst/include"  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -ftemplate-depth-256  -I"/usr/local/lib/R/site-library/Rcpp/include"   -fpic  -O3 -pipe      -c gm__grammars__statement_grammar_inst.cpp -o gm__grammars__statement_grammar_inst.o
g++ -I/usr/share/R/include      -I"/usr/local/lib/R/site-library/rstan/include//stansrc"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0/"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0//unsupported"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/boost_1.54.0" -I"/usr/local/lib/R/site-library/rstan/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"../inst/include/stansrc"   -isystem"../inst/include/stanlib/eigen_3.2.0"  -isystem"../inst/include/stanlib/eigen_3.2.0/unsupported"  -isystem"../inst/include/stanlib/boost_1.54.0" -I"../inst/include"  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -ftemplate-depth-256  -I"/usr/local/lib/R/site-library/Rcpp/include"   -fpic  -O3 -pipe      -c gm__grammars__term_grammar_inst.cpp -o gm__grammars__term_grammar_inst.o
g++ -I/usr/share/R/include      -I"/usr/local/lib/R/site-library/rstan/include//stansrc"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0/"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0//unsupported"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/boost_1.54.0" -I"/usr/local/lib/R/site-library/rstan/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"../inst/include/stansrc"   -isystem"../inst/include/stanlib/eigen_3.2.0"  -isystem"../inst/include/stanlib/eigen_3.2.0/unsupported"  -isystem"../inst/include/stanlib/boost_1.54.0" -I"../inst/include"  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -ftemplate-depth-256  -I"/usr/local/lib/R/site-library/Rcpp/include"   -fpic  -O3 -pipe      -c gm__grammars__var_deccls_grammar_inst.cpp -o gm__grammars__var_deccls_grammar_inst.o
g++ -I/usr/share/R/include      -I"/usr/local/lib/R/site-library/rstan/include//stansrc"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0/"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0//unsupported"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/boost_1.54.0" -I"/usr/local/lib/R/site-library/rstan/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"../inst/include/stansrc"   -isystem"../inst/include/stanlib/eigen_3.2.0"  -isystem"../inst/include/stanlib/eigen_3.2.0/unsupported"  -isystem"../inst/include/stanlib/boost_1.54.0" -I"../inst/include"  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -ftemplate-depth-256  -I"/usr/local/lib/R/site-library/Rcpp/include"   -fpic  -O3 -pipe      -c gm__grammars__whitespace_grammar_inst.cpp -o gm__grammars__whitespace_grammar_inst.o
g++ -I/usr/share/R/include      -I"/usr/local/lib/R/site-library/rstan/include//stansrc"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0/"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/eigen_3.2.0//unsupported"  -isystem"/usr/local/lib/R/site-library/rstan/include/stanlib/boost_1.54.0" -I"/usr/local/lib/R/site-library/rstan/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"../inst/include/stansrc"   -isystem"../inst/include/stanlib/eigen_3.2.0"  -isystem"../inst/include/stanlib/eigen_3.2.0/unsupported"  -isystem"../inst/include/stanlib/boost_1.54.0" -I"../inst/include"  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -ftemplate-depth-256  -I"/usr/local/lib/R/site-library/Rcpp/include"   -fpic  -O3 -pipe      -c agrad__rev__var_stack.cpp -o agrad__rev__var_stack.o
ar qc libstan.a agrad__rev__var_stack.o 
# -@if test ! -e ../inst/libstan; then mkdir -p ../inst/libstan; fi
# cp libstan.a ../inst/libstan
# rm libstan.a 
g++ -shared -o rstan.so stanc.o chains.o misc.o init.o gm__ast_def.o gm__grammars__expression_grammar_inst.o gm__grammars__program_grammar_inst.o gm__grammars__statement_2_grammar_inst.o gm__grammars__statement_grammar_inst.o gm__grammars__term_grammar_inst.o gm__grammars__var_deccls_grammar_inst.o gm__grammars__whitespace_grammar_inst.o -L/usr/lib64/R/lib -lR
installing via 'install.libs.R' to /usr/local/lib/R/site-library/rstan
installing rstan libs to /usr/local/lib/R/site-library/rstan/libs
installing libstan.a to /usr/local/lib/R/site-library/rstan/libstan
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (rstan)

command to just compile model & reuse without fit object

From Kevin van Horn on stan-users:

Is there any way to evaluate the log joint probability of a data set and its gradient in rstan without creating a stan_fit object? It seems awkward that I have to do this

    sf <- sampling(my_stan_model, data=data, init=0, chains=1, iter=2)

just so that I can evaluate log_prob for various parameter vectors (via log_prob(sf, parameter_vector)).

Jiqiang wrote back:

No. One reason is that we added these functions later and a natural place to add is for stanfit object as the data have been read (and a model instance in terms of C++ that using Rcpp is created in memory, which is needed for these two functions).

This should be doable with some code re-org on the R side. There are a few other modularity issues like this I'd also like to address, but I'll put them in separate feature requests.

Data type inconsistencies

I'm finding it awkward to maintain the distinction between parameters in the constrained space and those in the unconstrained space. It had seemed to me that the standard was for constrained parameters to be expressed as a list, and unconstrained parameters to be expressed as a vector. But optimizing seems to return a vector in the constrained space. This forces a list version to be recovered using something like relist instead of constrain_pars, as one might expect.

Some more details:

stan-dev/stan#406

Failure installing rstan 1.3.0

Hello,

I am getting the error messages below in trying to install rstan ("...compilation failed" but I have copied all messages displayed), following instructions at http://code.google.com/p/stan/wiki/RStanGettingStarted#R on a Windows 7 (Enterprise SP1) machine, 64-bit, i5 2.5 GHz, 4 GB RAM, with R 3.0.1 (64 bit).

The test for Rcpp, which has been installed, together with inline) works successfully.

I have looked at various posts and messages but not found anything similar.

Thanks for any advice or solutions.
Derek Eaton

install.packages('rstan', type = 'source', INSTALL_opts = "--merge-multiarch")
Warning in install.packages :
cannot open: HTTP status was '404 Not Found'
Warning in install.packages :
cannot open: HTTP status was '404 Not Found'
Warning in install.packages :
unable to access index for repository http://wiki.stan.googlecode.com/git/R/bin/windows/contrib/3.0
Warning in install.packages :
package ‘rstan’ is not available (for R version 3.0.1)
Installing package into ‘C:/Users/eaton/Documents/R/win-library/3.0’
(as ‘lib’ is unspecified)
trying URL 'http://wiki.stan.googlecode.com/git/R/src/contrib/rstan_1.3.0.tar.gz'
Content type 'application/x-gzip' length 200 bytes
opened URL
downloaded 4.1 Mb

Warning in install.packages :
downloaded length 4342171 != reported length 200

install for i386

  • installing source package 'rstan' ...
    ** libs
    running 'src/Makefile.win' ...
    cygwin warning:
    MS-DOS style path detected: C:/Users/eaton/DOCUME1/R/R-301.1/etc//i386/Makeconf
    Preferred POSIX equivalent is: /cygdrive/c/Users/eaton/DOCUME1/R/R-301.1/etc/i386/Makeconf
    CYGWIN environment variable option "nodosfilewarning" turns off this warning.
    Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
    g++ -m32 -I"C:/Users/eaton/DOCUME1/R/R-301.1/include" -DDEBUG -I"../inst/include/stansrc" -I"../inst/include/stanlib/eigen_3.1.2" -I"../inst/include/stanlib/eigen_3.1.2/unsupported" -I"../inst/include/stanlib/boost_1.53.0" -I"../inst/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"C:/Users/eaton/Documents/R/win-library/3.0/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O0 -Wall -mtune=core2 -g -c stanc.cpp -o stanc.o
    g++ -m32 -I"C:/Users/eaton/DOCUME1/R/R-301.1/include" -DDEBUG -I"../inst/include/stansrc" -I"../inst/include/stanlib/eigen_3.1.2" -I"../inst/include/stanlib/eigen_3.1.2/unsupported" -I"../inst/include/stanlib/boost_1.53.0" -I"../inst/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"C:/Users/eaton/Documents/R/win-library/3.0/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O0 -Wall -mtune=core2 -g -c chains.cpp -o chains.o
    g++ -m32 -I"C:/Users/eaton/DOCUME1/R/R-301.1/include" -DDEBUG -I"../inst/include/stansrc" -I"../inst/include/stanlib/eigen_3.1.2" -I"../inst/include/stanlib/eigen_3.1.2/unsupported" -I"../inst/include/stanlib/boost_1.53.0" -I"../inst/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"C:/Users/eaton/Documents/R/win-library/3.0/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O0 -Wall -mtune=core2 -g -c misc.cpp -o misc.o
    g++ -m32 -I"C:/Users/eaton/DOCUME1/R/R-301.1/include" -DDEBUG -I"../inst/include/stansrc" -I"../inst/include/stanlib/eigen_3.1.2" -I"../inst/include/stanlib/eigen_3.1.2/unsupported" -I"../inst/include/stanlib/boost_1.53.0" -I"../inst/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"C:/Users/eaton/Documents/R/win-library/3.0/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O0 -Wall -mtune=core2 -g -c gm__ast_def.cpp -o gm__ast_def.o
    g++ -m32 -I"C:/Users/eaton/DOCUME1/R/R-301.1/include" -DDEBUG -I"../inst/include/stansrc" -I"../inst/include/stanlib/eigen_3.1.2" -I"../inst/include/stanlib/eigen_3.1.2/unsupported" -I"../inst/include/stanlib/boost_1.53.0" -I"../inst/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"C:/Users/eaton/Documents/R/win-library/3.0/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O0 -Wall -mtune=core2 -g -c gm__grammars__expression_grammar_inst.cpp -o gm__grammars__expression_grammar_inst.o
    g++ -m32 -I"C:/Users/eaton/DOCUME1/R/R-301.1/include" -DDEBUG -I"../inst/include/stansrc" -I"../inst/include/stanlib/eigen_3.1.2" -I"../inst/include/stanlib/eigen_3.1.2/unsupported" -I"../inst/include/stanlib/boost_1.53.0" -I"../inst/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"C:/Users/eaton/Documents/R/win-library/3.0/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O0 -Wall -mtune=core2 -g -c gm__grammars__program_grammar_inst.cpp -o gm__grammars__program_grammar_inst.o
    g++ -m32 -I"C:/Users/eaton/DOCUME1/R/R-301.1/include" -DDEBUG -I"../inst/include/stansrc" -I"../inst/include/stanlib/eigen_3.1.2" -I"../inst/include/stanlib/eigen_3.1.2/unsupported" -I"../inst/include/stanlib/boost_1.53.0" -I"../inst/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"C:/Users/eaton/Documents/R/win-library/3.0/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O0 -Wall -mtune=core2 -g -c gm__grammars__statement_2_grammar_inst.cpp -o gm__grammars__statement_2_grammar_inst.o
    g++ -m32 -I"C:/Users/eaton/DOCUME1/R/R-301.1/include" -DDEBUG -I"../inst/include/stansrc" -I"../inst/include/stanlib/eigen_3.1.2" -I"../inst/include/stanlib/eigen_3.1.2/unsupported" -I"../inst/include/stanlib/boost_1.53.0" -I"../inst/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"C:/Users/eaton/Documents/R/win-library/3.0/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O0 -Wall -mtune=core2 -g -c gm__grammars__statement_grammar_inst.cpp -o gm__grammars__statement_grammar_inst.o
    g++ -m32 -I"C:/Users/eaton/DOCUME1/R/R-301.1/include" -DDEBUG -I"../inst/include/stansrc" -I"../inst/include/stanlib/eigen_3.1.2" -I"../inst/include/stanlib/eigen_3.1.2/unsupported" -I"../inst/include/stanlib/boost_1.53.0" -I"../inst/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"C:/Users/eaton/Documents/R/win-library/3.0/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O0 -Wall -mtune=core2 -g -c gm__grammars__term_grammar_inst.cpp -o gm__grammars__term_grammar_inst.o
    g++ -m32 -I"C:/Users/eaton/DOCUME1/R/R-301.1/include" -DDEBUG -I"../inst/include/stansrc" -I"../inst/include/stanlib/eigen_3.1.2" -I"../inst/include/stanlib/eigen_3.1.2/unsupported" -I"../inst/include/stanlib/boost_1.53.0" -I"../inst/include" -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I"C:/Users/eaton/Documents/R/win-library/3.0/Rcpp/include" -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O0 -Wall -mtune=core2 -g -c gm__grammars__var_deccls_grammar_inst.cpp -o gm__grammars__var_deccls_grammar_inst.o
    c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/as.exe: gm__grammars__var_deccls_grammar_inst.o: section .debug_frame$ZN5boost6fusion4consINS_6spirit2qi6actionINS3_25parameterized_nonterminalINS3_4ruleINS2_7classic18position_iterator2INS2_10multi_passISt19istreambuf_iteratorIcSt11char_traitsIcEENS2_17iterator_policies14default_policyINSE_11ref_countedENSE_8no_checkENSE_24buffering_input_iteratorENSE_15split_std_dequeEEEEENS7_18file_position_baseISsEEEEFN4stan2gm10expressionEiENSQ_18whitespace_grammarISO_EENS2_11unused_typeESV_EENS0_6vectorINS_7phoenix5actorINS2_9attributeILi1EEEEENS0_5void_ES13_S13_S13_S13_S13_S13_S13_S13_EEEENSZ_INSY_9compositeINSY_11assign_evalENSX_INSY_8argumentILi2EEENS16_INSY_6detail13function_evalILi3EEENSX_INSY_5valueINSQ_19set_int_range_upperEEENS10_ILi0EEENS2_8argumentILi0EEENSY_9referenceISt18basic_stringstreamIcSC_SaIcEEEES13_S13_S13_S13_S13_S13_EEEES13_S13_S13_S13_S13_S13_S13_S13_EEEEEEEENS0_3nilEEC1ERKS1T_RKS1U: string table overflow at offset 10000927
    C:\Users\eaton\AppData\Local\Temp\ccxjzmBc.s: Assembler messages:
    C:\Users\eaton\AppData\Local\Temp\ccxjzmBc.s: Fatal error: can't close gm__grammars__var_deccls_grammar_inst.o: File too big
    make: *** [gm__grammars__var_deccls_grammar_inst.o] Error 1
    ERROR: compilation failed for package 'rstan'
  • removing 'C:/Users/eaton/Documents/R/win-library/3.0/rstan'
    Warning in install.packages :
    running command '"C:/Users/eaton/DOCUME1/R/R-301.1/bin/x64/R" CMD INSTALL --merge-multiarch -l "C:\Users\eaton\Documents\R\win-library\3.0" C:\Users\eaton\AppData\Local\Temp\RtmpWKKVSm/downloaded_packages/rstan_1.3.0.tar.gz' had status 1
    Warning in install.packages :
    installation of package ‘rstan’ had non-zero exit status

stan_rdump allow max digits specification

It'd be nice if we could specify the number of digits of precision so simulated file outputs didn't get so huge. As is, I see things like this:

K <- 4
N <- 32
x <- 
structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 0.0436764488507174, -0.310472063173452,
1.74928640167937, -1.52005793042295, -0.718757839520306, 0.233486781358933,

suppress all output from RStan

Requested by Avraham Adler on stan-users:

Firstly, as a medium-term lurker but first-time poster, I would like to thank the entire Stan development team for the creation and maintenance of Stan.

I am using Stan as part of a paper I am trying to write, and I am struggling with trying to suppress diagnostic messages. For example, when I have used JAGS, R2jags, and knitr, once I set echo, messages, and warnings to FALSE, I can have the model run every time I knit the paper, and only have the results I want displayed through \Sexpr{}. Using Stan, I am having much more of a problem. I have searched the group and have found the following threads:

  • Suppressing Warning Messages
  • silent stan?
  • RStan print() - Trivial request

I have verbose set to FALSE and refresh set to -1. I have used suppressMessages/Warnings as suggested in the thread (1), and that does not seem to do anything more than setting messages and warnings settings in the knitr chunk. I have wrapped my stan() call in sink() calls, as discussed in thread (2) as such:

<<'Bayes_Stan', eval=TRUE, echo=FALSE, message=FALSE, warning=FALSE, cache=0>>=
sink(file = "a", type = c("output", "message"))
library(rstan)
LN_S <- suppressMessages(suppressWarnings(stan(file = 'Bayes.stan', data = BayesData, pars = c('mu', 'sigma', 'LR_post', 'ASL_post', 'dev'), iter = 300000, warmup = 50000, thin = 25, chains = 5, seed = 12, refresh = -1, verbose = FALSE)))

[snip extractions and assignments]

LNPlus_S <- suppressMessages(suppressWarnings(stan(file = 'BayesPlus.stan', data = BayesDataPlus, pars = c('Pars', 'LR_post', 'ASL_post', 'dev'), iter = 300000, warmup = 50000, thin = 25, chains = 5, seed = 12, refresh = -1, verbose = FALSE)))

[snip extractions and assignments]
sink()
@

Regardless, my knitted output looks like:

…Therefore, the model was rebuilt in Stan (Stan Development Team, 2014a)—a Bayesian modeling language whose samplers are non-Gibbs.
##
## TRANSLATING MODEL 'Bayes' FROM Stan CODE TO C++ CODE NOW.
## COMPILING THE C++ CODE FOR MODEL 'Bayes' NOW.
## cygwin warning:
## MS-DOS style path detected: C:/R/RCurrent/R-30~1.2/etc/x64/Makeconf
## Preferred POSIX equivalent is: /cygdrive/c/R/RCurrent/R-30~1.2/etc/x64/Makeconf
## CYGWIN environment variable option "nodosfilewarning" turns off this warning.
## Consult the user's guide for more details about POSIX paths:
## http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
## C:/R/RCurrent/R-3.0.2/library/rstan/include//stansrc/stan/agrad/rev/var_stack.hpp:49:17: warning: 'void stan::agrad::free_memory()' defined but not used [-Wunused-function]
## C:/R/RCurrent/R-3.0.2/library/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'void stan::agrad::set_zero_all_adjoints()' defined but not used [-Wunused-function]
##
## TRANSLATING MODEL 'BayesPlus' FROM Stan CODE TO C++ CODE NOW.
## COMPILING THE C++ CODE FOR MODEL 'BayesPlus' NOW.
## cygwin warning:
## MS-DOS style path detected: C:/R/RCurrent/R-30~1.2/etc/x64/Makeconf
## Preferred POSIX equivalent is: /cygdrive/c/R/RCurrent/R-30~1.2/etc/x64/Makeconf
## CYGWIN environment variable option "nodosfilewarning" turns off this warning.
## Consult the user's guide for more details about POSIX paths:
## http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
## C:/R/RCurrent/R-3.0.2/library/rstan/include//stansrc/stan/agrad/rev/var_stack.hpp:49:17: warning: 'void stan::agrad::free_memory()' defined but not used [-Wunused-function]
## C:/R/RCurrent/R-3.0.2/library/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'void stan::agrad::set_zero_all_adjoints()' defined but not used [-Wunused-function]
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -0.34910650273000776:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.6172265406146098:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.2449912107872052:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.0263658781850085:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.7036664255500364:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.7912999475616009:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -0.67853001987262718:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -0.56723437122169695:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.9622578028376079:0, but must be > 0!Rejecting proposed initial value with zero density.
## Error in function stan::prob::lognormal_log(N4stan5agrad3varE): Scale parameter is -1.9058489407892381:0, but must be > 0!Rejecting proposed initial value with zero density.
The No-U-Turn-Sampler behind Stan is much more robust to highly autocorrelated parameters…

While I can always knit the Rnw, edit the resulting tex file to remove these lines, and re-texify that file, I would appreciate knowing if there is any way to prevent the need for such post-processing.

rstan package ist not installed after successful compilation

I am using a MacPro with 10.9.1 running and the latest version of R. I tried to install the rstan package how it has been described. It worked fine until the following messages

installing via 'install.libs.R' to /Library/Frameworks/R.framework/Versions/3.0/Resources/library/rstan
installing rstan libs to /Library/Frameworks/R.framework/Versions/3.0/Resources/library/rstan/libs
installing libstan.a to /Library/Frameworks/R.framework/Versions/3.0/Resources/library/rstan/libstan
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
kann shared object '/Library/Frameworks/R.framework/Versions/3.0/Resources/library/rstan/libs/rstan.so' nicht laden:
dlopen(/Library/Frameworks/R.framework/Versions/3.0/Resources/library/rstan/libs/rstan.so, 6): Symbol not found: __ZNK4Rcpp7RObject4attrERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE
Referenced from: /Library/Frameworks/R.framework/Versions/3.0/Resources/library/rstan/libs/rstan.so
Expected in: flat namespace
in /Library/Frameworks/R.framework/Versions/3.0/Resources/library/rstan/libs/rstan.so
Fehler: Laden fehlgeschlagen
Ausführung angehalten
ERROR: loading failed

  • removing ‘/Library/Frameworks/R.framework/Versions/3.0/Resources/library/rstan’

Die heruntergeladenen Quellpakete sind in
‘/private/var/folders/4j/wt_djlx914n1hhl9jpsc7gq40000gn/T/RtmpGvUg5W/downloaded_packages’
Warnmeldung:
In install.packages("rstan", type = "source") :
Installation des Pakets ‘rstan’ hatte Exit-Status ungleich 0

Incorrect names() for sampling results in the degenerated case

This is the simple Stan model with 0-length parameter array 'a' to demonstrate the issue:

data {
  int<lower=0> n;
}
parameters {
  real a0;
  real a[n];
}
model {
   a0 ~ normal(0,1);
   a ~ normal(a0,1);
}
zero_array.stan_model <- stan_model( model_code = stan_zero_array_code )
sampling( zero_array.stan_model, data = list( n = 0 ) )

It fails with

`names` attribute [3] must be the same length as the vector [2]

It looks like some name is being created for zero-length 'a', while its actually not present in the samples.

enhancements to output analysis

It would be nice if we could reproduce all the Coda functionality in RStan.

  1. Ideally, the posterior analysis functionality should be able to operate on an object that just contains the relevant information about variable names, dimensions, and draws with order and chain ID. (This could be a stanfit object w/o a model, but I think a better approach would be to refactor the relevant parts of the stanfit object into a standalone object that the stanfit object holds on to.)
  2. Some way to read the output of WinBUGS, OpenBUGS, and JAGS into such an object. We need this capability in order to do the kinds of evaluations both Andrew and our users have been asking for.
  3. Add all the functionality from Coda that's missing from Stan. That would include the Geweke diagnostics, autocorrelation plots (if we don't have them), running mean plots, etc. We'd have to do a sweep of the Coda doc to specify this further.

compiler warnings in Boost and Eigen

There are a lot of compiler warnings in Boost and Eigen when compiling RStan and using RStan. These can be suppressed by changing the -I compiler flags to -isystem.

I'll try to take a look at the build files and create a pull request if I find them. If anyone else has time, please feel free to take care of it first.

The -isystem should only be used for the libraries and not for includes of RStan source.

function to thin extracted posterior

Tamas Papp has some utilities that may be useful to include as part of RStan itself:

https://github.com/tpapp/my-stan-utils

These include a function to thin the extracted draws from a fit using thin_subarrays, and example of which is

posterior <- extract(fit, permuted=TRUE)

thinned_posterior <- thin_subarrays(posterior, 1:30)

With permuted=TRUE, it's OK to just take the first ones, as the permutation has already shuffled (including shuffling across chains).

RStan 2.2.0 broken with Rcpp 0.11 on Mac 10.6.8

It seems a different error message than that in #43.

Running the eight school example gives

TRANSLATING MODEL 'schools_code' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'schools_code' NOW.
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/Module.h: In copy constructor ‘Rcpp::S4_field<Class>::S4_field(const Rcpp::S4_field<Class>&) [with Class = rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> > >]’:
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/module/class.h:416:   instantiated from ‘Rcpp::List Rcpp::class_<Class>::fields(const Rcpp::XPtr<Rcpp::class_Base, Rcpp::PreserveStorage, void Rcpp::standard_delete_finalizer [with T = Rcpp::class_Base]>&) [with Class = rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> > >]’
file7ae563151ca0.cpp:517:   instantiated from here
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/Module.h:331: error: no matching function for call to ‘Rcpp::Reference_Impl<Rcpp::PreserveStorage>::Reference_Impl()’
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/Reference.h:56: note: candidates are: Rcpp::Reference_Impl<StoragePolicy>::Reference_Impl(const std::string&) [with StoragePolicy = Rcpp::PreserveStorage]
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/Reference.h:41: note:                 Rcpp::Reference_Impl<StoragePolicy>::Reference_Impl(SEXPREC*) [with StoragePolicy = Rcpp::PreserveStorage]
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/Reference.h:34: note:                 Rcpp::Reference_Impl<StoragePolicy>::Reference_Impl(const Rcpp::Reference_Impl<StoragePolicy>&) [with StoragePolicy = Rcpp::PreserveStorage]
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/Module.h: In copy constructor ‘Rcpp::S4_CppOverloadedMethods<Class>::S4_CppOverloadedMethods(const Rcpp::S4_CppOverloadedMethods<Class>&) [with Class = rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> > >]’:
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/module/class.h:435:   instantiated from ‘Rcpp::List Rcpp::class_<Class>::getMethods(const Rcpp::XPtr<Rcpp::class_Base, Rcpp::PreserveStorage, void Rcpp::standard_delete_finalizer [with T = Rcpp::class_Base]>&, std::string&) [with Class = rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> > >]’
file7ae563151ca0.cpp:517:   instantiated from here
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/Module.h:256: error: no matching function for call to ‘Rcpp::Reference_Impl<Rcpp::PreserveStorage>::Reference_Impl()’
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/Reference.h:56: note: candidates are: Rcpp::Reference_Impl<StoragePolicy>::Reference_Impl(const std::string&) [with StoragePolicy = Rcpp::PreserveStorage]
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/Reference.h:41: note:                 Rcpp::Reference_Impl<StoragePolicy>::Reference_Impl(SEXPREC*) [with StoragePolicy = Rcpp::PreserveStorage]
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/Reference.h:34: note:                 Rcpp::Reference_Impl<StoragePolicy>::Reference_Impl(const Rcpp::Reference_Impl<StoragePolicy>&) [with StoragePolicy = Rcpp::PreserveStorage]
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/Module.h: In copy constructor ‘Rcpp::S4_CppConstructor<Class>::S4_CppConstructor(const Rcpp::S4_CppConstructor<Class>&) [with Class = rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> > >]’:
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/module/class.h:446:   instantiated from ‘Rcpp::List Rcpp::class_<Class>::getConstructors(const Rcpp::XPtr<Rcpp::class_Base, Rcpp::PreserveStorage, void Rcpp::standard_delete_finalizer [with T = Rcpp::class_Base]>&, std::string&) [with Class = rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> > >]’
file7ae563151ca0.cpp:517:   instantiated from here
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/Module.h:218: error: no matching function for call to ‘Rcpp::Reference_Impl<Rcpp::PreserveStorage>::Reference_Impl()’
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/Reference.h:56: note: candidates are: Rcpp::Reference_Impl<StoragePolicy>::Reference_Impl(const std::string&) [with StoragePolicy = Rcpp::PreserveStorage]
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/Reference.h:41: note:                 Rcpp::Reference_Impl<StoragePolicy>::Reference_Impl(SEXPREC*) [with StoragePolicy = Rcpp::PreserveStorage]
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/Reference.h:34: note:                 Rcpp::Reference_Impl<StoragePolicy>::Reference_Impl(const Rcpp::Reference_Impl<StoragePolicy>&) [with StoragePolicy = Rcpp::PreserveStorage]
make: *** [file7ae563151ca0.o] Error 1

ERROR(s) during compilation: source code errors or compiler configuration errors!

Program source:
  1: 
  2: // includes from the plugin
  3: 
  4: 
  5: // user includes
  6: // Code generated by Stan version 2.1
  7: 
  8: #include <stan/model/model_header.hpp>
  9: 
 10: namespace model7ae53a022620_schools_code_namespace {
 11: 
 12: using std::vector;
 13: using std::string;
 14: using std::stringstream;
 15: using stan::model::prob_grad;
 16: using stan::math::get_base1;
 17: using stan::math::initialize;
 18: using stan::math::stan_print;
 19: using stan::math::lgamma;
 20: using stan::io::dump;
 21: using std::istream;
 22: using namespace stan::math;
 23: using namespace stan::prob;
 24: 
 25: typedef Eigen::Matrix<double,Eigen::Dynamic,1> vector_d;
 26: typedef Eigen::Matrix<double,1,Eigen::Dynamic> row_vector_d;
 27: typedef Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> matrix_d;
 28: 
 29: class model7ae53a022620_schools_code : public prob_grad {
 30: private:
 31:     int J;
 32:     vector<double> y;
 33:     vector<double> sigma;
 34: public:
 35:     model7ae53a022620_schools_code(stan::io::var_context& context__,
 36:         std::ostream* pstream__ = 0)
 37:         : prob_grad::prob_grad(0) {
 38:         static const char* function__ = "model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code(%1%)";
 39:         (void) function__; // dummy call to supress warning
 40:         size_t pos__;
 41:         (void) pos__; // dummy call to supress warning
 42:         std::vector<int> vals_i__;
 43:         std::vector<double> vals_r__;
 44:         context__.validate_dims("data initialization", "J", "int", context__.to_vec());
 45:         J = int(0);
 46:         vals_i__ = context__.vals_i("J");
 47:         pos__ = 0;
 48:         J = vals_i__[pos__++];
 49:         context__.validate_dims("data initialization", "y", "double", context__.to_vec(J));
 50:         stan::math::validate_non_negative_index("y", "J", J);
 51:         y = std::vector<double>(J,double(0));
 52:         vals_r__ = context__.vals_r("y");
 53:         pos__ = 0;
 54:         size_t y_limit_0__ = J;
 55:         for (size_t i_0__ = 0; i_0__ < y_limit_0__; ++i_0__) {
 56:             y[i_0__] = vals_r__[pos__++];
 57:         }
 58:         context__.validate_dims("data initialization", "sigma", "double", context__.to_vec(J));
 59:         stan::math::validate_non_negative_index("sigma", "J", J);
 60:         sigma = std::vector<double>(J,double(0));
 61:         vals_r__ = context__.vals_r("sigma");
 62:         pos__ = 0;
 63:         size_t sigma_limit_0__ = J;
 64:         for (size_t i_0__ = 0; i_0__ < sigma_limit_0__; ++i_0__) {
 65:             sigma[i_0__] = vals_r__[pos__++];
 66:         }
 67: 
 68:         // validate data
 69:         try { 
 70:             check_greater_or_equal(function__,J,0,"J");
 71:         } catch (std::domain_error& e) { 
 72:             throw std::domain_error(std::string("Invalid value of J: ") + std::string(e.what()));
 73:         };
 74:         for (int k0__ = 0; k0__ < J; ++k0__) {
 75:             try { 
 76:                 check_greater_or_equal(function__,sigma[k0__],0,"sigma[k0__]");
 77:             } catch (std::domain_error& e) { 
 78:                 throw std::domain_error(std::string("Invalid value of sigma: ") + std::string(e.what()));
 79:             };
 80:         }
 81: 
 82: 
 83:         // validate transformed data
 84: 
 85:         // set parameter ranges
 86:         num_params_r__ = 0U;
 87:         param_ranges_i__.clear();
 88:         ++num_params_r__;
 89:         ++num_params_r__;
 90:         num_params_r__ += J;
 91:     }
 92: 
 93:     ~model7ae53a022620_schools_code() { }
 94: 
 95: 
 96:     void transform_inits(const stan::io::var_context& context__,
 97:                          std::vector<int>& params_i__,
 98:                          std::vector<double>& params_r__) const {
 99:         stan::io::writer<double> writer__(params_r__,params_i__);
100:         size_t pos__;
101:         (void) pos__; // dummy call to supress warning
102:         std::vector<double> vals_r__;
103:         std::vector<int> vals_i__;
104: 
105: 
106:         if (!(context__.contains_r("mu")))
107:             throw std::runtime_error("variable mu missing");
108:         vals_r__ = context__.vals_r("mu");
109:         pos__ = 0U;
110:         context__.validate_dims("initialization", "mu", "double", context__.to_vec());
111:         double mu(0);
112:         mu = vals_r__[pos__++];
113:         try { writer__.scalar_unconstrain(mu); } catch (std::exception& e) {  throw std::runtime_error(std::string("Error transforming variable mu: ") + e.what()); }
114: 
115:         if (!(context__.contains_r("tau")))
116:             throw std::runtime_error("variable tau missing");
117:         vals_r__ = context__.vals_r("tau");
118:         pos__ = 0U;
119:         context__.validate_dims("initialization", "tau", "double", context__.to_vec());
120:         double tau(0);
121:         tau = vals_r__[pos__++];
122:         try { writer__.scalar_lb_unconstrain(0,tau); } catch (std::exception& e) {  throw std::runtime_error(std::string("Error transforming variable tau: ") + e.what()); }
123: 
124:         if (!(context__.contains_r("eta")))
125:             throw std::runtime_error("variable eta missing");
126:         vals_r__ = context__.vals_r("eta");
127:         pos__ = 0U;
128:         context__.validate_dims("initialization", "eta", "double", context__.to_vec(J));
129:         std::vector<double> eta(J,double(0));
130:         for (int i0__ = 0U; i0__ < J; ++i0__)
131:             eta[i0__] = vals_r__[pos__++];
132:         for (int i0__ = 0U; i0__ < J; ++i0__)
133:             try { writer__.scalar_unconstrain(eta[i0__]); } catch (std::exception& e) {  throw std::runtime_error(std::string("Error transforming variable eta: ") + e.what()); }
134:         params_r__ = writer__.data_r();
135:         params_i__ = writer__.data_i();
136:     }
137: 
138:     void transform_inits(const stan::io::var_context& context,
139:                          Eigen::Matrix<double,Eigen::Dynamic,1>& params_r) const {
140:       std::vector<double> params_r_vec;
141:       std::vector<int> params_i_vec;
142:       transform_inits(context, params_i_vec, params_r_vec);
143:       params_r.resize(params_r_vec.size());
144:       for (int i = 0; i < params_r.size(); ++i)
145:         params_r(i) = params_r_vec[i];
146:     }
147: 
148: 
149:     template <bool propto__, bool jacobian__, typename T__>
150:     T__ log_prob(vector<T__>& params_r__,
151:                  vector<int>& params_i__,
152:                  std::ostream* pstream__ = 0) const {
153: 
154:         T__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
155:         (void) DUMMY_VAR__;  // suppress unused var warning
156: 
157:         T__ lp__(0.0);
158:         stan::math::accumulator<T__> lp_accum__;
159: 
160:         // model parameters
161:         stan::io::reader<T__> in__(params_r__,params_i__);
162: 
163:         T__ mu;
164:         (void) mu;   // dummy to suppress unused var warning
165:         if (jacobian__)
166:             mu = in__.scalar_constrain(lp__);
167:         else
168:             mu = in__.scalar_constrain();
169: 
170:         T__ tau;
171:         (void) tau;   // dummy to suppress unused var warning
172:         if (jacobian__)
173:             tau = in__.scalar_lb_constrain(0,lp__);
174:         else
175:             tau = in__.scalar_lb_constrain(0);
176: 
177:         vector<T__> eta;
178:         size_t dim_eta_0__ = J;
179:         eta.reserve(dim_eta_0__);
180:         for (size_t k_0__ = 0; k_0__ < dim_eta_0__; ++k_0__) {
181:             if (jacobian__)
182:                 eta.push_back(in__.scalar_constrain(lp__));
183:             else
184:                 eta.push_back(in__.scalar_constrain());
185:         }
186: 
187: 
188:         // transformed parameters
189:         vector<T__> theta(J);
190: 
191:         // initialized transformed params to avoid seg fault on val access
192:                 stan::math::fill(theta,DUMMY_VAR__);
193: 
194:         for (int j = 1; j <= J; ++j) {
195:             stan::math::assign(get_base1_lhs(theta,j,"theta",1), (mu + (tau * get_base1(eta,j,"eta",1))));
196:         }
197: 
198:         // validate transformed parameters
199:         for (int i0__ = 0; i0__ < J; ++i0__) {
200:             if (stan::math::is_uninitialized(theta[i0__])) {
201:                 std::stringstream msg__;
202:                 msg__ << "Undefined transformed parameter: theta" << '[' << i0__ << ']';
203:                 throw std::runtime_error(msg__.str());
204:             }
205:         }
206: 
207:         const char* function__ = "validate transformed params %1%";
208:         (void) function__; // dummy to suppress unused var warning
209:         // model body
210:         lp_accum__.add(normal_log<propto__>(eta, 0, 1));
211:         lp_accum__.add(normal_log<propto__>(y, theta, sigma));
212: 
213:         lp_accum__.add(lp__);
214:         return lp_accum__.sum();
215: 
216:     } // log_prob()
217: 
218:     template <bool propto, bool jacobian, typename T>
219:     T log_prob(Eigen::Matrix<T,Eigen::Dynamic,1>& params_r,
220:                std::ostream* pstream = 0) const {
221:       std::vector<T> vec_params_r;
222:       vec_params_r.reserve(params_r.size());
223:       for (int i = 0; i < params_r.size(); ++i)
224:         vec_params_r.push_back(params_r(i));
225:       std::vector<int> vec_params_i;
226:       return log_prob<propto,jacobian,T>(vec_params_r, vec_params_i, pstream);
227:     }
228: 
229: 
230:     void get_param_names(std::vector<std::string>& names__) const {
231:         names__.resize(0);
232:         names__.push_back("mu");
233:         names__.push_back("tau");
234:         names__.push_back("eta");
235:         names__.push_back("theta");
236:     }
237: 
238: 
239:     void get_dims(std::vector<std::vector<size_t> >& dimss__) const {
240:         dimss__.resize(0);
241:         std::vector<size_t> dims__;
242:         dims__.resize(0);
243:         dimss__.push_back(dims__);
244:         dims__.resize(0);
245:         dimss__.push_back(dims__);
246:         dims__.resize(0);
247:         dims__.push_back(J);
248:         dimss__.push_back(dims__);
249:         dims__.resize(0);
250:         dims__.push_back(J);
251:         dimss__.push_back(dims__);
252:     }
253: 
254:     template <typename RNG>
255:     void write_array(RNG& base_rng__,
256:                      std::vector<double>& params_r__,
257:                      std::vector<int>& params_i__,
258:                      std::vector<double>& vars__,
259:                      bool include_tparams__ = true,
260:                      bool include_gqs__ = true,
261:                      std::ostream* pstream__ = 0) const {
262:         vars__.resize(0);
263:         stan::io::reader<double> in__(params_r__,params_i__);
264:         static const char* function__ = "model7ae53a022620_schools_code_namespace::write_array(%1%)";
265:         (void) function__; // dummy call to supress warning
266:         // read-transform, write parameters
267:         double mu = in__.scalar_constrain();
268:         double tau = in__.scalar_lb_constrain(0);
269:         vector<double> eta;
270:         size_t dim_eta_0__ = J;
271:         for (size_t k_0__ = 0; k_0__ < dim_eta_0__; ++k_0__) {
272:             eta.push_back(in__.scalar_constrain());
273:         }
274:         vars__.push_back(mu);
275:         vars__.push_back(tau);
276:         for (int k_0__ = 0; k_0__ < J; ++k_0__) {
277:             vars__.push_back(eta[k_0__]);
278:         }
279: 
280:         if (!include_tparams__) return;
281:         // declare and define transformed parameters
282:         double lp__ = 0.0;
283:         (void) lp__; // dummy call to supress warning
284:         stan::math::accumulator<double> lp_accum__;
285: 
286:         vector<double> theta(J, 0.0);
287: 
288:         for (int j = 1; j <= J; ++j) {
289:             stan::math::assign(get_base1_lhs(theta,j,"theta",1), (mu + (tau * get_base1(eta,j,"eta",1))));
290:         }
291: 
292:         // validate transformed parameters
293: 
294:         // write transformed parameters
295:         for (int k_0__ = 0; k_0__ < J; ++k_0__) {
296:             vars__.push_back(theta[k_0__]);
297:         }
298: 
299:         if (!include_gqs__) return;
300:         // declare and define generated quantities
301: 
302: 
303:         // validate generated quantities
304: 
305:         // write generated quantities
306:     }
307: 
308:     template <typename RNG>
309:     void write_array(RNG& base_rng,
310:                      Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
311:                      Eigen::Matrix<double,Eigen::Dynamic,1>& vars,
312:                      bool include_tparams = true,
313:                      bool include_gqs = true,
314:                      std::ostream* pstream = 0) const {
315:       std::vector<double> params_r_vec(params_r.size());
316:       for (int i = 0; i < params_r.size(); ++i)
317:         params_r_vec[i] = params_r(i);
318:       std::vector<double> vars_vec;
319:       std::vector<int> params_i_vec;
320:       write_array(base_rng,params_r_vec,params_i_vec,vars_vec,include_tparams,include_gqs,pstream);
321:       vars.resize(vars_vec.size());
322:       for (int i = 0; i < vars.size(); ++i)
323:         vars(i) = vars_vec[i];
324:     }
325: 
326: 
327:     void write_csv_header(std::ostream& o__) const {
328:         stan::io::csv_writer writer__(o__);
329:         writer__.comma();
330:         o__ << "mu";
331:         writer__.comma();
332:         o__ << "tau";
333:         for (int k_0__ = 1; k_0__ <= J; ++k_0__) {
334:             writer__.comma();
335:             o__ << "eta" << '.' << k_0__;
336:         }
337:         for (int k_0__ = 1; k_0__ <= J; ++k_0__) {
338:             writer__.comma();
339:             o__ << "theta" << '.' << k_0__;
340:         }
341:         writer__.newline();
342:     }
343: 
344:     template <typename RNG>
345:     void write_csv(RNG& base_rng__,
346:                    std::vector<double>& params_r__,
347:                    std::vector<int>& params_i__,
348:                    std::ostream& o__,
349:                    std::ostream* pstream__ = 0) const {
350:         stan::io::reader<double> in__(params_r__,params_i__);
351:         stan::io::csv_writer writer__(o__);
352:         static const char* function__ = "model7ae53a022620_schools_code_namespace::write_csv(%1%)";
353:         (void) function__; // dummy call to supress warning
354:         // read-transform, write parameters
355:         double mu = in__.scalar_constrain();
356:         writer__.write(mu);
357:         double tau = in__.scalar_lb_constrain(0);
358:         writer__.write(tau);
359:         vector<double> eta;
360:         size_t dim_eta_0__ = J;
361:         for (size_t k_0__ = 0; k_0__ < dim_eta_0__; ++k_0__) {
362:             eta.push_back(in__.scalar_constrain());
363:             writer__.write(eta[k_0__]);
364:         }
365: 
366:         // declare, define and validate transformed parameters
367:         double lp__ = 0.0;
368:         (void) lp__; // dummy call to supress warning
369:         stan::math::accumulator<double> lp_accum__;
370: 
371:         vector<double> theta(J, 0.0);
372: 
373:         for (int j = 1; j <= J; ++j) {
374:             stan::math::assign(get_base1_lhs(theta,j,"theta",1), (mu + (tau * get_base1(eta,j,"eta",1))));
375:         }
376: 
377: 
378:         // write transformed parameters
379:         for (int k_0__ = 0; k_0__ < J; ++k_0__) {
380:             writer__.write(theta[k_0__]);
381:         }
382: 
383:         // declare and define generated quantities
384: 
385: 
386:         // validate generated quantities
387: 
388:         // write generated quantities
389:         writer__.newline();
390:     }
391: 
392:     template <typename RNG>
393:     void write_csv(RNG& base_rng,
394:                    Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
395:                    std::ostream& o,
396:                    std::ostream* pstream = 0) const {
397:       std::vector<double> params_r_vec(params_r.size());
398:       for (int i = 0; i < params_r.size(); ++i)
399:         params_r_vec[i] = params_r(i);
400:       std::vector<int> params_i_vec;  // dummy
401:       write_csv(base_rng, params_r_vec, params_i_vec, o, pstream);
402:     }
403: 
404:     static std::string model_name() {
405:         return "model7ae53a022620_schools_code";
406:     }
407: 
408: 
409:     void constrained_param_names(std::vector<std::string>& param_names__,
410:                                  bool include_tparams__ = true,
411:                                  bool include_gqs__ = true) const {
412:         std::stringstream param_name_stream__;
413:         param_name_stream__.str(std::string());
414:         param_name_stream__ << "mu";
415:         param_names__.push_back(param_name_stream__.str());
416:         param_name_stream__.str(std::string());
417:         param_name_stream__ << "tau";
418:         param_names__.push_back(param_name_stream__.str());
419:         for (int k_0__ = 1; k_0__ <= J; ++k_0__) {
420:             param_name_stream__.str(std::string());
421:             param_name_stream__ << "eta" << '.' << k_0__;
422:             param_names__.push_back(param_name_stream__.str());
423:         }
424: 
425:         if (!include_gqs__ && !include_tparams__) return;
426:         for (int k_0__ = 1; k_0__ <= J; ++k_0__) {
427:             param_name_stream__.str(std::string());
428:             param_name_stream__ << "theta" << '.' << k_0__;
429:             param_names__.push_back(param_name_stream__.str());
430:         }
431: 
432:         if (!include_gqs__) return;
433:     }
434: 
435: 
436:     void unconstrained_param_names(std::vector<std::string>& param_names__,
437:                                    bool include_tparams__ = true,
438:                                    bool include_gqs__ = true) const {
439:         std::stringstream param_name_stream__;
440:         param_name_stream__.str(std::string());
441:         param_name_stream__ << "mu";
442:         param_names__.push_back(param_name_stream__.str());
443:         param_name_stream__.str(std::string());
444:         param_name_stream__ << "tau";
445:         param_names__.push_back(param_name_stream__.str());
446:         for (int k_0__ = 1; k_0__ <= J; ++k_0__) {
447:             param_name_stream__.str(std::string());
448:             param_name_stream__ << "eta" << '.' << k_0__;
449:             param_names__.push_back(param_name_stream__.str());
450:         }
451: 
452:         if (!include_gqs__ && !include_tparams__) return;
453:         for (int k_0__ = 1; k_0__ <= J; ++k_0__) {
454:             param_name_stream__.str(std::string());
455:             param_name_stream__ << "theta" << '.' << k_0__;
456:             param_names__.push_back(param_name_stream__.str());
457:         }
458: 
459:         if (!include_gqs__) return;
460:     }
461: 
462: }; // model
463: 
464: } // namespace
465: 
466: #include <rstan/rstaninc.hpp>
467: /**
468:  * Define Rcpp Module to expose stan_fit's functions to R. 
469:  */ 
470: RCPP_MODULE(stan_fit4model7ae53a022620_schools_code_mod){
471:   Rcpp::class_<rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, 
472:                boost::random::ecuyer1988> >("stan_fit4model7ae53a022620_schools_code")
473:     // .constructor<Rcpp::List>() 
474:     .constructor<SEXP, SEXP>() 
475:     // .constructor<SEXP, SEXP>() 
476:     .method("call_sampler", 
477:             &rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::ecuyer1988>::call_sampler) 
478:     .method("param_names", 
479:             &rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::ecuyer1988>::param_names) 
480:     .method("param_names_oi", 
481:             &rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::ecuyer1988>::param_names_oi) 
482:     .method("param_fnames_oi", 
483:             &rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::ecuyer1988>::param_fnames_oi) 
484:     .method("param_dims", 
485:             &rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::ecuyer1988>::param_dims) 
486:     .method("param_dims_oi", 
487:             &rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::ecuyer1988>::param_dims_oi) 
488:     .method("update_param_oi", 
489:             &rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::ecuyer1988>::update_param_oi) 
490:     .method("param_oi_tidx",
491:             &rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::ecuyer1988>::param_oi_tidx)
492:     .method("grad_log_prob", 
493:             &rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::ecuyer1988>::grad_log_prob) 
494:     .method("log_prob", 
495:             &rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::ecuyer1988>::log_prob) 
496:     .method("unconstrain_pars", 
497:             &rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::ecuyer1988>::unconstrain_pars) 
498:     .method("constrain_pars", 
499:             &rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::ecuyer1988>::constrain_pars) 
500:     .method("num_pars_unconstrained", 
501:             &rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::ecuyer1988>::num_pars_unconstrained)
502:     .method("unconstrained_param_names", 
503:             &rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::ecuyer1988>::unconstrained_param_names)
504:     .method("constrained_param_names", 
505:             &rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::ecuyer1988>::constrained_param_names)
506:     ;
507: } 
508: 
509: // declarations
510: extern "C" {
511: SEXP file7ae563151ca0( ) ;
512: }
513: 
514: // definition
515: 
516: SEXP file7ae563151ca0(  ){
517:  return Rcpp::wrap("schools_code");
518: }
519: 
520: 
Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! /Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/Module.h: In copy constructor ‘Rcpp::S4_field<Class>::S4_field(const Rcpp::S4_field<Class>&) [with Class = rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> > >]’:
/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include/Rcpp/module/class.h:416:   instantiated from ‘Rcpp::List Rcpp::class_<Class>::fields(const Rcpp::XPtr<Rcpp::class_Base, Rcpp::PreserveStorage, void Rcpp::standard_delete_finalizer [with T = Rcpp::class_Base]>&) [with Class = rstan::stan_fit<model7ae53a022620_schools_code_namespace::model7ae53a022620_schools_code, boost::random::additive_combine_engine<boost::random
In addition: Warning message:
running command '/Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB file7ae563151ca0.cpp 2> file7ae563151ca0.cpp.err.txt' had status 1 

failure to install rstan 1.3.0 from within Architect on Ubuntu 12.04 LTS

(Tobias Verbeke originally submitted on Stan's issue tracker as stan-dev/stan#233 . I just moved it here.)

I was not able to install rstan 1.3.0 from within Architect 0.9.3 (which has R 3.0.1) on an up to date Ubuntu 12.04 LTS (amd64); when executing from the command line I get the following error message.

** R
Loading required package: inline
Warning: namespace ‘rstan’ is not available and has been replaced
by .GlobalEnv when processing object ‘exfit’
** inst
** preparing package for lazy loading
Error in setMethod("unconstrain_pars", signature = "stanfit", function(object,  : 
  no existing definition for function ‘unconstrain_pars’
Error : unable to load R code in package ‘rstan’
ERROR: lazy loading failed for package ‘rstan’
* removing ‘/home/tobias/.architect/workspace/.metadata/.r/eplugin-local-eu.openanalytics.r.server/user-library/rstan’

The error message is the same as reported in #139, be it that it is on a different platform, different OS and different IDE.

AFAICS there is no .Rprofile involved (there is no such file on my system) and other profile files that come with R are factory-fresh. Is there any clue on what is causing this?

Select what model parameters to collect

Probably, this is a more general STAN question and maybe it even have been addressed already, but I hadn't found the solution.

Sometimes the parameters/transformed parameters are purely auxiliary and must not be collected. Collecting them a) increases the memory/disk space footprint b) makes it impossible to join the stanfit objects that differ only by these auxiliary parameters.

In JAGS one can explicitly specify the set of parameters to be collected (variable.names= in coda.samples()). Is it possible to implement something similar in (r)stan?

Add Two parameter Pareto (aka Lomax) distribution?

The Pareto distribution currently in Stan is the one parameter version (also known as the single-parameter (A.4.1.4 - pdf) or Pareto Type I). In actuarial science, the Pareto is one of the most commonly used long-tailed distributions, but primarily in its two-parameter version A.2.4.1, also known as Pareto Type II or Lomax. I've looked at pareto.hpp, and the code is way beyond my meager skills. How difficult would it be to add this flavor of Pareto to Stan?

number of comment lines in read_stan_csv too limited

Reported to me off list:

I just discovered a nasty bug in rstan which prevents read_stan_csv to work properly for the case of a full mass matrix. The function refuses to import the csv files generated in this case. The reason is simple: In my case I have a lot of variables and hence the the mass matrix becomes large. Now read_stan_csv reads all the comments from the stan run which it parses. If it does not find the “Elapsed Time” line in the comments the function aborts. However, the number of comments to import is limited to 50. This limit is hard coded in the function and it is by far to small in my case due to the many variables for which the mass matrix is identified after adaptation.

[Hopefully this will be easy to verify and fix.]

Rstan 2.0.0 and dense mass matrix fails with NUTS

From Sebastian Webber on stan-users:

Maybe I read the documentation wrong, but I am not able to run NUTS with a full mass matrix:

sdemo <- stan_demo("eight_schools", algorithm="NUTS", control=list(metric="dense_e"))
print(sdemo)

... works ...

sdemoM <- stan_demo("eight_schools", algorithm="NUTS", control=list(metric="dense_e"))
print(sdemoM)

fails with:

TRANSLATING MODEL 'eight_schools' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'eight_schools' NOW.
SAMPLING FOR MODEL 'eight_schools' NOW (CHAIN 1).
Iteration: 2000 / 2000 [100%]  (Sampling)
Elapsed Time: 6.25 seconds (Warm-up)
              2.29 seconds (Sampling)
              8.54 seconds (Total)

Error : No sampler matching HMC specification!
error occurred during calling the sampler; sampling not done
R2.15.1>

Am I calling it wrong? What would correspond to the option of rstan 1.3.0 allowing me to run NUTS with a full mass matrix instead of a diagonal one. I have some models which run a lot better with a full mass matrix.

make output of optimizing() consistent without output of stan()

David Chudzicki suggested this enhancement in mail to stan-users of Feb 3, which I excerpt here:

Calling the extract method on a stanfit object (returned by sampling or stan) puts the parameters in a very convenient form for working with. Is there a nice way to get the parameters resulting from optimizing in a similarly convenient form?

Naively, it seems to me like maybe it would make sense for the return value of optimizing to share a class with the return value of sampling. We do some of the same things with both types of fits, and I'd like the way I handle them to be similar. Maybe optimizing should give you a stanfit object with 1 chain and 1 iteration? Or maybe they're different subclasses of the same parent class?

Right now the return is a simple list rather than an object like the stanfit object.

RStan dump truncating integers with scientific notation

Reported by Kevin S Van Horn on stan-users list:

I had a variable n with value 1234567890123456. This was written to the dump file as 1.234568e+15, which avoids the problem of it being interpreted as an integer, but loses everything after the first 7 digits.

What should we do for this? Issues are that

  • it's larger than a 32-bit int
  • it's an integer that's getting written out in scientific notation, which we reserve for double values

Seems to me we do one of the following

  • fix the I/O in Stan so that it can read long integers and store them and then raise an error if you try to get them as an int and they overflow; this also requires forcing R not to write out scientific notation for integer values
  • include type information in the rstan_dump output, and if we see a value larger than 2^32 - 1, raise some kind of error from rstan_dump

It seems to do this right, we also need to allow

  • control number of significant digits in dump output

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

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.)

set_cppo('debug') broken

This is not related to the problems with the new (11.0) release of Rcpp, but g++ won't compile stan models under the old (10.6) Rcpp if I set_cppo('debug').

Testing using the 8 schools model:

library(rstan)
set_cppo("fast")

schools_code <- '
  data {
    int<lower=0> J; // number of schools 
    real y[J]; // estimated treatment effects
    real<lower=0> sigma[J]; // s.e. of effect estimates 
  }
  parameters {
    real mu; 
    real<lower=0> tau;
    real eta[J];
  }
  transformed parameters {
    real theta[J];
    for (j in 1:J)
      theta[j] <- mu + tau * eta[j];
  }
  model {
    eta ~ normal(0, 1);
    y ~ normal(theta, sigma);
  }
'

schools_dat <- list(J = 8, 
                    y = c(28,  8, -3,  7, -1,  1, 18, 12),
                    sigma = c(15, 10, 16, 11,  9, 11, 10, 18))

fit <- stan(model_code = schools_code, data = schools_dat, 
            iter = 1000, chains = 4)

set_cppo("debug")
fit <- stan(model_code = schools_code, data = schools_dat, 
            iter = 1000, chains = 4)

produces output

TRANSLATING MODEL 'schools_code' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'schools_code' NOW.
cygwin warning:
  MS-DOS style path detected: C:/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf
  Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
C:/Users/JonathanGilligan/Documents/R/win-library/3.0/rstan/include//stansrc/stan/agrad/rev/var_stack.hpp:49:17: warning: 'void stan::agrad::free_memory()' defined but not used [-Wunused-function]
C:/Users/JonathanGilligan/Documents/R/win-library/3.0/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'void stan::agrad::set_zero_all_adjoints()' defined but not used [-Wunused-function]
SAMPLING FOR MODEL 'schools_code' NOW (CHAIN 1).
Iteration: 1000 / 1000 [100%]  (Sampling)
Elapsed Time: 0.026 seconds (Warm-up)
              0.027 seconds (Sampling)
              0.053 seconds (Total)

SAMPLING FOR MODEL 'schools_code' NOW (CHAIN 2).
Iteration: 1000 / 1000 [100%]  (Sampling)
Elapsed Time: 0.024 seconds (Warm-up)
              0.018 seconds (Sampling)
              0.042 seconds (Total)

SAMPLING FOR MODEL 'schools_code' NOW (CHAIN 3).
Iteration: 1000 / 1000 [100%]  (Sampling)
Elapsed Time: 0.027 seconds (Warm-up)
              0.018 seconds (Sampling)
              0.045 seconds (Total)

SAMPLING FOR MODEL 'schools_code' NOW (CHAIN 4).
Iteration: 1000 / 1000 [100%]  (Sampling)
Elapsed Time: 0.031 seconds (Warm-up)
              0.027 seconds (Sampling)
              0.058 seconds (Total)

for the 'fast' compile and

mode debug with DDEBUG for compiling C++ code is set

TRANSLATING MODEL 'schools_code' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'schools_code' NOW.
...
Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! cygwin warning:
  MS-DOS style path detected: C:/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf
  Preferred POSIX equivalent is: /cygdrive/c/PROGRA~1/R/R-30~1.2/etc/x64/Makeconf
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
C:/Users/JonathanGilligan/Documents/R/win-library/3.0/rstan/include//stansrc/stan/agrad/rev/var_stack.hpp:49:17: warning: 'void stan::agrad::free_memory()' defined but not used [-Wunused-function]
C:/Users/JonathanGilligan/Documents/R/win-library/3.0/rstan/include//stansrc/stan/agrad/rev/chainable.hpp:87:17: warning: 'void stan::agrad::set_zero_all_adjoints()' defined but not used [-Wunused-function]
c:/rtools/gcc-4.6.3/bin/../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/bin/as.exe: file1c9814344f2e.o: too many sections (37382)
C:\Users\JONA
In addition: Warning message:
running command 'C:/PROGRA~1/R/R-30~1.2/bin/x64/R CMD SHLIB file1c9814344f2e.cpp 2> file1c9814344f2e.cpp.err.txt' had status 1 

for the 'debug' compile (the "..." is omitting a 500+ line dump of the C++ code)

My G++ is from the latest RTools ("GCC 4.6.3 20111208 (prerelease) (GCC)")

My R sessionInfo is

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rstan_2.1.0   Rcpp_0.10.6   inline_0.3.13

loaded via a namespace (and not attached):
[1] codetools_0.2-8 stats4_3.0.2    tools_3.0.2    
> 

For what it's worth, I'm working on 64-bit windows 7 Professional, 16 GB RAM, 86 GB free disk space. I have several similarly configured computers and see this problem with 100% reproducibility on all of them.

print treepepth, etc. in output of print()

We want to include the same diagnostic output "parameters" as in CmdStan, which means adding

So that means adding:

  • accept_stat__
  • stepsize__
  • treedepth__
  • n_leapfrog__
  • n_divergent__

CmdStan's output looks like:

                 Mean     MCSE   StdDev        5%   50%   95%  N_Eff  N_Eff/s  R_hat
lp__             -7.3  3.5e-02  6.9e-01  -8.7e+00  -7.0  -6.7    390    34020   1.00
accept_stat__    0.64  1.2e-02  3.6e-01   5.1e-03  0.74   1.0    882    76898   1.00
stepsize__        1.8  7.8e-15  5.6e-15   1.8e+00   1.8   1.8   0.50       44   1.00
treedepth__     0.076  8.6e-03  2.7e-01   0.0e+00  0.00   1.0    942    82167   1.00
n_leapfrog__     2.7  4.9e-02  1.3e+00        1.0   3.0   3.0    716    65090  1.0e+00
n_divergent__    0.00  0.0e+00  0.0e+00   0.0e+00  0.00  0.00   1000    90909   1.00
theta            0.25  4.2e-03  1.2e-01   9.0e-02  0.23  0.47    827    72146   1.00

Small rstan_options documentation bug Edit

[moved from https://github.com/stan-dev/stan/issues/420]

The documentation for Rstan 2.0.1 says that the option for setting the color for NA and infinite values of rhat is 'plot_rhat_na_col', but the correct option is 'plot_rhat_nan_col'.

Also, the documentation says that plot_rhat_cols should be the same length as plot_rhat_breaks, but the default is for length(rstan_options('plot_rhat_breaks')) to be 4 and length(rstan_options('plot_rhat_cols')) to be 6.

unable to use data argument for stan() for local objects

From Andrew:

Hi, I have a small problem. When I call stan, specifying data like this:
data=c(“N”,”K”,"X","y"),
it processes the data fine, except if I do this within a function where the data are defined locally (inside the function), in which case it says it can’t find the data).

The function call works fine if I give the data as a list:
data=list(N=N,K=K,X=X,y=y)

compression for I/O in read_comments function

From Sebastian Weber (edited for formatting/naming)

The outputs from CmdStan can become quite large for complex models. Hence the desire to compress these files with bzip2 (which saves 70% of the file size). But the read_comments call in read_stan_csv is a problem here. If I pass a list of *.csv.bz2 files to read_stan_csv, the R function read.csv will not complain at all to read in the compressed csv file, but the read_comments function which is internal to RStan does not like the compressed file.

If the read_comments file could deal with compressed file streams that would solve the problem I think and then allow me to process compressed csv files which is a lot faster as 70% less of data needs to be transfer over our network (stuff is stored on NAS).

stan_demo with long path name does not work

Windows, R 3.0.1:

> stan_demo()
Error in file(fname, "rt") : cannot open the connection
In addition: Warning message:
In file(fname, "rt") :
  cannot open file 'C:/Program Files/R/R-3.0.1/library/rstan/include/stansrc/models/bugs_examples/vol1/magnesium/magnesi': No such file or directory
Error in get_model_strcode(file, model_code) : 
  cannot open model file "C:/Program Files/R/R-3.0.1/library/rstan/include/stansrc/models/bugs_examples/vol1/magnesium/magnesi"
> 

The reason seems to be that function select.list of R can only support names of length less than 100 for some reason.

> a <- paste(rep(1,100), collapse = '')
> a
[1] "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
> select.list(a)
[1] "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"

> select.list(paste0(a,"z"))
[1] "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"

Strange results with the rats example

I don't know if this is an error but it seems kind of strange that these problems occur with the ordinary rats example. rats.stan and rats_dat is the same as on the example page. Im at a Mac 10.9 machine.

The eight school example is working just fine. So I wonder what is the problem.

> rats_fit <- stan(file = 'Code/stanModels/rats.stan', data = rats_dat, verbose = FALSE)

TRANSLATING MODEL 'rats' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'rats' NOW.
SAMPLING FOR MODEL 'rats' NOW (CHAIN 1).
Iteration:    1 / 2000 [  0%]  (Warmup)

Informational Message: The current Metropolis proposal is about to be rejected becuase of the following issue:
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is 0:0, but must be > 0!
If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Iteration: 2000 / 2000 [100%]  (Sampling)
Elapsed Time: 14.5698 seconds (Warm-up)
              1.83452 seconds (Sampling)
              16.4044 seconds (Total)

SAMPLING FOR MODEL 'rats' NOW (CHAIN 2).
Iteration: 2000 / 2000 [100%]  (Sampling)
Elapsed Time: 7.61113 seconds (Warm-up)
              1.75341 seconds (Sampling)
              9.36453 seconds (Total)

SAMPLING FOR MODEL 'rats' NOW (CHAIN 3).
Iteration: 2000 / 2000 [100%]  (Sampling)
Elapsed Time: 5.02147 seconds (Warm-up)
              1.87574 seconds (Sampling)
              6.89721 seconds (Total)

SAMPLING FOR MODEL 'rats' NOW (CHAIN 4).
Iteration:    1 / 2000 [  0%]  (Warmup)

Informational Message: The current Metropolis proposal is about to be rejected becuase of the following issue:
Error in function stan::prob::normal_log(N4stan5agrad3varE): Scale parameter is 0:0, but must be > 0!
If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
Iteration: 2000 / 2000 [100%]  (Sampling)
Elapsed Time: 7.12446 seconds (Warm-up)
              1.74103 seconds (Sampling)
              8.86549 seconds (Total)

And my session info in R:

> sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] sv_SE.UTF-8/sv_SE.UTF-8/sv_SE.UTF-8/C/sv_SE.UTF-8/sv_SE.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rstan_2.2.0   inline_0.3.13 Rcpp_0.11.0  

loaded via a namespace (and not attached):
[1] codetools_0.2-8 stats4_3.0.2    tools_3.0.2    

And the eight schools example:

TRANSLATING MODEL 'testSchools' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'testSchools' NOW.
SAMPLING FOR MODEL 'testSchools' NOW (CHAIN 1).
Iteration: 1000 / 1000 [100%]  (Sampling)
Elapsed Time: 0.177893 seconds (Warm-up)
              0.139657 seconds (Sampling)
              0.31755 seconds (Total)

SAMPLING FOR MODEL 'testSchools' NOW (CHAIN 2).
Iteration: 1000 / 1000 [100%]  (Sampling)
Elapsed Time: 0.207837 seconds (Warm-up)
              0.231257 seconds (Sampling)
              0.439094 seconds (Total)

SAMPLING FOR MODEL 'testSchools' NOW (CHAIN 3).
Iteration: 1000 / 1000 [100%]  (Sampling)
Elapsed Time: 0.226824 seconds (Warm-up)
              0.151477 seconds (Sampling)
              0.378301 seconds (Total)

SAMPLING FOR MODEL 'testSchools' NOW (CHAIN 4).
Iteration: 1000 / 1000 [100%]  (Sampling)
Elapsed Time: 0.200859 seconds (Warm-up)
              0.164935 seconds (Sampling)
              0.365794 seconds (Total)

stan_rdump outputs large ints in scientific notation

stan_rdump() (v2.1.0) dumps large ints in scientific notation in some cases.

e.g.

N <- 1000000
stan_rdump(c('N'), file='test.data.R')

outputs:
N <- 1e+06

when trying to load the data into Stan this produces an error:

Exception: int variable contained non-int values; processing stage=data initialization; variable name=N; base type=int
Diagnostic information: 
Dynamic exception type: std::runtime_error
std::exception::what: int variable contained non-int values; processing stage=data initialization; variable name=N; base type=int

How to install rstan and stan from github?

I was able to follow the directions to fetch rstan from github, then to download and initialize the stan submodule.

When I install rstan via an official distribution, it is clever enough to download stan and install it.

I tried "make install" according to "INSTALL.txt" but I get this far:

brown@air ~/D/C/r/rstan> make install                                                                                                                   
if test -d tmpstanlib; then ln -s ../../../tmpstanlib/ ./rstan/inst/include/stanlib; else ln -s ../../../../stan/lib ./rstan/inst/include/stanlib; fi
ln -s ../../../../stan/src ./rstan/inst/include/stansrc
/opt/local/Library/Frameworks/R.framework/Resources/bin/R --vanilla CMD build rstan --md5  # --no-vignettes --no-manual
* checking for file ‘rstan/DESCRIPTION’ ... OK
* preparing ‘rstan’:
* checking DESCRIPTION meta-information ... OK
* cleaning src
* installing the package to process help pages
      -----------------------------------
* installing *source* package ‘rstan’ ...
** libs
** arch - 
/usr/bin/clang++ -I/opt/local/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I"../inst/include/stansrc"   -I""  -I"/unsupported"  -I -I"../inst/include"  -DBOOST_RESULT_OF_USE_TR1 -DBOOST_NO_DECLTYPE -DBOOST_DISABLE_ASSERTS -I/opt/local/include -I"/Users/brown/Library/R/3.0/library/Rcpp/include"   -fPIC  -O3  -c stanc.cpp -o stanc.o
stanc.cpp:4:10: fatal error: ‘stan/version.hpp’ file not found
#include <stan/version.hpp>
         ^
1 error generated.
make[1]: *** [stanc.o] Error 1
ERROR: compilation failed for package ‘rstan’
* removing ‘/private/var/folders/hp/qxqj0lld5rv3sfcn9kk1d5fc0000gn/T/Rtmpfy7eUL/Rinst9b52e425aba/rstan’
      -----------------------------------
ERROR: package installation failed
make: *** [rstan_1.3.0.tar.gz] Error 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.