# 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.95188  0.84474 -2.3106 0.020854 *
    #> smoker       2.17611  0.82296  2.6442 0.008188 **
    #> gender      -0.49585  0.42060 -1.1789 0.238431
    #> ---
    #> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    #>
    #>
    #> Count regression coefficients:
    #>              Estimate    StdErr z.value   p.value
    #> (Intercept)  0.716720  0.179855  3.9850 6.748e-05 ***
    #> smoker      -0.611764  0.183405 -3.3356 0.0008512 ***
    #> gender       0.036213  0.177482  0.2040 0.8383240
    #> ---
    #> 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.163   0.008 0.341 -1.961 -1.338 -1.121 -0.936 -0.619 1624.737
    #>              Rhat
    #> (Intercept) 1.002
    #>
    #> Count regression coefficients:
    #>               mean se_mean    sd   2.5%    25%    50%    75%  97.5%    n_eff
    #> (Intercept)  0.720   0.003 0.145  0.441  0.622  0.719  0.818  1.005 2909.966
    #> smoker      -1.075   0.003 0.145 -1.361 -1.173 -1.075 -0.979 -0.787 2404.475
    #> gender       0.170   0.003 0.139 -0.107  0.080  0.169  0.263  0.448 2792.616
    #>              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: 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 511 log-likelihood matrix
    #>
    #>          Estimate   SE
    #> elpd_loo   -626.8 24.8
    #> p_loo         4.5  0.4
    #> looic      1253.5 49.5
    #> ------
    #> 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)
    #>
    #> Computed from 4000 by 511 log-likelihood matrix
    #>
    #>           Estimate   SE
    #> elpd_waic   -626.8 24.8
    #> p_waic         4.5  0.4
    #> waic        1253.5 49.5