11
$\begingroup$

I'm currently working on a series of Poisson time series models trying to estimate the effect of a change in how the counts were obtained (switching from one diagnostic test to another) while controlling for other trends over time (say a general increase in the incidence of disease). I've got data for a number of different sites.

While I've been tinkering with GAMs as well, I've fit a series of pretty basic GLMs with time trends in them, then pooling the results. The code for this would look something like this in SAS:

PROC GENMOD data=work.data descending;
  model counts = dependent_variable time time*time / link=log dist = poisson;
run;

or this in R:

glm(counts ~ dependent_variable + time + time*time, family="poisson")

Then taking those estimates, and pooling them over the various sites. It's also been suggested to be that I try using a Poisson mixed model with a random slope and intercept for each site, rather than pooling. So essentially you'd have the fixed effect of dependent_variable, then a random effect for the intercept and time (or ideally time and time^2 though I understand that gets a bit hairy).

My issue is I have no idea how to fit one of these models, and it seems that mixed models are where everyone's documentation goes suddenly very opaque. Anyone have a simple explanation (or code) on how to fit what I'm looking to fit, and what to look out for?

$\endgroup$

2 Answers 2

20
$\begingroup$

In R:

library(lme4)
lmer(counts ~ dependent_variable + (1+time|ID), family="poisson")

In this case $Y_i \sim {\rm Poisson}(\lambda_i)$ and this code fits the model

$$ \log(\lambda_i) = \beta_0 + \beta_1 X_i + \eta_{i1} + \eta_{i2}t $$

where $X_i$ is dependent_variable, $t$ is time and $i$ is ID. $\beta_0, \beta_1$ are fixed effects and $\eta_{i1}, \eta_{i2}$ are random effects whose variances are estimated by the model.

Here's an example with some quickly simulated data where the random effect variances truly are 0, the covariate has no effect, every outcome is ${\rm Poisson}(1)$, and each individual is seen 10 times at times $t = 1,...,10$.

x = rnorm(100)
t = rep(1:10,each=10)
ID = rep(1:10,10)
y = rpois(100,1)
g <- lmer(y ~ x + (1+t|ID), family="poisson")
summary(g)
Generalized linear mixed model fit by the Laplace approximation 
Formula: y ~ x + (1 + t | ID) 
   AIC   BIC logLik deviance
 108.8 121.9 -49.42    98.85
Random effects:
 Groups Name        Variance  Std.Dev. Corr   
 ID     (Intercept) 0.0285038 0.168831        
        t           0.0027741 0.052669 -1.000 
Number of obs: 100, groups: ID, 10

Fixed effects:
            Estimate Std. Error z value Pr(>|z|)
(Intercept) -0.09078    0.11808  -0.769    0.442
x            0.13670    0.08845   1.546    0.122

Correlation of Fixed Effects:
  (Intr)
x -0.127

One point of caution - the Std.Dev. column is just the square root of the Variance column, NOT the standard error of the variance estimate!

$\endgroup$
8
  • $\begingroup$ And its ηi1 that results in the random intercept? $\endgroup$
    – Fomite
    Commented May 6, 2012 at 2:24
  • $\begingroup$ $\eta_{i1}$ is the random intercept, yes. $\endgroup$
    – Macro
    Commented May 6, 2012 at 2:27
  • $\begingroup$ Thanks for the answer - one more question. In some of the GLMs, some of the sites benefit greatly from a t^2 term. It seems that most people tag out at one or two random effects - how nasty is a third one going to be in terms of computation? $\endgroup$
    – Fomite
    Commented May 6, 2012 at 2:39
  • $\begingroup$ Well, in the simulated example above, which only had 100 observations and 10 groups, adding the third random effect (by typing g <- lmer(y ~ x + (1+t+I(t^2)|ID), family="poisson")), increased computation time from about .75 seconds to about 11 seconds. As the sample size grows the increase in computing time probably also increases. $\endgroup$
    – Macro
    Commented May 6, 2012 at 2:46
  • 1
    $\begingroup$ @andrea, that would reflect a belief that there is a secular trend in the data set - I didn't assume a priori that this made sense. If the units were people and $t$ were age, then I certainly agree that a fixed effect in time made a lot of sense, but in other situations, the slope in time would be more of a random direction each individual is headed. That's why I didn't include that effect (and epigrad didn't ask how to include the fixed time effect) $\endgroup$
    – Macro
    Commented May 6, 2012 at 13:50
2
$\begingroup$

In SAS:

proc glimmix data = yourdata ic = q;
    class id;
    model y = x / dist = poisson solution;
    random intercept t / subject = id;
run;

But then of course there are plenty of options, more or less useful, to play with.

$\endgroup$
1
  • $\begingroup$ Thanks :) Sadly, I seem to have run aground on convergence issues, but I'll tinker with those. $\endgroup$
    – Fomite
    Commented May 6, 2012 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.