Lets say I have the following lin_reg.stan
file.
data {
int<lower=0> N;
vector[N] x;
vector[N] y;
}
parameters {
real alpha;
real beta;
real<lower=0> sigma;
}
model {
y ~ normal(alpha + beta * x, sigma);
}
I know I can have a data.R
file that contains the following data
N <- 10
y <- c(3,3,4,5,4,7,8,7,7,8)
x <- c(1,2,1,2,1,3,3,4,3,4)
Using ./lin_reg sample data file=lin_reg.R
then view the results with stansummary output.csv
This runs fine with no problem, but this seems like a toy example. In fact, most of the data I would like to use in stan is tidy. In this format there is no N<-10
, just column names and their data for each observation. Is it possible to send a csv or dataframe in that is tidy to stan?
For example a tidy csv file would like like:
y x
7 3
8 3
7 4
8 3
7 4
8 3