简体   繁体   English

gam / bam / bam(discrete = TRUE)不包含/不包含/不包含交互(predict(type =“ terms”))

[英]gam/bam/bam(discrete=TRUE) does/does/does not include interactions in predict(type=“terms”)

When using the bam(discrete=TRUE) option, the predict(type="terms") function no longer reports interaction terms. 使用bam(discrete = TRUE)选项时,predict(type =“ terms”)函数不再报告交互项。 This can be avoided by putting interaction terms in as separate, interacted columns, preventing the function from seeing the source of the interaction, but this is troublesome. 可以通过将交互项放在单独的交互列中来避免这种情况,以防止函数看到交互源,但这很麻烦。 Is there some theoretical reason we should not expect to see interactions from bam(discrete=TRUE), even though we can accomplish the same thing by creating the interactions explicitly? 尽管我们可以通过显式创建交互来完成相同的事情,但是有一些理论上的原因使我们不希望看到bam(discrete = TRUE)的交互吗?

The problem is fixable whenever we replace the interaction terms x:y with a bunch of columns explicitly encoding the interaction. 每当我们用一堆显式编码交互的列替换交互项x:y时,该问题就可以解决。 I have tried other, various fixes in an attempt to force the interactions through; 我尝试了其他各种修复方法,以试图使交互通过。 eg (0+x):y, which I'm not sure is even meaningful, suspecting that the columns are removed in the same way the intercept is removed from predict.bam(type="terms"). 例如(0 + x):y,我不确定这是否有意义,因为怀疑该列已以与Forecast.bam(type =“ terms”)中的截距相同的方式被删除。

library(mgcv)

mydf <- data.frame(class = factor(round(runif(500), digits=1)),
               x     = runif(500),
               y     = runif(500))

mydf$z <- 1 + as.numeric(mydf$class) * mydf$x + 6*(mydf$y - 0.5)^2 + 
rnorm(n=500, mean=0, sd=0.1)

mygam <- gam(z ~ 0 + class + class:x + s(y), data=mydf)

head(predict(mygam, type="terms"))

mybam <- bam(z ~ 0 + class + class:x + s(y), data=mydf)

head(predict(mybam, type="terms"))

mydiscretebam <- bam(z ~ 0 + class + class:x + s(y), discrete=TRUE, data=mydf)

head(predict(mydiscretebam, type="terms"))

I expect the results to differ, since there are two different optimization algorithms in use, but I'm surprised that the interactions are not even reported in the third predict call. 我期望结果会有所不同,因为使用了两种不同的优化算法,但是令我惊讶的是,在第三个预测调用中甚至没有报告交互作用。 The model estimates in this case are not the sum of the terms. 在这种情况下,模型估计值不是项的总和。 Why is the intercept removed? 为什么要删除拦截器? Is this also responsible for the interactions being removed? 这还负责删除交互吗? The coefficients are available in the summary, same as any other parametric coefficient, so is their exclusion accidental? 汇总中可以使用这些系数,与其他任何参数系数一样,因此将其排除是偶然的吗?

As far as I know, I'm really just changing the optimization algorithm. 据我所知,我实际上只是在更改优化算法。 The fact that certain columns come from interactions seems irrelevant. 某些列来自交互的事实似乎无关紧要。

It's a bug in predict.gam (which is called by the discrete version of predict.bam to do the parametric terms). 这是predict.gam中的一个错误(由predict.bam的离散版本调用以执行参数项)。 Fixed for the next release. 已为下一个版本修复。 Thanks. 谢谢。 Meanwhile you can use 同时您可以使用

predict(mydiscretebam, type="terms",discrete=FALSE)

Simon (mgcv maintainer) 西蒙(mgcv维护者)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 mgcv:predict.bam() 中的标准误差不同,离散 = true - mgcv: standard errors differ in predict.bam() with discrete = true 为什么在mgcv :: bam()中使用cluster =参数会导致错误? - Why does using cluster= argument in mgcv::bam() result in an error? 使用带有family = betar的bam()的GAM错误 - GAM error using bam() with family = betar predict.glm(, type=&quot;terms&quot;) 实际上做了什么? - What does predict.glm(, type="terms") actually do? 有没有办法产生不居中的 predict.gam(..., type=&quot;terms&quot;) 值 - Is there a way to produce predict.gam(..., type="terms") values that are NOT centered 为什么用离散选项拟合具有随机效应的 GAM 会导致非常不同的输出? - Why does fitting a GAM with random effects with the discrete option result in very different outputs? GAM(mgcv)中分类术语之间的相互作用 - Interactions between categorical terms in GAM (mgcv) 尝试从 bam() output 预测没有随机效应的错误 - Error trying to predict without random effect from bam() output 拟合随机效果Z20F35E630DAF44DBFA4C3F68F53999999999999999999999999999999999999999DAFAM()而不是GAM()ZC1C425268E68E6855174C174F174140278E608ENENENENENENENENENENENENENENED时,错误 - error when fitting random effects model using bam() rather than gam() function in mgcv package, R 预测如何处理包含AsIs函数的模型? - How does predict deal with models that include the AsIs function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM