# Zero-inflated Bell model

    library(bellreg)

    data(cells)

    # ML approach:
    mle <- zibellreg(cells ~ smoker+gender|smoker+gender, data = cells, approach = "mle")
    summary(mle)
    #> Call:
    #> zibellreg(formula = cells ~ smoker + gender | smoker + gender,
    #>     data = cells, approach = "mle")
    #>
    #> Zero-inflated regression coefficients:
    #>             Estimate   StdErr z.value  p.value
    #> (Intercept) -1.95230  0.84509 -2.3102 0.020878 *
    #> smoker       2.17646  0.82330  2.6436 0.008203 **
    #> gender      -0.49579  0.42061 -1.1787 0.238503
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #>
    #> Count regression coefficients:
    #>              Estimate    StdErr z.value   p.value
    #> (Intercept)  0.716551  0.179860  3.9839 6.778e-05 ***
    #> smoker      -0.611777  0.183409 -3.3356 0.0008512 ***
    #> gender       0.036389  0.177480  0.2050 0.8375493
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #> ---
    #> logLik = -610.3234   AIC = 1232.647

    # Bayesian approach:
    bayes <- zibellreg(cells ~ 1|smoker+gender, data = cells, approach = "bayes", refresh = FALSE)
    summary(bayes)
    #> Call:
    #> zibellreg(formula = cells ~ 1 | smoker + gender, data = cells,
    #>     approach = "bayes", refresh = FALSE)
    #>
    #> Zero-inflated regression coefficients:
    #>               mean se_mean   sd   2.5%    25%    50%    75%  97.5%    n_eff
    #> (Intercept) -1.149   0.006 0.31 -1.848 -1.333 -1.119 -0.936 -0.634 2610.283
    #>              Rhat
    #> (Intercept) 1.001
    #>
    #> Count regression coefficients:
    #>               mean se_mean    sd   2.5%    25%    50%    75%  97.5%    n_eff
    #> (Intercept)  0.714   0.003 0.146  0.427  0.615  0.716  0.814  1.000 3029.991
    #> smoker      -1.066   0.003 0.145 -1.349 -1.163 -1.068 -0.971 -0.780 2303.155
    #> gender       0.175   0.003 0.142 -0.100  0.078  0.176  0.272  0.457 2922.114
    #>              Rhat
    #> (Intercept) 1.000
    #> smoker      1.001
    #> gender      1.000
    #> ---
    #> Inference for Stan model: zibellreg.
    #> 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: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details.
    #>
    #> Computed from 4000 by 511 log-likelihood matrix.
    #>
    #>          Estimate    SE
    #> elpd_loo  -1032.6  50.5
    #> p_loo       189.0  18.5
    #> looic      2065.2 101.0
    #> ------
    #> MCSE of elpd_loo is NA.
    #> MCSE and ESS estimates assume independent draws (r_eff=1).
    #>
    #> Pareto k diagnostic values:
    #>                          Count Pct.    Min. ESS
    #> (-Inf, 0.7]   (good)     419   82.0%   511
    #>    (0.7, 1]   (bad)       70   13.7%   <NA>
    #>    (1, Inf)   (very bad)  22    4.3%   <NA>
    #> See help('pareto-k-diagnostic') for details.
    loo::waic(log_lik)
    #> Warning:
    #> 93 (18.2%) p_waic estimates greater than 0.4. We recommend trying loo instead.
    #>
    #> Computed from 4000 by 511 log-likelihood matrix.
    #>
    #>           Estimate   SE
    #> elpd_waic   -994.0 47.2
    #> p_waic       150.4 14.0
    #> waic        1987.9 94.3
    #>
    #> 93 (18.2%) p_waic estimates greater than 0.4. We recommend trying loo instead.