I am using stan through rstan package in R. Below is my model. This model has an interaction term as X1 * X2
library(rstan)
library(bayesrules)
data(weather_WU); head(weather_WU, 20)
MCMC_Regression_Model =
"
data {
int<lower = 0> n;
vector[n] Y;
vector[n] X1;
vector[n] X2;
}
parameters {
real beta0;
real beta1;
real beta2;
real beta3;
real<lower = 0> sigma;
}
model {
Y ~ normal(beta0 + beta1 * X1 + beta2 * X2 +
beta3 * X1 .* X2, sigma);
beta0 ~ normal(25, 5);
beta1 ~ normal(0, 37.52);
beta2 ~ normal(0, 0.82);
beta3 ~ normal(0, 0.55);
sigma ~ exponential(0.13);
}
"
MCMC_Regression_SIMU =
stan(model_code = MCMC_Regression_Model,
data = list(n = nrow(weather_WU),
Y = weather_WU[['temp9am']],
X1 = weather_WU[['location']],
X2 = weather_WU[['humidity9am']]
),
chains = 4,
iter = 5000 * 2,
seed = 84735
)
With this, I get below error
Error in mod$fit_ptr() :
Exception: variable does not exist; processing stage=data
initialization; variable name=X1; base type=vector_d (in
'model1e9057045768_9ae288549657a6a89a994b0dc81a6d24' at
line 5)
This error says that variable does not exist but, variable is pretty much there in definition.
I will really appreciate if you could help me to correctly run above code.