stan problem

99 views
Skip to first unread message

Andrew Gelman

unread,
Aug 27, 2012, 10:01:19 PM8/27/12
to stan...@googlegroups.com
J
I just followed the Getting Started instructions then tried the schools model but got the following error (see below).
A

P.S. Also in the Getting Started instructions we should add a couple lines telling people to do print(fit) and plot(fit) and look at the results.

---

COMPILING MODEL 'anon_model' FROM Stan CODE TO C++ CODE NOW.
Error in stanc(model.code, model.name) :
Failed to parse Stan model 'anon_model' and error message provided as:
LOCATION: file=input; line=3, column=8

int<lower=0> J; // number of schools
^-- here

DIAGNOSTIC(S) FROM PARSER:

Parser expecting: <identifier>

Jiqiang Guo

unread,
Aug 27, 2012, 10:04:01 PM8/27/12
to stan...@googlegroups.com
A:

I think you still have a previous version of rstan.  So you need to reinstall it as now the new syntax is used. 
I will add print(fit) and plot(fit) to the wiki soon. 

Jiqiang


--



Andrew Gelman

unread,
Aug 27, 2012, 10:08:40 PM8/27/12
to stan...@googlegroups.com
J
I did reinstall it.  That is, I followed the instructions on the page.  See below for a cut-and-paste of my R console.
A


> options(repos = c(getOption("repos"), rstan = "http://wiki.stan.googlecode.com/git/R"))
> install.packages('rstan', type = 'source')
Installing package(s) into ‘/Library/Frameworks/R.framework/Versions/2.15/Resources/library’
(as ‘lib’ is unspecified)
Content type 'application/x-gzip' length unknown
opened URL
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ......….
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
.......... .......... .......... .......... ..........
..
downloaded 2.3 Mb

