gpt4 book ai didi

r - R 中 gam 函数的问题

转载 作者:行者123 更新时间:2023-12-02 04:20:45 27 4
gpt4 key购买 nike

我正在尝试拟合广义加性逻辑回归模型,但出现了一个奇怪的错误:

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

为什么它会告诉我这里没有数据参数,而显然有数据参数?

最佳答案

请注意,错误消息来自对函数内部调用的 terms.formula() 的调用。此函数看不到您传递给 gam()data= 参数。

如果您查看 ?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).

您可以在通过标准 terms() 函数将公式传递给 gam 之前对其进行扩展。例如

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

您没有提供任何类型的reproducible example因此无法验证这是否适合您。

关于r - R 中 gam 函数的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30627642/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com