Reputation: 41
I am on Apple M2 Pro Ventura 13.3, R version 4.3.1 and RStudio 2023.12.2+402. When inserting Stan chunks into a Markdown file, RStudio is simply not recognizing the Stan code. There is no run button in the top right corner of the chunk either.
I tried to store my model as text within an r chunk, like:
stock <- '
data{
int<lower = 1> n;
vector[n] temp;
vector[n] unit;
}
parameters{
real beta0 ;
real beta1 ;
real sigma ;
}
model{
beta0 ~ uniform(-600,600);
sigma ~ normal(0,1000);
beta1 ~ normal(0,1000);
for (i in 1:n){
unit[i] ~ normal(beta0 + temp[i] * beta1, sigma) ;
}
}
generated quantities{
real units_pred ;
units_pred = normal_rng(beta0 + 30 * beta1, sigma) ;
}
'
Then trying to fit the model :
model3 <- rstan::stan_model(model_code = stock)
fit3 <- sampling(model3
, data=data_ice
, iter=n_iter
, chains=4
)
summary(fit3)
But I am unable to store the model as text object. I am not able to read in the model from an Rstan File either. (tried it via writeLines(readLines("test.stan")) where test.stan stores the model.
This seems really odd, since I am able to run Stan in a regular R script, but not in RMarkdown. It seems there is something with RStudio, but I can't figure what's wrong.
Anyone has an idea please what the reason could be?
Upvotes: 1
Views: 39