Skip to contents
library(bellreg)

data(faults)

# ML approach:
mle <- bellreg(nf ~ lroll, data = faults, approach = "mle")
summary(mle)
#> Call:
#> bellreg(formula = nf ~ lroll, data = faults, approach = "mle")
#> 
#> Coefficients:
#>               Estimate     StdErr z.value   p.value    
#> (Intercept) 0.98525430 0.33219440  2.9659  0.003018 ** 
#> lroll       0.00190932 0.00049003  3.8963 9.767e-05 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> logLik = -88.96139   AIC = 181.9228

# Bayesian approach:
bayes <- bellreg(nf ~ lroll, data = faults, approach = "bayes", refresh = FALSE)
summary(bayes)
#> 
#> bellreg(formula = nf ~ lroll, data = faults, approach = "bayes", 
#>     refresh = FALSE)
#> 
#>              mean se_mean    sd  2.5%   25%   50%   75% 97.5%    n_eff Rhat
#> (Intercept) 0.987   0.007 0.326 0.348 0.766 0.987 1.209 1.614 2297.096    1
#> lroll       0.002   0.000 0.000 0.001 0.002 0.002 0.002 0.003 2754.420    1
#> 
#> Inference for Stan model: bellreg.
#> 4 chains, each with iter=2000; warmup=1000; thin=1; 
#> post-warmup draws per chain=1000, total post-warmup draws=4000.

log_lik <- loo::extract_log_lik(bayes$fit)
loo::loo(log_lik)
#> Warning: Relative effective sample sizes ('r_eff' argument) not specified.
#> For models fit with MCMC, the reported PSIS effective sample sizes and 
#> MCSE estimates will be over-optimistic.
#> 
#> Computed from 4000 by 32 log-likelihood matrix
#> 
#>          Estimate  SE
#> elpd_loo    -91.0 3.9
#> p_loo         1.9 0.6
#> looic       182.0 7.9
#> ------
#> Monte Carlo SE of elpd_loo is 0.0.
#> 
#> All Pareto k estimates are good (k < 0.5).
#> See help('pareto-k-diagnostic') for details.
loo::waic(log_lik)
#> Warning: 
#> 1 (3.1%) p_waic estimates greater than 0.4. We recommend trying loo instead.
#> 
#> Computed from 4000 by 32 log-likelihood matrix
#> 
#>           Estimate  SE
#> elpd_waic    -91.0 3.9
#> p_waic         1.9 0.6
#> waic         182.0 7.9
#> 
#> 1 (3.1%) p_waic estimates greater than 0.4. We recommend trying loo instead.