Why is it that the following works
data{
int<lower=0> N;
int<lower=0> K;
matrix[N, K] X;
//vector[N] Y;
int<lower=0,upper=1> y[N];
}
parameters{
real alpha;
vector[K] beta;
}
model{
y ~ bernoulli_logit(alpha + X * beta);
}
but if I use
vector[N] Y;
instead of
int<lower=0,upper=1> y[N];
I get the error
No matches for:
vector ~ bernoulli_logit(vector)
the values int<lower=0,upper=1> y[N]
and vector[N] Y
seem similar to me. I am not sure why one works and the other does not.
For reproducibility here is some simulated data in R:
x1 <- rnorm(n, 0, 1)
x2 <- rnorm(n, 0, 1)
e <- rnorm(n, 0, .5^2)
a <- 1
b1 <- 2
b2 <- 3
u <- a + b1*x1 + b2*x2 + e #linear combination
pr <- 1/(1 + exp(-u)) # inverse of the logit function
y <- rbinom(n,1,pr)
x <- as.data.frame(list(x1=x1,x2=x2)) %>% as.matrix()
# logistic regression
fit.logistic <- stan(file = "logistic.stan",
data = list(N=length(y),X=x,Y=y,K=ncol(x)))