Stan Errors

619 views
Skip to first unread message

Jo Lweny

unread,
Sep 8, 2015, 9:22:00 AM9/8/15
to Stan users mailing list
Hello Stan People,
Anyone kindly help out of this
I am trying to run a simple spatial model in rstan using the script attached.
Apparently I end up getting errors(which I don't understand) as shown below:





If so, you need to call increment_log_prob() with the log absolute determinant of the Jacobian of the transform.
Left-hand-side of sampling statement:
    rho_tr ~ gamma(...)


COMPILING THE C++ CODE FOR MODEL '2d2f9cabb7124e9b34547d4f6f8fe9fc' NOW.
cygwin warning:
  MS-DOS style path detected: C:/R/R-32~1.1/etc/x64/Makeconf
  Preferred POSIX equivalent is: /cygdrive/c/R/R-32~1.1/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
[20,1,4]
[10,1,4]
Error in eval(expr, envir, enclos) : Exception thrown at line 21:
[]: accessing element out of range. index 1 out of range; expecting index to be between 1 and 0; index position = 1x
failed to create the sampler; sampling not done




Session Info(IF NECESSARY)
> sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS release 6.7 (Final)

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

attached base packages:
 [1] parallel  tcltk     grid      splines   stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] stringr_1.0.0         geostatsp_1.3.5       SpatialExtremes_2.0-2 geoR_1.7-5.1          rstan_2.7.0-1         inline_0.3.14         Rcpp_0.11.1           RColorBrewer_1.1-2    foreign_0.8-63        raster_2.4-18        
[11] R.basic_0.53.0        abind_1.4-3           fields_8.2-1          maps_2.3-9            spam_1.0-1            epiR_0.9-62           survival_2.38-1       maptools_0.8-36       lattice_0.20-31       INLA_0.0-1392038736  
[21] Matrix_1.2-1          sp_1.0-14             R.utils_1.29.8        R.oo_1.19.0           R.methodsS3_1.7.0    

loaded via a namespace (and not attached):
 [1] magrittr_1.5             MASS_7.3-40              RandomFields_3.1.1       tools_3.2.1              RandomFieldsUtils_0.0.10 numDeriv_2014.2-1        codetools_0.2-11         splancs_2.01-37          stringi_0.5-5           
[10] stats4_3.2.1            

>

Pf_spatial_model.R

Daniel Lee

unread,
Sep 8, 2015, 9:31:32 AM9/8/15
to stan-users mailing list
Hi,

On Tue, Sep 8, 2015 at 9:22 AM, Jo Lweny <jolwe...@gmail.com> wrote:
Apparently I end up getting errors(which I don't understand) as shown below:
[20,1,4]
[10,1,4]
Error in eval(expr, envir, enclos) : Exception thrown at line 21:
[]: accessing element out of range. index 1 out of range; expecting index to be between 1 and 0; index position = 1x
failed to create the sampler; sampling not done



This is telling you that you have an error at line 21. It should be this line:
  for(i in 1:N_obs) x[i]<- x_obs[i];

It helps to put your Stan program into a separate file so you can easily track line numbers.

I'm guessing that x[i] and x_obs[i] are different sizes, but I don't know why it'd give you that message. I'll try to hunt it down what that message means.

Jan

unread,
Sep 8, 2015, 9:38:12 AM9/8/15
to Stan users mailing list

row_vector [D] x_obs[N_obs];
row_vector
[D] x[N];

Assigning one to the other would only work if their dimensions are the same, i.e. N==N_obs.

Daniel Lee

unread,
Sep 8, 2015, 9:38:52 AM9/8/15
to stan-users mailing list
Ah. It's making sense now. I don't know if there's a better way to form that error message.

Stan is an imperative language (it executes things in the order you write it).

If you look at the transformed data block:
transformed data{
  int<lower=1> N;
  row_vector[D] x[N];
  matrix [N,D] x_mat;
  vector[N] mu;
  N<- N_obs + N_pred;
  ...


you are trying to declare x as: row_vector[D] x[N]. Here, N is still 0. It only gets set to N_obs + N_pred after x is declared.

One way to fix it is to declare x as:
  row_vector[D] x[N_obs + N_pred];


With that fix, you'll run into problems for x_mat and mu, but I'll let you take care of that.



Daniel

Bob Carpenter

unread,
Sep 8, 2015, 3:14:06 PM9/8/15
to stan-...@googlegroups.com
Do we have a simple example to recreate this message? If so,
can someone create an issue to create a better formulated error
message?

I can't make heads or tails of the text of that message.

I don't like that "expecting index to be between 1 and 0" --- I
have no idea what it means and I may have written the error message.
And why is the position "1x" rather than "1"?

And why does it say "eval(expr, envir, enclos)" --- is that some
kind of carryover from R or something else?

- 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.
> For more options, visit https://groups.google.com/d/optout.

Ben Goodrich

unread,
Sep 8, 2015, 6:21:49 PM9/8/15
to Stan users mailing list
On Tuesday, September 8, 2015 at 3:14:06 PM UTC-4, Bob Carpenter wrote:
And why does it say "eval(expr, envir, enclos)"  --- is that some
kind of carryover from R or something else?

R

Ben

Reply all
Reply to author
Forward
0 new messages