What's wrong with my modeling?

Error in new_CppObject_xp(fields$.module, fields$.pointer, …) :
Exception: variable does not exist; processing stage=data initialization; variable name=N; base type=int (in ‘modelc854a6a58ef_bayesianweightedquantile’ at line 2)

here is my stan file:

  1 data {
  2   int N;
  3   real Y[N];
  4   real X1[N];
  5   real wt[N];
  6   real tau;
  7 }
  8 parameters {
  9   real a;
10   real b;
11 }
12 model {
13  int h[N];
14  real u[N];
15  real lambda[N];
16  a~normal(0,10);
17  b~normal(0,10);
18  for (i in 1:N){
19    h[i]=0;
20    u[i]=(Y[i]-a-b*X1[i]);
21    lambda[i]=wt[i]*(log(tau*(1-tau))+(fabs(u[i])+(2*tau-1)*u[i])/2)+10000;
22    h[i]~poisson(lambda[i]);
23  }
24 }

Hi!

The program is looking for data N, but is not finding it. You have to give Stan some integer N in your data list.

Cheers!

N is the number of sample
in my R.file, i have

quantile_dat <- list(N <- length(Y),tau,X1=X1,Y=Y,wt=wt)

This should be

quantile_dat <- list(N = length(Y), tau = tau, X1 = X1, Y = Y, wt = wt)
2 Likes

EDIT: I’m too slow! (The Stan forum is getting really fast/good at answering stuff… nice! :)

There are two things wrong with your R code: First, You can’t use <- in a list (N won’t be named otherwise). Second, tau must be named.

Try:

quantile_dat <- list(
  N = length(Y),
  tau = tau,
  X1 = X1,
  Y = Y,
  wt = wt
)
1 Like

The N is not contained in the data, because the following code.

> a<-list(x<-1,y=3)
> a$x
NULL
> a$y
[1] 3

I think it should be

quantile_dat <- list(N = length(Y),tau=tau,X1=X1,Y=Y,wt=wt)

2 Likes

that works, thanks a lot