Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何修复mgcv'error in terms.formula(formula,data=data)中gam()中的错误:ExtractVars中的模型公式无效_R_Gam_Mgcv - Fatal编程技术网

如何修复mgcv'error in terms.formula(formula,data=data)中gam()中的错误:ExtractVars中的模型公式无效

如何修复mgcv'error in terms.formula(formula,data=data)中gam()中的错误:ExtractVars中的模型公式无效,r,gam,mgcv,R,Gam,Mgcv,在mgcv包中安装gam时,我无法解决这个看似简单的错误消息。非常感谢您的帮助 'terms.formulaformula中出错,数据=数据:ExtractVars中的模型公式无效' 我已经阅读了stackoverflow上所有类似的帖子,但仍然无法解决这个问题。其他一些帖子似乎建议,如果变量名包含空格,则可能发生这种情况,但我的错误并非如此 加载包 读入数据 确定因素 运行模式 我认为你有误解和打字错误。请注意,在te平滑中,您有by=fs,我认为您的意思是使用bs=fs 其次,如果你想要一个

在mgcv包中安装gam时,我无法解决这个看似简单的错误消息。非常感谢您的帮助

'terms.formulaformula中出错,数据=数据:ExtractVars中的模型公式无效'

我已经阅读了stackoverflow上所有类似的帖子,但仍然无法解决这个问题。其他一些帖子似乎建议,如果变量名包含空格,则可能发生这种情况,但我的错误并非如此

加载包 读入数据 确定因素 运行模式
我认为你有误解和打字错误。请注意,在te平滑中,您有by=fs,我认为您的意思是使用bs=fs

其次,如果你想要一个“fs”平滑,你不需要使用te,你需要使用s来设置它。你在哪里

te(abun_adjust_dist, RHDV2_arrive_cat, by = "fs")
你想要

s(abun_adjust_dist, RHDV2_arrive_cat, bs = "fs")

假设您需要RHDV2到达等级的abun_adjust_dist的随机平滑。

您是否也收到了由于在平滑函数中使用因子变量而非随机效应导致的错误?我没有收到在平滑函数中使用因子的错误,但是我对使用GAM还不熟悉,所以我很想知道这是否普遍是可取的/可能的?不,我认为在平滑中使用因子是不明智的,除非它们被用作随机效果。例如,在一个普通的线性回归中,你在一个连续变量上加上一个x^2项,你不会试图在一个分类变量上做这种转换。。。样条曲线也是如此。谢谢,非常感谢
join$site <- factor(join$site)
join$season <- factor(join$season)
join$RHDV_transmis_cat <- factor(join$RHDV_transmis_cat)
join$RHDV2_arrive_cat <- factor(join$RHDV2_arrive_cat)
gam_1 <- gam(RHDV_transmis_cat ~  s(age) + s(weight) + s(site) + s(RCV) + s(season, bs = "cc") + s(preceeding_mth_temp) + s(preceeding_mth_rain) + s(RHDV2_arrive_cat) + s(abun_adjust_dist) + te(abun_adjust_dist, RHDV2_arrive_cat, by ="fs") + s(RHDV2_arrive_cat, season, bs = "re"), data = join, family = binomial, method = "REML", select = TRUE)
te(abun_adjust_dist, RHDV2_arrive_cat, by = "fs")
s(abun_adjust_dist, RHDV2_arrive_cat, bs = "fs")