Hi. I am new to rstan and have some problem with the fitting of my model. I would appreciate if anyone have some input and some advice to help me. It was possible for me to run this code with the normal distribution but when I try to do it with student’s t-distribution I receive an error. I have the following code for my model:
write("// Stan model for simple linear regression
data {
int < lower = 1 > N; // Sample size
real<lower=0> nu; //Degrees of freedom
vector[N] x; // Predictor
vector[N] y; // Outcome
}
parameters {
real alpha; // Intercept
real beta; // Slope (regression coefficients)
real < lower = 0 > sigma; // Error SD
}
model {
y ~ student_t(nu, alpha + x * beta , sigma);
}
generated quantities {
} // The posterior predictive distribution",
"stan_model1.stan")
stanc("stan_model1.stan")
stan_model1 <- "stan_model1.stan"
fit <- stan(file = stan_model1, data = stan_data, warmup = 500, iter = 1000, chains = 4, cores = 2, thin = 1)
I receive the following error:
"Error in mod$fit_ptr() :
Exception: variable does not exist; processing stage=data initialization; variable name=nu; base type=double (in ‘modelcb6c70f3ed69_stan_model1’ at line 5)
failed to create the sampler; sampling not done".
Anyone knows what is wrong when I try to define my model? This is my first post here and I apologize if this is something that’s been discussed before, I couldn’t find any similar post.