Is there a way to pass a 0-length vector as data in RStan?

81 views
Skip to first unread message

Daniel Lee

unread,
Jul 18, 2015, 12:17:04 PM7/18/15
to stan-...@googlegroups.com
I'm thinking of something like...

data {
  int N;
  real y[N];
}
...


and I want to pass from R
data <- list()
data$N <- 0
data$y <- numeric(0)

or something else for data$y that can be passed rstan.



Ben Goodrich

unread,
Jul 18, 2015, 12:25:32 PM7/18/15
to stan-...@googlegroups.com, bea...@alum.mit.edu

That is known to work, but you might need 2.7.0.

Ben
 

Jonah

unread,
Jul 18, 2015, 12:26:31 PM7/18/15
to stan-...@googlegroups.com
numeric(0) should work actually. For instance this should run:

stancode <- "
 data {
   int N;
   real y[N];
}
 parameters {
   real x;
 }
 model{
   x ~ normal(0,1);
 }
"

fit <- stan(model_code = stancode, data = list(N = 0, y = numeric(0)), chains = 1, iter = 10)




On Saturday, July 18, 2015 at 12:17:04 PM UTC-4, Daniel Lee wrote:

Jonah

unread,
Jul 18, 2015, 12:31:32 PM7/18/15
to stan-...@googlegroups.com
y could also be logical(0) or integer(0) and it should work too. 

Daniel Lee

unread,
Jul 18, 2015, 12:32:48 PM7/18/15
to stan-...@googlegroups.com

Ok, I'll try it. I actually had a problem with an int array, but hopefully this works.

Daniel

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

Daniel Lee

unread,
Jul 18, 2015, 3:44:50 PM7/18/15
to stan-...@googlegroups.com
thanks!

Sebastian Weber

unread,
Jul 20, 2015, 4:12:20 AM7/20/15
to stan-...@googlegroups.com
Hi!

Does this work in cmdstan?

Best,
Sebastian

Bob Carpenter

unread,
Jul 20, 2015, 10:43:18 AM7/20/15
to stan-...@googlegroups.com
Yes --- you just need to supply a zero-length data vector, c().

- Bob
Reply all
Reply to author
Forward
0 new messages