I would like to run a robust logistic regression (robit) in Stan. The model is suggested in Gelman & Hill's "Data Analysis Using Regression and Multilevel Methods" (2006, pp. 124), but I'm not sure how to implement it. I checked Stan's Github repository and the reference manual, but unfortunately I'm still confused. Here's some code I've used to model a regular logistic regression. What should I add to it so that the errors follow, say, a t distribution with 7 degrees of freedom? By any chance, would it be the same procedure if I run a multilevel analysis?
library(rstan)
set.seed(1)
x1 <- rnorm(100)
x2 <- rnorm(100)
z <- 1 + 2*x1 + 3*x2
pr <- 1/(1+exp(-z))
y <- rbinom(100,1,pr)
df <- list(N=100, y=y,x1=x1,x2=x2)
# Stan code
model1 <- '
data {
int<lower=0> N;
int<lower=0,upper=1> y[N];
vector[N] x1;
vector[N] x2;
}
parameters {
real beta_0;
real beta_1;
real beta_2;
}
model {
y ~ bernoulli_logit(beta_0 + beta_1 * x1 + beta_2 * x2);
}
'
# Run the model
fit <- stan(model_code = model1, data = df, iter = 1000, chains = 4)
print(fit)
Thank you!
df = data.list(N=100, y=y,x1=x1,x2=x2)
. There is nodata.list()
in R; it should read:df = list(N=100, y=y,x1=x1,x2=x2)
. – Amontillado