rstan Install issues

590 views
Skip to first unread message

jvolpe...@gmail.com

unread,
Jan 12, 2017, 11:52:05 AM1/12/17
to Stan users mailing list
I'm having problems installing for the first time rstan. I'm using R 3.3.2 and followed the RStan Getting Started document. I'm getting the following errors when trying the example "rats"

> y <- read.table('rats.txt', header = TRUE)
> x <- c(8, 15, 22, 29, 36)
> xbar <- mean(x)
> N <- nrow(y)
> T <- ncol(y)
> rats_fit <- stan(file = 'rats.stan')
DIAGNOSTIC(S) FROM PARSER:
Warning (non-fatal): assignment operator <- deprecated in the Stan language; use = instead.
Warning (non-fatal): assignment operator <- deprecated in the Stan language; use = instead.
Warning (non-fatal): assignment operator <- deprecated in the Stan language; use = instead.
Warning (non-fatal): assignment operator <- deprecated in the Stan language; use = instead.

In file included from C:/Program Files/R/R-3.3.2/library/BH/include/boost/config.hpp:39:0,
                 from C:/Program Files/R/R-3.3.2/library/BH/include/boost/math/tools/config.hpp:13,
                 from C:/Program Files/R/R-3.3.2/library/StanHeaders/include/stan/math/rev/core/var.hpp:7,
                 from C:/Program Files/R/R-3.3.2/library/StanHeaders/include/stan/math/rev/core/gevv_vvv_vari.hpp:5,
                 from C:/Program Files/R/R-3.3.2/library/StanHeaders/include/stan/math/rev/core.hpp:12,
                 from C:/Program Files/R/R-3.3.2/library/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from C:/Program Files/R/R-3.3.2/library/StanHeaders/include/stan/math.hpp:4,
                 from C:/Program Files/R/R-3.3.2/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from file1570189b551b.cpp:8:
C:/Program Files/R/R-3.3.2/library/BH/include/boost/config/compiler/gcc.hpp:186:0: warning: "BOOST_NO_CXX11_RVALUE_REFERENCES" redefined
 #  define BOOST_NO_CXX11_RVALUE_REFERENCES
 ^
