I'm using mepoisson to model county-level cancer diagnoses using county population as the exposure and county as the grouping variable. I'd like to use margins to explore the results but I want to make sure I understand what it is doing first. As I understand it, after mepoisson, margins give the average expected count accounting for the exposure. So the result for margins should be equal to the average result for predict. I'm finding that this is not true if I include the grouping variable in the model. Why is that?

I've included examples below with and without the grouping variable. In the example with the grouping variable the average result for predict (0.68) equals the result for margins; however, when county is added as a grouping variable in the second example, the result for predict is 0.67 but the result for margins equals 2.37.

Thanks for your help!

Example with no grouping variable:

. mepoisson count i.sex i.agedx19 i.raceV3 smkstd, exposure( population ) nolog
> irr

Poisson regression Number of obs = 23,751

Wald chi2(8) = 9626.52
Log likelihood = -21260.323 Prob > chi2 = 0.0000
-------------------------------------------------------------------------------
count | IRR Std. Err. z P>|z| [95% Conf. Interval]
--------------+----------------------------------------------------------------
sex |
Female | 4.157373 .0905313 65.43 0.000 3.983668 4.338652
|
agedx19 |
20-24 years | 1.336104 .0542031 7.14 0.000 1.233981 1.446677
25-29 years | 1.719949 .0653374 14.28 0.000 1.596541 1.852895
30-34 years | 2.164966 .0792471 21.10 0.000 2.015086 2.325995
35-39 years | 2.541452 .0919042 25.79 0.000 2.367559 2.728118
|
raceV3 |
Black | .9550939 .0322864 -1.36 0.174 .8938646 1.020517
All other .. | 1.696862 .0414454 21.65 0.000 1.617544 1.780069
|
smkstd | 2.151101 .0203501 80.97 0.000 2.111583 2.191359
_cons | 6.21e-06 2.36e-07 -316.16 0.000 5.77e-06 6.69e-06
ln(populat~n) | 1 (exposure)
-------------------------------------------------------------------------------
Note: _cons estimates baseline incidence rate (conditional on zero random
effects).

. predict mepois3
(option mu assumed)

. sum mepois3

Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
mepois3 | 23,751 .6816976 1.779936 6.79e-06 18.03993

. margins

Predictive margins Number of obs = 23,751
Model VCE : OIM

Expression : Predicted mean, predict()

------------------------------------------------------------------------------
| Delta-method
| Margin Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_cons | .6816976 .0053574 127.24 0.000 .6711973 .692198
------------------------------------------------------------------------------

Example with grouping variable:

. mepoisson count i.sex i.agedx19 i.raceV3 smkstd, exposure( population ) nolog
> irr || fips:

Mixed-effects Poisson regression Number of obs = 23,751
Group variable: fips Number of groups = 596

Obs per group:
min = 25
avg = 39.9
max = 379

Integration method: mvaghermite Integration pts. = 7

Wald chi2(8) = 3353.84
Log likelihood = -18310.529 Prob > chi2 = 0.0000
-------------------------------------------------------------------------------
count | IRR Std. Err. z P>|z| [95% Conf. Interval]
--------------+----------------------------------------------------------------
sex |
Female | 2.944917 .0966152 32.92 0.000 2.761514 3.1405
|
agedx19 |
20-24 years | 1.41085 .0574339 8.46 0.000 1.302655 1.528031
25-29 years | 1.863787 .0711791 16.30 0.000 1.729372 2.00865
30-34 years | 2.293706 .0843796 22.57 0.000 2.134147 2.465195
35-39 years | 2.667509 .0969174 27.00 0.000 2.48416 2.864391
|
raceV3 |
Black | .9986017 .0368053 -0.04 0.970 .9290086 1.073408
All other .. | 1.778699 .0483276 21.20 0.000 1.686457 1.875987
|
smkstd | 1.391104 .0469908 9.77 0.000 1.301987 1.486322
_cons | .0000143 7.37e-07 -216.01 0.000 .0000129 .0000158
ln(populat~n) | 1 (exposure)
--------------+----------------------------------------------------------------
fips |
var(_cons)| .3381108 .030477 .2833562 .4034461
-------------------------------------------------------------------------------
Note: Estimates are transformed only in the first equation.
Note: _cons estimates baseline incidence rate (conditional on zero random
effects).
LR test vs. Poisson model: chibar2(01) = 5899.59 Prob >= chibar2 = 0.0000

. predict mepois2
(predictions based on fixed effects and posterior means of random effects)
(option mu assumed)
(using 7 quadrature points)

. sum mepois2

Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
mepois2 | 23,751 .674743 1.151657 .0000212 9.125875

. margins

Predictive margins Number of obs = 23,751
Model VCE : OIM

Expression : Marginal predicted mean, predict()

------------------------------------------------------------------------------
| Delta-method
| Margin Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_cons | 2.367583 .134671 17.58 0.000 2.103632 2.631533
------------------------------------------------------------------------------