简体   繁体   English

R中的gam函数出现问题

[英]Issue with gam function in R

I'm trying to fit a generalized additive logistic regression model, but I'm getting a strange error: 我正在尝试拟合广义加法逻辑回归模型,但出现一个奇怪的错误:

gam_object = gam(event ~ s(time) + ., data = lapse_train, family = "binomial") 

Error in terms.formula(gf, specials = c("s", "te", "ti", "t2")) : '.' in formula and no 'data' argument

Why would it be telling me there is no data argument here when there obviously is? 当明显存在时,为什么会告诉我这里没有数据参数?

Note that the error message is from a call to terms.formula() which is called inside the function. 请注意,错误消息是从对函数内部调用的terms.formula()的调用中terms.formula()的。 This function doesn't see the data= parameter you passed to gam() . 该函数看不到您传递给gam()data=参数。

If you check out the ?formula.gam help page you'll see that 如果您查看?formula.gam帮助页面,您会看到

The formulae supplied to gam are exactly like that supplied to glm except that smooth terms, s, te, ti and t2 can be added to the right hand side ( and . is not supported in gam formulae ). 提供给gam的公式与提供给glm的公式完全相同,只是可以在右侧添加平滑项s,te,ti和t2( gam公式中不支持。 )。

You could expand the formula before passing it to gam via the standard terms() function. 您可以先扩展公式,然后再通过标准terms()函数将其传递给gam For example 例如

gam_object <- gam(terms(event ~ s(time) + ., data=lapse_train), 
    data = lapse_train, family = "binomial") 

You didn't supply any sort of reproducible example so it's not possible to verify that this will work for you. 您没有提供任何可复制的示例,因此无法验证它是否对您有用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM