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.98524220 0.33219474 2.9659 0.003018 **
#> lroll 0.00190934 0.00049004 3.8963 9.766e-05 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#>
#> logLik = AIC = 181.9228
# Bayesian approach:
bayes <- bellreg(nf ~ lroll, data = faults, approach = "bayes", refresh = FALSE)
summary(bayes)
#> Call:
#> bellreg(formula = nf ~ lroll, data = faults, approach = "bayes",
#> refresh = FALSE)
#>
#> Prior specifications:
#> intercept ~ normal(0, 10)
#> beta ~ normal(0, 2.5)
#>
#> Summary of the posterior distribution:
#> mean sd 2.5% 50% 97.5% n_eff Rhat
#> (Intercept) 0.9744 0.3287 0.325 0.9791 1.6076 2541.710 1.0004
#> lroll 0.0019 0.0005 0.001 0.0019 0.0028 3042.628 1.0002
#>
#> 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)
#>
#> Computed from 4000 by 32 log-likelihood matrix.
#>
#> Estimate SE
#> elpd_loo -91.0 4.0
#> p_loo 1.9 0.6
#> looic 182.0 7.9
#> ------
#> MCSE of elpd_loo is 0.0.
#> MCSE and ESS estimates assume independent draws (r_eff=1).
#>
#> All Pareto k estimates are good (k < 0.7).
#> 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 181.9 7.9
#>
#> 1 (3.1%) p_waic estimates greater than 0.4. We recommend trying loo instead.