# NOT RUN {
# Package rstan needs to be installed for running this example.
# }
# NOT RUN {
if (requireNamespace("rstan", quietly = TRUE)) {
n = 2000
p = 4
set.seed(34)
x1 = rnorm(n, 10, 2)
x2 = rnorm(n, 5, 3)
x3 = rnorm(n, -2, 1)
x4 = rnorm(n, 0, 5)
y = 2.4 - 0.6 * x1 + 5.5 * x2 - 7.2 * x3 + 5.7 * x4 + rnorm(n)
data = data.frame(x1, x2, x3, x4, y)
normalmodell = '
data {
int<lower=0> n;
int<lower=0> d;
matrix[n,d] X; // predictor matrix
vector[n] y; // outcome vector
}
parameters {
real alpha; // intercept
vector[d] beta; // coefficients for predictors
real<lower=0> sigma; // error scale
}
model {
y ~ normal(alpha + X * beta, sigma); // likelihood
}
'
datas = list(n = nrow(data), d = ncol(data)-1,
y = data[, dim(data)[2]], X = data[, 1:(dim(data)[2]-1)])
fit0 = rstan::stan(model_code = normalmodell, data = datas, chains = 4, iter = 1000)
fit1 = mrbayes(dataMr = data, obsPerBlock = 500, y = 'y')
}
# }
Run the code above in your browser using DataLab