[英]Interactions between categorical terms in GAM (mgcv)
I'm trying to fit a model using the mgcv package and I need to include interactions between categorical terms.我正在尝试使用 mgcv package 来拟合 model 并且我需要包括分类术语之间的交互。 I know how to implement interactions between continuous and categorical variables as
我知道如何实现连续变量和分类变量之间的交互
s(x1, by=c1)
but I don't know how to change this for two categorical terms and I couldn't find anything.但我不知道如何为两个分类术语更改它,我找不到任何东西。
You can add parametric terms to the formula just as you would in a linear model or a GLM.您可以将参数项添加到公式中,就像在线性 model 或 GLM 中一样。
gam(y ~ f1 + f2 + f1:f2 + s(x1), data = df, method = "REML")
or via the shorthand或通过速记
gam(y ~ f1 * f2 + s(x1), data = df, method = "REML")
would be a model with main effects plus interactions of the two categorical variables f1
and f2
plus a smooth effect of continuous variable x1
.将是一个 model ,主效应加上两个分类变量
f1
和f2
的交互作用加上连续变量x1
的平滑效应。
Anything you can do with parametric terms in lm()
or glm()
can be used in the formula for gam()
, gamm()
, bam()
, and gamm4::gamm4()
.您可以对
lm()
或glm()
中的参数项执行的任何操作都可以用于gam()
、 gamm()
、 bam()
和gamm4::gamm4()
的公式中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.