Fits a count-response regression model via glm(family = poisson()),
with optional stepwise selection.
Usage
reg_poisson(
formula,
data,
step = FALSE,
direction = c("both", "forward", "backward"),
...
)Value
A named list analogous to reg_lm(), plus:
- dispersion
Dispersion ratio (should be near 1).
- residuals
Data frame with observed, fitted, Pearson residual.
Examples
set.seed(42)
x1 = rnorm(100)
mu = exp(1 + 0.3*x1)
y = rpois(100, mu)
reg_poisson(y ~ x1, data = data.frame(y, x1))
#> $model
#>
#> Call: glm(formula = formula, family = poisson(), data = data)
#>
#> Coefficients:
#> (Intercept) x1
#> 0.8483 0.4226
#>
#> Degrees of Freedom: 99 Total (i.e. Null); 98 Residual
#> Null Deviance: 167.2
#> Residual Deviance: 123.8 AIC: 374.2
#>
#> $coefficient
#> # A tibble: 2 × 7
#> term estimate std.error statistic p.value conf.low conf.high
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 (Intercept) 0.848 0.0687 12.3 5.32e-35 0.712 0.985
#> 2 x1 0.423 0.0664 6.37 1.92e-10 0.291 0.554
#>
#> $dispersion
#> [1] 1.154
#>
#> $residuals
#> observed fitted_val pearson_residual
#> 1 7 4.1691059 1.38644347
#> 2 2 1.8398619 0.11805980
#> 3 5 2.7231554 1.37973977
#> 4 3 3.0519517 -0.02973797
#> 5 1 2.7709135 -1.06386340
#> 6 2 2.2333090 -0.15611950
#> 7 8 4.4242640 1.69998438
#> 8 2 2.2441564 -0.16298272
#> 9 3 5.4811848 -1.05979505
#> 10 2 2.2746579 -0.18211009
#> 11 4 4.0542770 -0.02695624
#> 12 6 6.1390630 -0.05612553
#> 13 1 1.2987449 -0.26214318
#> 14 0 2.0761521 -1.44088586
#> 15 2 2.2077876 -0.13984310
#> 16 5 3.0559369 1.11208550
#> 17 3 2.0713634 0.64523457
#> 18 1 0.7601125 0.27514953
#> 19 1 0.8327583 0.18326738
#> 20 7 4.0804790 1.44529343
#> 21 2 2.0518603 -0.03620437
#> 22 0 1.1002632 -1.04893430
#> 23 3 2.1720691 0.56176836
#> 24 8 3.9026502 2.07406910
#> 25 4 5.2030449 -0.52741569
#> 26 4 1.9472457 1.47104720
#> 27 2 2.0951190 -0.06571473
#> 28 0 1.1087327 -1.05296377
#> 29 1 2.8370662 -1.09066171
#> 30 1 1.7822383 -0.58594409
#> 31 2 2.8314998 -0.49414443
#> 32 2 3.1462080 -0.64620412
#> 33 3 3.6174482 -0.32463800
#> 34 0 1.8057926 -1.34379783
#> 35 9 2.8913613 3.59247088
#> 36 3 1.1305707 1.75816722
#> 37 0 1.6766861 -1.29486915
#> 38 4 1.6302576 1.85597886
#> 39 1 0.8420510 0.17212644
#> 40 2 2.3716791 -0.24134604
#> 41 1 2.5482020 -0.96986368
#> 42 3 2.0052113 0.70250722
#> 43 1 3.2179146 -1.23639593
#> 44 1 1.7181125 -0.54785632
#> 45 2 1.3100893 0.60275721
#> 46 3 2.8045475 0.11671049
#> 47 1 1.6577096 -0.51083418
#> 48 2 4.2999863 -1.10915366
#> 49 2 1.9464418 0.03838888
#> 50 6 3.0814812 1.66258069
#> 51 2 2.6761489 -0.41332073
#> 52 1 1.6771255 -0.52286119
#> 53 3 4.5459525 -0.72507628
#> 54 3 3.0649242 -0.03708485
#> 55 0 2.4260531 -1.55757924
#> 56 4 2.6253217 0.84841789
#> 57 1 3.1124216 -1.19737833
#> 58 3 2.4261271 0.36843332
#> 59 1 0.6593168 0.41956927
#> 60 3 2.6345823 0.22513019
#> 61 3 1.9999834 0.70712147
#> 62 1 2.5259353 -0.96011887
#> 63 2 2.9868287 -0.57100069
#> 64 8 4.2201192 1.83999119
#> 65 2 1.7176861 0.21540723
#> 66 2 4.0502920 -1.01876156
#> 67 5 2.6919412 1.40674076
#> 68 2 3.6226536 -0.85253537
#> 69 6 3.4467572 1.37526621
#> 70 6 3.1676082 1.59143020
#> 71 0 1.5030694 -1.22599729
#> 72 4 2.2484022 1.16814671
#> 73 3 3.0399234 -0.02289795
#> 74 1 1.5610715 -0.44906255
#> 75 4 1.8569448 1.57265649
#> 76 2 2.9857848 -0.57049633
#> 77 2 3.2315635 -0.68509448
#> 78 3 2.8414700 0.09404591
#> 79 2 1.6064110 0.31053794
#> 80 1 1.4675052 -0.38591944
#> 81 4 4.4264802 -0.20270739
#> 82 0 2.6047343 -1.61391892
#> 83 1 2.4246997 -0.91494366
#> 84 7 2.2194106 3.20894748
#> 85 1 1.4100254 -0.34530058
#> 86 2 3.0251583 -0.58940917
#> 87 2 2.1309526 -0.08970722
#> 88 0 2.1621422 -1.47042246
#> 89 3 3.4651854 -0.24989801
#> 90 0 3.3055905 -1.81812830
#> 91 6 4.2065505 0.87443209
#> 92 3 1.9099957 0.78870033
#> 93 2 3.0745879 -0.61284198
#> 94 3 4.2047627 -0.58753097
#> 95 1 1.4606943 -0.38118267
#> 96 0 1.6234615 -1.27415130
#> 97 3 1.4478192 1.28998640
#> 98 2 1.2606998 0.65843819
#> 99 1 2.4160487 -0.91101464
#> 100 0 3.0783008 -1.75450870
#>
#> $diagnostics
#> # A tibble: 3 × 2
#> metric value
#> <chr> <dbl>
#> 1 dispersion 1.15
#> 2 aic 374.
#> 3 bic 379.
#>
#> $model_info
#> # A tibble: 1 × 2
#> aic bic
#> <dbl> <dbl>
#> 1 374. 379.
#>
#> $formula
#> y ~ x1
#> <environment: 0x000002249ea1f888>
#>
#> $input
#> y x1
#> 1 7 1.37095845
#> 2 2 -0.56469817
#> 3 5 0.36312841
#> 4 3 0.63286260
#> 5 1 0.40426832
#> 6 2 -0.10612452
#> 7 8 1.51152200
#> 8 2 -0.09465904
#> 9 3 2.01842371
#> 10 2 -0.06271410
#> 11 4 1.30486965
#> 12 6 2.28664539
#> 13 1 -1.38886070
#> 14 0 -0.27878877
#> 15 2 -0.13332134
#> 16 5 0.63595040
#> 17 3 -0.28425292
#> 18 1 -2.65645542
#> 19 1 -2.44046693
#> 20 7 1.32011335
#> 21 2 -0.30663859
#> 22 0 -1.78130843
#> 23 3 -0.17191736
#> 24 8 1.21467470
#> 25 4 1.89519346
#> 26 4 -0.43046913
#> 27 2 -0.25726938
#> 28 0 -1.76316309
#> 29 1 0.46009735
#> 30 1 -0.63999488
#> 31 2 0.45545012
#> 32 2 0.70483734
#> 33 3 1.03510352
#> 34 0 -0.60892638
#> 35 9 0.50495512
#> 36 3 -1.71700868
#> 37 0 -0.78445901
#> 38 4 -0.85090759
#> 39 1 -2.41420765
#> 40 2 0.03612261
#> 41 1 0.20599860
#> 42 3 -0.36105730
#> 43 1 0.75816324
#> 44 1 -0.72670483
#> 45 2 -1.36828104
#> 46 3 0.43281803
#> 47 1 -0.81139318
#> 48 2 1.44410126
#> 49 2 -0.43144620
#> 50 6 0.65564788
#> 51 2 0.32192527
#> 52 1 -0.78383894
#> 53 3 1.57572752
#> 54 3 0.64289931
#> 55 0 0.08976065
#> 56 4 0.27655075
#> 57 1 0.67928882
#> 58 3 0.08983289
#> 59 1 -2.99309008
#> 60 3 0.28488295
#> 61 3 -0.36723464
#> 62 1 0.18523056
#> 63 2 0.58182373
#> 64 8 1.39973683
#> 65 2 -0.72729206
#> 66 2 1.30254263
#> 67 5 0.33584812
#> 68 2 1.03850610
#> 69 6 0.92072857
#> 70 6 0.72087816
#> 71 0 -1.04311894
#> 72 4 -0.09018639
#> 73 3 0.62351816
#> 74 1 -0.95352336
#> 75 4 -0.54282881
#> 76 2 0.58099650
#> 77 2 0.76817874
#> 78 3 0.46376759
#> 79 2 -0.88577630
#> 80 1 -1.09978090
#> 81 4 1.51270701
#> 82 0 0.25792144
#> 83 1 0.08844023
#> 84 7 -0.12089654
#> 85 1 -1.19432890
#> 86 2 0.61199690
#> 87 2 -0.21713985
#> 88 0 -0.18275671
#> 89 3 0.93334633
#> 90 0 0.82177311
#> 91 6 1.39211638
#> 92 3 -0.47617392
#> 93 2 0.65034856
#> 94 3 1.39111046
#> 95 1 -1.11078888
#> 96 0 -0.86079259
#> 97 3 -1.13173868
#> 98 2 -1.45921400
#> 99 1 0.07998255
#> 100 0 0.65320434
#>