<command-line>:0:0: note: this is the location of the previous definition
cc1plus.exe: warning: unrecognized command line option "-Wno-ignored-attributes"
Error in tryCatch(evalq(getNamespace("Rcpp"), <environment>), error = function (x)  : 
  unused arguments (error = function (x) 
x, interrupt = function (x) 
x)
In addition: Warning messages:
1: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
2: In FUN(X[[i]], ...) : data with name y is not numeric and not used

Ben Goodrich

unread,
Jan 12, 2017, 12:43:17 PM1/12/17
to Stan users mailing list
On Thursday, January 12, 2017 at 11:52:05 AM UTC-5, jvolpe...@gmail.com wrote:
I'm having problems installing for the first time rstan. I'm using R 3.3.2 and followed the RStan Getting Started document. I'm getting the following errors when trying the example "rats"

It may work if you add an as.matrix() to
 
> y <- read.table('rats.txt', header = TRUE)

so that it is

y <- as.matrix(read.table('rats.txt', header = TRUE))

I have adjusted that line in the wiki. If not, then you have some sort of an installation problem.

Ben

Atul Ingle

unread,
Jan 12, 2017, 12:43:35 PM1/12/17
to Stan users mailing list
It works for me when replace all the "<-" with "=" in rats.rstan and typecast y to be a matrix
y = as.matrix(y)
before calling stan().



On Thursday, January 12, 2017 at 11:52:05 AM UTC-5, jvolpe...@gmail.com wrote:

Bob Carpenter

unread,
Jan 12, 2017, 2:31:13 PM1/12/17
to stan-...@googlegroups.com
We'll take a pass through all the models soon and clean this up.
The warning isn't fatal---you can still use <- instead of =, but
we'll eliminate <- at some point in the future.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

jvolpe...@gmail.com

unread,
Jan 12, 2017, 4:15:18 PM1/12/17
to stan-...@googlegroups.com
Same problem with the as.matrix added.
> y <- as.matrix(read.table('rats.txt', header = TRUE))
> x <- c(8, 15, 22, 29, 36)
> xbar <- mean(x)
> N <- nrow(y)
> T <- ncol(y)
> rats_fit <- stan(file = 'rats.stan')
DIAGNOSTIC(S) FROM PARSER:
Warning (non-fatal): assignment operator <- deprecated in the Stan language; use = instead.
Warning (non-fatal): assignment operator <- deprecated in the Stan language; use = instead.
Warning (non-fatal): assignment operator <- deprecated in the Stan language; use = instead.
Warning (non-fatal): assignment operator <- deprecated in the Stan language; use = instead.

In file included from C:/Program Files/R/R-3.3.2/library/BH/include/boost/config.hpp:39:0,
                 from C:/Program Files/R/R-3.3.2/library/BH/include/boost/math/tools/config.hpp:13,
                 from C:/Program Files/R/R-3.3.2/library/StanHeaders/include/stan/math/rev/core/var.hpp:7,
                 from C:/Program Files/R/R-3.3.2/library/StanHeaders/include/stan/math/rev/core/gevv_vvv_vari.hpp:5,
                 from C:/Program Files/R/R-3.3.2/library/StanHeaders/include/stan/math/rev/core.hpp:12,
                 from C:/Program Files/R/R-3.3.2/library/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from C:/Program Files/R/R-3.3.2/library/StanHeaders/include/stan/math.hpp:4,
                 from C:/Program Files/R/R-3.3.2/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from file101c444cad6.cpp:8:
C:/Program Files/R/R-3.3.2/library/BH/include/boost/config/compiler/gcc.hpp:186:0: warning: "BOOST_NO_CXX11_RVALUE_REFERENCES" redefined
 #  define BOOST_NO_CXX11_RVALUE_REFERENCES
 ^
<command-line>:0:0: note: this is the location of the previous definition
cc1plus.exe: warning: unrecognized command line option "-Wno-ignored-attributes"
Error in tryCatch(evalq(getNamespace("Rcpp"), <environment>), error = function (x)  : 
  unused arguments (error = function (x) 
x, interrupt = function (x) 
x)

Marina Golivets

unread,
Jan 29, 2017, 12:28:24 PM1/29/17
to Stan users mailing list
Hello,

I am getting a similar error when passing a list of matrices to Stan:

"is.na() applied to non-(list or vector) of type 'NULL'data with name V_d is not numeric and not usedError : variable does not exist; processing stage=data initialization; variable name=V_d; base type=matrix_d
failed to create the sampler; sampling not done"

The code had worked fine before I reinstalled rstan on my computer. I tried reinstalling rstan once again following all the instructions, but it didn't solve the issue. 

Also, I tried adding -Wno-macro-redefined to CXXFLAGS in .R/Makevars to suppress warnings (as suggested here: https://github.com/stan-dev/rstan/issues/372), but, again, it didn't work.

Marina




четвер, 12 січня 2017 р. 16:15:18 UTC-5 користувач jvolpe...@gmail.com написав:

Ben Goodrich

unread,
Jan 29, 2017, 1:01:42 PM1/29/17
to Stan users mailing list
On Sunday, January 29, 2017 at 12:28:24 PM UTC-5, Marina Golivets wrote:
I am getting a similar error when passing a list of matrices to Stan:

This has been fixed on GitHub: https://github.com/stan-dev/rstan/issues/384

Ben

Marina Golivets

unread,
Jan 29, 2017, 1:41:47 PM1/29/17
to Stan users mailing list
Thank you, Ben! I am not sure if I can apply it to my case, however, because I was passing a big list (>1000) of variance-covariance matrices. If I pass an array instead and declare it as real[ , , ], I don't see how I can redeclare it as an array of variance-covariance matrices. Here is the code I was using before:

data {
...
matrix[Kmax, Kmax] V_d[K]; // sampling variance-covariance matrices 
}
...
model {
int pos;
    pos = 1;
    for (i in 1:K) {
    segment(d, pos, L[i]) ~ multi_normal(segment(theta, pos, L[i]), block (V_d[i], 1, 1, L[i], L[i]));
    pos = pos + L[i];
    }
}

Thank you for any help,
Marina



неділя, 29 січня 2017 р. 13:01:42 UTC-5 користувач Ben Goodrich написав:

Ben Goodrich

unread,
Jan 29, 2017, 1:44:32 PM1/29/17
to Stan users mailing list
On Sunday, January 29, 2017 at 1:41:47 PM UTC-5, Marina Golivets wrote:
Thank you, Ben! I am not sure if I can apply it to my case, however, because I was passing a big list (>1000) of variance-covariance matrices. If I pass an array instead and declare it as real[ , , ], I don't see how I can redeclare it as an array of variance-covariance matrices. Here is the code I was using before:

You can pass an R array that is 1000 by 3 by 3 or whatever to the data block of a Stan program that has

cov_matrix[3] Sigma[1000];

Or you can install the fixed rstan from GitHub via devtools::install_github.

Ben

Marina Golivets

unread,
Jan 29, 2017, 2:00:37 PM1/29/17
to Stan users mailing list
I'm afraid that if I pass an R array and declare it as cov_matrix[3] Sigma[1000], the orders of dimensions will not match. It's gonna be [3, 3, 1000] vs [1000, 3, 3].
So I might reinstall the older version of rstan.
Thanks,
Marina

неділя, 29 січня 2017 р. 13:44:32 UTC-5 користувач Ben Goodrich написав:

Ben Goodrich

unread,
Jan 29, 2017, 2:27:49 PM1/29/17
to Stan users mailing list
On Sunday, January 29, 2017 at 2:00:37 PM UTC-5, Marina Golivets wrote:
I'm afraid that if I pass an R array and declare it as cov_matrix[3] Sigma[1000], the orders of dimensions will not match. It's gonna be [3, 3, 1000] vs [1000, 3, 3].

The dimensions of Sigma in Stan are 1000 x 3 x 3, just like in R. You don't read from left to right.
 
 So I might reinstall the older version of rstan.

Those versions have a broken NUTS algorithm.

Ben
 

Marina Golivets

unread,
Jan 29, 2017, 3:11:31 PM1/29/17
to stan-...@googlegroups.com
I might be completely missing something out, but for a three-dimensional R array the dimensions would be listed as [3, 3, 1000]. For example:

> a <- matrix(rep(1, 4), byrow=T, 2, 2)
> b <- matrix(rep(2, 4), byrow=T, 2, 2)
> c <- matrix(rep(3, 4),byrow=T, 2, 2)
> M <-  cbind(a, b, c)
> dim(M) <- c(3, 2, 2)
> M
, , 1

     [,1] [,2]
[1,]    1    1
[2,]    1    2
[3,]    1    2

, , 2

     [,1] [,2]
[1,]    2    3
[2,]    2    3
[3,]    3    3

> dim(M) <- c(2, 2, 3)
> M
, , 1

     [,1] [,2]
[1,]    1    1
[2,]    1    1

, , 2

     [,1] [,2]
[1,]    2    2
[2,]    2    2

, , 3

     [,1] [,2]
[1,]    3    3
[2,]    3    3

Best,
Marina

--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/PgT09wl3psQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+unsubscribe@googlegroups.com.

To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Best regards, 
Marina Golivets

Ben Goodrich

unread,
Jan 29, 2017, 6:01:13 PM1/29/17
to Stan users mailing list
On Sunday, January 29, 2017 at 3:11:31 PM UTC-5, Marina Golivets wrote:
I might be completely missing something out, but for a three-dimensional R array the dimensions would be listed as [3, 3, 1000]. For example:

> a <- matrix(rep(1, 4), byrow=T, 2, 2)
> b <- matrix(rep(2, 4), byrow=T, 2, 2)
> c <- matrix(rep(3, 4),byrow=T, 2, 2)
> M <-  cbind(a, b, c)
> dim(M) <- c(3, 2, 2)

Iff the data block of your Stan program included

matrix[2,2] M[3];

this M would be fine to pass from R.
 
> dim(M) <- c(2, 2, 3)

If your data block of the Stan program included

matrix[2,2] M[3];

this would yield an error because Stan is expecting M to be an R array that is 3x2x2.

Ben

Marina Golivets

unread,
Jan 29, 2017, 7:45:59 PM1/29/17
to Stan users mailing list
Thanks, Ben! I rearranged the data in the R array that I was passing to Stan and it worked just fine.
Marina

неділя, 29 січня 2017 р. 18:01:13 UTC-5 користувач Ben Goodrich написав:
Reply all
Reply to author
Forward
0 new messages