I’m using RStan and logistic
is the following S4 stanmodel class:
> logistic
S4 class stanmodel 'logistic' coded as follows:
data {
int<lower=0> i;
int<lower=0> j;
int<lower=0> y[i];
int<lower=0> n[i];
matrix[i, j] X;
cov_matrix[j] Sigma;
real mu_intercept; # Prior on intercept of regression parameters
}
transformed data {
vector[j] mu;
mu = rep_vector(0, j);
mu[1] = mu_intercept;
}
parameters {
vector[j] beta;
}
model {
beta ~ multi_normal(mu, Sigma);
y ~ binomial_logit(n, X * beta);
}
generated quantities {
real<lower=0,upper=1> yhat[j];
yhat[1] = inv_logit(beta[1]);
for (k in 2:j) {
yhat[k] = inv_logit(beta[1] + beta[k]);
}
}
data
is the following list:
> data
data
$i
[1] 3
$j
[1] 3
$y
[1] 10 11 12
$n
[1] 21 22 23
$X
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 1 1 0
[3,] 1 0 1
$mu_intercept
[1] 0
$Sigma
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 1 0
Notice in data
that y
is of length 3 as specified by i
.
I run the Stan model as follows and get the error:
> stan.fit <- rstan::sampling(logistic, data=data)
Error in new_CppObject_xp(fields$.module, fields$.pointer, ...) :
mismatch in dimension declared and found in context; processing stage=data initialization; variable name=y; position=0; dims declared=(7); dims found=(3)
failed to create the sampler; sampling not done
Why does Stan think that y
should be length 7?