I’m trying to adapt a complicated model from a continuous response variable to a binary one using logit and I’m having some trouble (I believe I’m missing something)
I’ve made a simple linear regression model to try things out with:
data {
int<lower=0> N; // number of data items
int<lower=0> K; // number of predictors
matrix[N, K] x; // predictor matrix
vector[N] y; // outcome vector
}
parameters {
real alpha; // intercept
vector[K] beta; // coefficients for predictors
real<lower=0> sigma; // error scale
}
model {
y ~ normal(x * beta + alpha, sigma); // likelihood
}
Ok this fits just fine no issues to toy data:
data(mtcars)
m <- 32
y <- sample(c(0,1), size = m, replace = TRUE)
dat <- list(N = m, y = y, K = 3, x = as.matrix(mtcars[, c("disp", "hp", "wt")]));
fit <- stan(file = "regression.stan",
data = dat, iter = 2012, chains = 4, cores = 4)
So I tried to edit this to a bernoulli_logit for the binary outcome:
data {
int<lower=0> N; // number of data items
int<lower=0> K; // number of predictors
matrix[N, K] x; // predictor matrix
int y[N]; // outcome vector
}
parameters {
real alpha; // intercept
vector[K] beta; // coefficients for predictors
real<lower=0> sigma; // error scale
vector[N] ystar;
}
model {
// likelihood
ystar ~ normal(x * beta + alpha, sigma);
y ~ bernoulli_logit(ystar);
}
I’m getting thousands of max tree depth warnings and pairs plots look like this:
I suspect I’m missing something with the model specificaiotn but I can’t think what. Can anyone help?
Thanks
Edit. I tried adding priors as follows:
//priors
alpha ~ std_normal();
beta ~std_normal();
sigma ~ inv_gamma(1,1);
which shows up some funnels, but I’m at a loss what to do about it: