I have fitted this model in Poisson regression, and I need to check for possible non linear effect of age using splines, in R. Can you please help me with the code?

glm_poisson_splines <- glm(FALL~GRP+AGE+SEX+offset(log(FU)),
  • 2
    $\begingroup$ You might like to take a look at the mgcv package for that cran.r-project.org/web/packages/mgcv/mgcv.pdf $\endgroup$
    – utobi
    Dec 1, 2016 at 14:33
  • 1
    $\begingroup$ Or you can just use glm() with ns() --- natural spline---basis, as in: mod <- glm(FALL ~ GRP+SEX+ns(AGE,df=4)+offset(log(FU)),family=poisson(),data=dat) Then remember first library(splines) $\endgroup$ Dec 1, 2016 at 14:49

1 Answer 1


You have at least two options:

  1. Use the mgcv package that comes with R.

  2. Or simpler, use regression splines, for instance natural splines as in the following:

mod <- glm(FALL ~ GRP + SEX + splines::ns(AGE, df=4) + offset(log(FU)), family=poisson(), data=dat) 

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.