Ответ Sandipan Karmakar говорит вам, что делать, это должно помочь вам на «как»:
> library(monomvn)
>
> ## following the lars diabetes example
> data(diabetes)
> str(diabetes)
'data.frame': 442 obs. of 3 variables:
$ x : AsIs [1:442, 1:10] 0.038075.... -0.00188.... 0.085298.... -0.08906.... 0.005383.... ...
..- attr(*, "dimnames")=List of 2
.. ..$ : NULL
.. ..$ : chr "age" "sex" "bmi" "map" ...
$ y : num 151 75 141 206 135 97 138 63 110 310 ...
[...]
> ## Bayesian Lasso regression
> reg_blas <- with(diabetes, blasso(x, y))
t=100, m=8
t=200, m=5
t=300, m=8
t=400, m=8
t=500, m=7
t=600, m=8
t=700, m=8
t=800, m=8
t=900, m=5
>
> ## posterior mean beta (setting those with >50% mass at zero to exactly zero)
> (beta <- colMeans(reg_blas$beta) * (colMeans(reg_blas$beta != 0) > 0.5))
b.1 b.2 b.3 b.4 b.5 b.6 b.7 b.8
0.0000 -195.9795 532.7136 309.1673 -101.1288 0.0000 -196.4315 0.0000
b.9 b.10
505.4726 0.0000
>
> ## n x nsims matrix of realizations from the posterior predictive:
> post_pred_y <- with(reg_blas, X %*% t(beta))
>
> ## predictions:
> y_pred <- rowMeans(post_pred_y)
> head(y_pred)
[1] 52.772443 -78.690610 24.234753 9.717777 -23.360369 -45.477199
>
> ## sd of y:
> sd_y <- apply(post_pred_y, 1, sd)
> head(sd_y)
[1] 6.331673 6.756569 6.031290 5.236101 5.657265 6.150473
>
> ## 90% credible intervals
> ci_y <- t(apply(post_pred_y, 1, quantile, probs=c(0.05, 0.95)))
> head(ci_y)
5% 95%
[1,] 42.842535 62.56743
[2,] -88.877760 -68.47159
[3,] 14.933617 33.85679
[4,] 1.297094 18.01523
[5,] -32.709132 -14.13260
[6,] -55.533807 -35.77809