Small helper function that computes the 2.5% and 97.5% quantiles and the mean of a vector. Useful for example when using function predict.bamlss.

c95(x)

Arguments

x

A numeric vector.

Examples

x <- rnorm(100)
c95(x)
#>        2.5%        Mean       97.5% 
#> -2.03558585 -0.08520532  1.96359896 

if (FALSE) ## Example computing predictions.
set.seed(123)
d <- data.frame("x" = seq(-3, 3, length = 30))
d$y <- sin(d$x) + rnorm(30, sd = 0.3)

## Estimate model and compute predictions.
## with c95().
b <- bamlss(y ~ s(x), data = d)
#> AICc  32.4494 logPost -45.4219 logLik  -9.3006 edf 5.4381 eps 0.5421 iteration   1
#> AICc  20.6556 logPost -37.4143 logLik  -3.1010 edf 5.6297 eps 0.1766 iteration   2
#> AICc  15.6084 logPost -34.5604 logLik   0.1807 edf 6.0962 eps 0.1383 iteration   3
#> AICc  14.6331 logPost -34.0098 logLik   1.2677 edf 6.4519 eps 0.0783 iteration   4
#> AICc  14.5393 logPost -33.9662 logLik   1.6215 edf 6.6299 eps 0.0344 iteration   5
#> AICc  14.5353 logPost -33.9652 logLik   1.7003 edf 6.6740 eps 0.0081 iteration   6
#> AICc  14.5352 logPost -33.9653 logLik   1.7114 edf 6.6803 eps 0.0011 iteration   7
#> AICc  14.5352 logPost -33.9653 logLik   1.7127 edf 6.6810 eps 0.0001 iteration   8
#> AICc  14.5352 logPost -33.9653 logLik   1.7129 edf 6.6811 eps 0.0000 iteration   9
#> AICc  14.5352 logPost -33.9653 logLik   1.7129 edf 6.6811 eps 0.0000 iteration   9
#> elapsed time:  0.12sec
#> Starting the sampler...
#> 
#> |                    |   0%  2.02sec
#> |*                   |   5%  1.99sec  0.10sec
#> |**                  |  10%  1.84sec  0.20sec
#> |***                 |  15%  1.76sec  0.31sec
#> |****                |  20%  1.66sec  0.41sec
#> |*****               |  25%  1.59sec  0.53sec
#> |******              |  30%  1.48sec  0.63sec
#> |*******             |  35%  1.38sec  0.74sec
#> |********            |  40%  1.28sec  0.85sec
#> |*********           |  45%  1.18sec  0.96sec
#> |**********          |  50%  1.08sec  1.08sec
#> |***********         |  55%  0.97sec  1.18sec
#> |************        |  60%  0.86sec  1.29sec
#> |*************       |  65%  0.75sec  1.40sec
#> |**************      |  70%  0.65sec  1.51sec
#> |***************     |  75%  0.54sec  1.62sec
#> |****************    |  80%  0.43sec  1.73sec
#> |*****************   |  85%  0.33sec  1.84sec
#> |******************  |  90%  0.22sec  2.00sec
#> |******************* |  95%  0.11sec  2.12sec
#> |********************| 100%  0.00sec  2.28sec
p <- predict(b, model = "mu", FUN = c95)
plot(d)
matplot(d$x, p, type = "l", lty = c(2, 1, 2),
  col = "black", add = TRUE)


## Example extracting coefficients.
coef(b, FUN = c95)
#>                           2.5%        Mean       97.5%
#> mu.s.s(x).b1        -2.7128249 -2.07000703 -1.44983517
#> mu.s.s(x).b2        -1.4800066  0.31732825  2.23923359
#> mu.s.s(x).b3        -0.6976676 -0.17336785  0.35867711
#> mu.s.s(x).b4        -1.2198943  0.15481990  1.54778071
#> mu.s.s(x).b5        -0.4754548  0.05119379  0.52651786
#> mu.s.s(x).b6        -1.5442848 -0.17577973  1.04634256
#> mu.s.s(x).b7        -0.6296562 -0.05705302  0.40215896
#> mu.s.s(x).b8        -2.9576602 -0.04595215  2.79233488
#> mu.s.s(x).b9        -2.5895736 -1.51987111 -0.34548875
#> mu.s.s(x).tau21      2.8397411 13.59739370 48.98173816
#> mu.s.s(x).alpha      1.0000000  1.00000000  1.00000000
#> mu.p.(Intercept)    -0.1202318 -0.01986826  0.06927125
#> mu.p.alpha           1.0000000  1.00000000  1.00000000
#> sigma.p.(Intercept) -1.6712943 -1.39173221 -1.09268439
#> sigma.p.alpha        0.5042547  0.93969229  1.00000000