* installing *source* package ‘rstan’ ...
** package ‘rstan’ successfully unpacked and MD5 sums checked
** libs
** arch - x86_64
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG -I"../inst/include/stansrc"   -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`"  -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`/unsupported"  -I"../inst/include/stanlib/boost_1.51.0"  -I"../inst/include"  -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -O3  -c stanc.cpp -o stanc.o
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG -I"../inst/include/stansrc"   -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`"  -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`/unsupported"  -I"../inst/include/stanlib/boost_1.51.0"  -I"../inst/include"  -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -O3  -c gm__grammars__whitespace_grammar_inst.cpp -o gm__grammars__whitespace_grammar_inst.o
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG -I"../inst/include/stansrc"   -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`"  -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`/unsupported"  -I"../inst/include/stanlib/boost_1.51.0"  -I"../inst/include"  -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -O3  -c gm__grammars__program_grammar_inst.cpp -o gm__grammars__program_grammar_inst.o
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG -I"../inst/include/stansrc"   -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`"  -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`/unsupported"  -I"../inst/include/stanlib/boost_1.51.0"  -I"../inst/include"  -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -O3  -c gm__grammars__statement_grammar_inst.cpp -o gm__grammars__statement_grammar_inst.o
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG -I"../inst/include/stansrc"   -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`"  -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`/unsupported"  -I"../inst/include/stanlib/boost_1.51.0"  -I"../inst/include"  -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -O3  -c gm__ast_def.cpp -o gm__ast_def.o
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG -I"../inst/include/stansrc"   -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`"  -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`/unsupported"  -I"../inst/include/stanlib/boost_1.51.0"  -I"../inst/include"  -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -O3  -c gm__grammars__var_deccls_grammar_inst.cpp -o gm__grammars__var_deccls_grammar_inst.o
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG -I"../inst/include/stansrc"   -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`"  -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`/unsupported"  -I"../inst/include/stanlib/boost_1.51.0"  -I"../inst/include"  -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -O3  -c gm__grammars__expression_grammar_inst.cpp -o gm__grammars__expression_grammar_inst.o
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG -I"../inst/include/stansrc"   -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`"  -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`/unsupported"  -I"../inst/include/stanlib/boost_1.51.0"  -I"../inst/include"  -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -O3  -c chains.cpp -o chains.o
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG -I"../inst/include/stansrc"   -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`"  -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`/unsupported"  -I"../inst/include/stanlib/boost_1.51.0"  -I"../inst/include"  -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -O3  -c misc.cpp -o misc.o
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG -I"../inst/include/stansrc"   -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`"  -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`/unsupported"  -I"../inst/include/stanlib/boost_1.51.0"  -I"../inst/include"  -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -O3  -c agrad__agrad.cpp -o agrad__agrad.o
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG -I"../inst/include/stansrc"   -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`"  -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`/unsupported"  -I"../inst/include/stanlib/boost_1.51.0"  -I"../inst/include"  -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -O3  -c agrad__matrix.cpp -o agrad__matrix.o
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG -I"../inst/include/stansrc"   -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`"  -I"`/Library/Frameworks/R.framework/Resources/bin/Rscript -e "cat(system.file('include', package = 'RcppEigen'))"`/unsupported"  -I"../inst/include/stanlib/boost_1.51.0"  -I"../inst/include"  -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -O3  -c math__matrix.cpp -o math__matrix.o
ar qc libstan.a agrad__agrad.o agrad__matrix.o math__matrix.o 
cp libstan.a ../inst/libstan/x86_64
rm libstan.a 
g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o rstan.so stanc.o gm__grammars__whitespace_grammar_inst.o gm__grammars__program_grammar_inst.o gm__grammars__statement_grammar_inst.o gm__ast_def.o gm__grammars__var_deccls_grammar_inst.o gm__grammars__expression_grammar_inst.o chains.o misc.o /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/lib/x86_64/libRcpp.a -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/2.15/Resources/library/rstan/libs/x86_64
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
   ‘rstan.Rnw’ 
** testing if installed package can be loaded

* DONE (rstan)

The downloaded source packages are in
‘/private/var/folders/t1/2vc2f6t52w19hx_m166scfkc0000gn/T/RtmpYhFYeP/downloaded_packages’
> library(rstan) 
Loading required package: Rcpp
Loading required package: inline
Loading required package: RcppEigen
rstan (Version 1.0, packaged: 2012-08-26 01:49:30 UTC; jq2)
rstan  Copyright (C) 2012 Columbia University
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under the General Public License version 3 or later.

Attaching package: ‘rstan’

The following object(s) are masked from ‘package:arm’:

    traceplot

The following object(s) are masked from ‘package:coda’:

    traceplot

> 

--
 
 

Andrew Gelman

unread,
Aug 27, 2012, 10:12:23 PM8/27/12
to stan...@googlegroups.com
J

I closed and reopened R and now it works.

So maybe this needs to be in the instructions.  After installing the package, close R and then reopen it.

Also, print() needs to be fixed:  the headers should be "mean", "se_mean", "sd", …, "n_eff", …
And in the note at the bottom of the print() output, "ESS" should be changed to "n_eff" and "samples" should be changed to "sample".

A

Jiqiang Guo

unread,
Aug 27, 2012, 10:17:42 PM8/27/12
to stan...@googlegroups.com
On Mon, Aug 27, 2012 at 10:12 PM, Andrew Gelman <gel...@stat.columbia.edu> wrote:
J

I closed and reopened R and now it works.

So maybe this needs to be in the instructions.  After installing the package, close R and then reopen it.
this is just temporary.  And I guess you have saved your workspace.  So for now, you might need to delete what you have saved. 
 

Also, print() needs to be fixed:  the headers should be "mean", "se_mean", "sd", …, "n_eff", …
And in the note at the bottom of the print() output, "ESS" should be changed to "n_eff" and "samples" should be changed to "sample".
Those have been fixed.  But the package on the web is not updated yet. I plan to get the dots changed and then upload.  

A

Jiqiang Guo

unread,
Aug 27, 2012, 11:13:54 PM8/27/12
to stan...@googlegroups.com
A:

By the way, what do you want for the log-posterior you mentioned earlier.  Now I have means of them for all chains, see the following (again, not uploaded)

> print(fit)
Inference for Stan model: anon_model.
4 chains: each with n.iter=1000; n.warmup=500; n.thin=1; 1000 samples saved.

         mean se_mean  sd 2.5% 25% 50%  75% 97.5% n_eff Rhat
theta[1] 10.8     0.8 6.9  0.3 6.9 9.8 13.3  28.0    66  1.1
theta[2]  8.2     0.3 5.3 -3.3 5.5 8.5 10.8  19.2   324  1.0
theta[3]  7.2     0.5 6.8 -9.4 4.7 7.8 10.6  18.8   202  1.0
theta[4]  8.0     0.4 5.5 -4.3 5.1 8.1 11.4  19.7   217  1.0
theta[5]  6.2     0.9 5.7 -7.8 2.6 7.4  9.8  15.3    37  1.1
theta[6]  7.0     0.4 5.9 -6.8 4.1 7.7 10.5  18.7   193  1.0
theta[7] 10.1     0.5 5.9  0.3 6.2 9.6 12.8  24.2   140  1.1
theta[8]  8.5     0.4 6.8 -5.6 4.7 8.8 11.4  22.2   270  1.0
mu        8.3     0.4 4.2 -0.7 5.6 8.6 10.7  16.5   108  1.0
tau       5.1     1.7 5.2  0.5 1.4 3.1  7.5  18.0     9  1.2

Log-posterior (mean of each chain): -14.9, -19.1, -5.1, -17.1.
Sample were drawn using NUTS2 at Mon Aug 27 23:11:22 2012.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at 
convergence, Rhat=1).

--
J

Andrew Gelman

unread,
Aug 28, 2012, 10:41:13 PM8/28/12
to stan...@googlegroups.com
J

The easiest thing is to simply include log_post as one more variable to save, just throw it on the bottom of the list of variables.  The only issue is that with big models, the log posterior will be a big number in absolute value (e.g., it might be something like -24000) which will make the table look ugly.  Log_post per observation would be fine except that in general we can't really define the number of "observations."  Also it's not really the log posterior, it's really the log joint density, or maybe not even that, given that there are so many different ways to write the model.

But for now let's just go with log_post as an extra row in the table and an extra element in the plot, just the way we did deviance in r2winbugs.  Then later we can think harder about best way of doing this.

A

--
 
 

Jiqiang Guo

unread,
Aug 29, 2012, 2:29:27 AM8/29/12
to stan...@googlegroups.com
Ok, I will do this. Thanks.
Reply all
Reply to author
Forward
0 new messages