Interpretation of interaction terms between continuous and binary factors in INLA (only one level appearing)

20 views
Skip to first unread message

Xiaoyue Liu

unread,
Oct 16, 2025, 12:31:21 AMOct 16
to R-inla discussion group
Dear all,

I am fitting a Poisson regression model in INLA that includes an interaction between a continuous variable and a binary factor (sex, with levels “men” and “women”). My goal is to estimate sex-specific slopes for each continuous variable.

My model formula is roughly as follows (simplified for clarity):

y ~ f(strata, model = "iid", hyper = list(prec = list(initial = log(1e-04), fixed = TRUE))) +
x1 + x2 + ... + xN +
x1:sex + x2:sex + ... + xN:sex - 1
where sex is a factor with levels "men" and "women".

In the model summary, I obtain coefficients for:
  • each main effect (x1, x2, …),
  • interaction terms like x1:sexwomen, x2:sexwomen, …,
  • and only one term for x1:sexmen (not for all others).
I’d like to confirm my interpretation and understand the reason for this asymmetric coding:
  • For the reference group (men), the effect should correspond to the main slope (e.g., x1).
  • For the other group (women), the slope should be the sum of the main and interaction effects (x1 + x1:sexwomen).
Is this interpretation correct in the context of INLA’s design matrix?

And why might one interaction column (e.g., x1:sexmen) appear in the output, while the others are dropped? Could this be related to the -1 in the formula or INLA’s internal factor-contrast handling?

Any clarification or reference on how INLA constructs these factor-interaction design matrices would be very helpful.

Thank you in advance for your insights!

Best,
Xiaoyue

This message is intended exclusively for its addressee and may contain information that is CONFIDENTIAL and protected by professional privilege. If you are not the intended recipient you are hereby notified that any dissemination, copy or disclosure of this communication is strictly prohibited by law. If this message has been received in error, please immediately notify us via e-mail and delete it.

DATA PROTECTION. We inform you that your personal data, including your e-mail address and data included in your email correspondence, are included in the ISGlobal Foundation files. Your personal data will be used for the purpose of contacting you and sending information on the activities of the above foundations. You can exercise your rights of access, rectification, cancellation and opposition by contacting the following address: lo...@isglobal.org. ISGlobal Privacy Policy at www.isglobal.org.

-----------------------------------------------------------------------------------------------------------------------------

CONFIDENCIALIDAD. Este mensaje y sus anexos se dirigen exclusivamente a su destinatario y puede contener información confidencial, por lo que la utilización, divulgación y/o copia sin autorización está prohibida por la legislación vigente. Si ha recibido este mensaje por error, le rogamos lo comunique inmediatamente por esta misma vía y proceda a su destrucción.

PROTECCIÓN DE DATOS. Sus datos de carácter personal utilizados en este envío, incluida su dirección de e-mail, forman parte de ficheros de titularidad de la Fundación ISGlobal  para cualquier finalidades de contacto, relación institucional y/o envío de información sobre sus actividades. Los datos que usted nos pueda facilitar contestando este correo quedarán incorporados en los correspondientes ficheros, autorizando el uso de su dirección de e-mail para las finalidades citadas. Puede ejercer los derechos de acceso, rectificación, cancelación y oposición dirigiéndose a lo...@isglobal.org . Política de privacidad en www.isglobal.org.

Helpdesk (Haavard Rue)

unread,
Oct 16, 2025, 2:38:11 PM (14 days ago) Oct 16
to Xiaoyue Liu, R-inla discussion group
The parsing of the fixed effects is done as with `lm()': model.matrix() (or its
sparse-matrix version of it)

You can check this like this:

> dat=data.frame(x=1:3, z=as.factor(c("a","b","c")),y = rep(NA,3))
> inla(y~x*z, data=dat)$model.matrix
"dsparseModelMatrix": 3 x 6 sparse Matrix of class "dgCMatrix"
(Intercept) x zb zc x:zb x:zc
1 1 1 . . . .
2 1 2 1 . 2 .
3 1 3 . 1 . 3
@ assign: 0 1 2 2 3 3
@ contrasts:
$z
[1] "contr.treatment"

> inla(y~x*z, data=dat, control.fixed=list(expand.factor.strategy =
"inla"))$model.matrix
"dsparseModelMatrix": 3 x 8 sparse Matrix of class "dgCMatrix"
(Intercept) x za zb zc x:za x:zb x:zc
1 1 1 1 . . 1 . .
2 1 2 . 1 . . 2 .
3 1 3 . . 1 . . 3
@ assign: 0 1 2 2 2 3 3 3
@ contrasts:
named list()


see ?control.fixed

note that the "inla" expansion does not drop factors, so you might need to use
some kind of sum-to-zero constr to make them likehood identifiable



On Wed, 2025-10-15 at 17:32 -0700, Xiaoyue Liu wrote:
> Dear all,
>
> I am fitting a Poisson regression model in INLA that includes an interaction
> between a continuous variable and a binary factor (sex, with levels “men” and
> “women”). My goal is to estimate sex-specific slopes for each continuous
> variable.
>
> My model formula is roughly as follows (simplified for clarity):
>
> y ~ f(strata, model = "iid", hyper = list(prec = list(initial = log(1e-04),
> fixed = TRUE))) +
>      x1 + x2 + ... + xN +
>      x1:sex + x2:sex + ... + xN:sex - 1
> where sex is a factor with levels "men" and "women".
>
> In the model summary, I obtain coefficients for:
>  * each main effect (x1, x2, …),
>  * interaction terms like x1:sexwomen, x2:sexwomen, …,
>  * and only one term for x1:sexmen (not for all others).
> I’d like to confirm my interpretation and understand the reason for this
> asymmetric coding:
>  * For the reference group (men), the effect should correspond to the main
> slope (e.g., x1).
>  * For the other group (women), the slope should be the sum of the main and
> --
> You received this message because you are subscribed to the Google Groups "R-
> inla discussion group" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to r-inla-discussion...@googlegroups.com.
> To view this discussion, visit
> https://groups.google.com/d/msgid/r-inla-discussion-group/28e07423-6324-4895-a8ed-e6be091f6d8bn%40googlegroups.com
> .

--
Håvard Rue
he...@r-inla.org
Screenshot From 2025-10-16 21-37-48.png
Reply all
Reply to author
Forward
0 new messages