Skip to contents
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.95125  0.84424 -2.3113 0.020819 * 
#> smoker       2.17553  0.82248  2.6451 0.008167 **
#> gender      -0.49601  0.42059 -1.1793 0.238275   
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> 
#> Count regression coefficients:
#>              Estimate    StdErr z.value   p.value    
#> (Intercept)  0.716784  0.179844  3.9856 6.731e-05 ***
#> smoker      -0.611842  0.183398 -3.3361 0.0008495 ***
#> gender       0.036218  0.177484  0.2041 0.8383045    
#> ---
#> 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.932 -1.343 -1.119 -0.93 -0.622 1966.336
#>             Rhat
#> (Intercept)    1
#> 
#> Count regression coefficients:
#>               mean se_mean    sd   2.5%    25%    50%    75%  97.5%    n_eff
#> (Intercept)  0.714   0.003 0.145  0.425  0.616  0.716  0.812  1.000 2965.117
#> smoker      -1.070   0.003 0.145 -1.354 -1.164 -1.071 -0.972 -0.789 2519.677
#> gender       0.176   0.002 0.135 -0.092  0.086  0.177  0.267  0.443 3091.451
#>             Rhat
#> (Intercept)    1
#> smoker         1
#> gender         1
#> --- 
#> 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  -1036.1  50.8
#> p_loo       191.8  18.1
#> looic      2072.3 101.6
#> ------
#> 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)     418   81.8%   2769    
#>    (0.7, 1]   (bad)       75   14.7%   <NA>    
#>    (1, Inf)   (very bad)  18    3.5%   <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   -998.0 47.5
#> p_waic       153.7 14.2
#> waic        1996.1 95.1
#> 
#> 93 (18.2%) p_waic estimates greater than 0.4. We recommend trying loo instead.