trouble reading in data

144 views
Skip to first unread message

Christopher Kedzie

unread,
Feb 11, 2016, 3:51:13 PM2/11/16
to Stan users mailing list
Hi,

I'm new to stan, so apologies if I am missing something obvious here.

I am trying to fit a simple poisson regression. My model compiles but when I try to run I get the following error:

Exception: data x value  beyond int range
Diagnostic information: 
stan_2.9.0/src/stan/io/dump.hpp(522): Throw in function bool stan::io::dump_reader::next()
Dynamic exception type: boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::invalid_argument> >
std::exception::what: data x value  beyond int range

The model is:


data
{
   
int<lower=0> N;
   
int<lower=0> K;
    matrix
[N,K] x;
   
int<lower=0> y[N];
}

parameters
{
    vector
[K] theta;
    vector
[1] b;
}


transformed parameters  
{
    real lp
[N];
    real
<lower=0> mu[N];

   
for (i in 1:N) {
        lp
[i] <- x[i] * theta + b[1];
        mu
[i] <- exp(lp[i]);
   
}
}

model
{
    y
~ poisson(mu);
}


And my data file 'all.data.R' is:

N <- 15
K
<- 1
x
<- matrix(c(1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 1.0, 1.0, 3.0, 1.0, 4.0, 1.0, 2.0, 2.0, 1.0), nrow=15, ncol=1)
y
<- c(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0)

I am running this with CmdStan:

./model1 optimize data file=all.data.R

Any help would be greatly appreciated!

Thanks,
Chris

Daniel Lee

unread,
Feb 11, 2016, 3:58:37 PM2/11/16
to stan-users mailing list
Hi Chris,

The format used to read from the data file isn't quite native R. I believe technical details on what's allowed is in the CmdStan manual, but it's really not worth reading.

The quick fix is to change x to:
x <-
structure(c(1, 1, 1, 1, 1, 2, 1, 1, 3, 1, 4, 1, 2, 2, 1),
.Dim = c(15, 1))

If you're using R to export the data, I'd suggest using rstan's stan_rdump() function. It handles edge cases better than just using dump() in R.


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.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christopher Kedzie

unread,
Feb 11, 2016, 4:04:26 PM2/11/16
to Stan users mailing list
Thanks for the quick reply! That worked. 
Reply all
Reply to author
Forward
0 new messages