Generalized additive model data.frame.default error: attempting to apply nonfunction
Generalized additive model data.frame.default error: attempting to apply nonfunction
我正在尝试 运行 使用 mgcv 包的通用加法模型,但我一直收到 model.frame.default 错误:
Error in model.frame.default(formula = Presence ~ Sex + wind_speed + baro + :
attempt to apply non-function
这是我正在使用的代码(由于数据集的大小,我正在使用 "bam()"):
stormGAM <- bam(Presence~Sex+wind_speed+s(wind_direc)+baro+s(SST_C)+as.factor(daynight),
data=PJstorm_alldata, family=binomial, na.action=TRUE)
数据如下:
'data.frame': 31795 obs. of 25 variables:
$ Con_hour : num 20127330 20127340 20127350 20127360 20127370 ...
$ Year : int 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 ...
$ Month : int 7 7 7 7 7 7 7 7 7 7 ...
$ Day : int 3 3 3 3 3 3 3 3 3 3 ...
$ Hour : int 3 4 5 6 7 8 9 10 11 12 ...
$ Timestamp : POSIXct, format: "2012-07-03 03:00:00" "2012-07-03 04:00:00" "2012-07-03 05:00:00" ...
$ Date : Date, format: "2012-07-03" "2012-07-03" "2012-07-03" ...
$ Region : Factor w/ 1 level "Jervis Bay": 1 1 1 NA NA NA NA NA NA NA ...
$ Station : Factor w/ 17 levels "JB1","JB10","JB11",..: 12 12 12 NA NA NA NA NA NA NA ...
$ ReceiverID : Factor w/ 37 levels "VR2W-100736",..: 5 5 5 NA NA NA NA NA NA NA ...
$ TagID : Factor w/ 54 levels "A69-1303-32577",..: 43 43 43 NA NA NA NA NA NA NA ...
$ Sex : Factor w/ 2 levels "Female","Male": 1 1 1 NA NA NA NA NA NA NA ...
$ wind_speed : num 11 11 10 12 11 11 14 15 20 24 ...
$ wind_direc : num 277 282 278 272 252 269 256 244 220 207 ...
$ sea_level_baro : num 1018 1018 1018 1019 1019 ...
$ baro : num 1018 1018 1018 1019 1019 ...
$ max_wind : num 17 13 13 17 17 21 22 24 33 41 ...
$ SST_C : num 17.4 17.4 17.4 17.4 17.4 ...
$ Presence : int 1 1 1 0 0 0 0 0 0 0 ...
$ gbirowsums : int 1 1 1 0 0 0 0 0 0 0 ...
$ Total_tagged : int 1 1 1 1 1 1 1 1 1 1 ...
$ Prop_Present : num 1 1 1 0 0 0 0 0 0 0 ...
$ sunrise : POSIXct, format: "2012-07-03 07:05:34" "2012-07-03 07:05:34" "2012-07-03 07:05:34" ...
$ sunset : POSIXct, format: "2012-07-03 16:57:00" "2012-07-03 16:57:00" "2012-07-03 16:57:00" ...
$ daynight : chr "night" "night" "night" "night" ...
我似乎找不到我的公式有任何明显的错误。我已检查以确保不存在列长度不匹配的错误,并且我没有看到任何缺少的括号、逗号或 +。我将我的代码与一些使用过 mgcv 包的同事进行了比较,但我无法找出问题所在。有什么建议吗?
感谢您的帮助。
问题是这样的
na.action = TRUE
na.action
需要一个 函数 并且你传递给它一个逻辑,(来自 ?bam
)
na.action
: a function which indicates what should happen when the data
contain NA
s. The default is set by the na.action
setting
of options
, and is na.fail
if that is unset. The
factory-fresh default is na.omit
.
本质上,在 model.frame()
内,您基本上是在要求 R 评估
TRUE(df)
正确地抛出错误,因为 TRUE
不是一个函数,但被作为一个函数调用。
如果您想省略带有 NA
的行而不是在它们出现时失败,请使用
na.action = na.omit
我正在尝试 运行 使用 mgcv 包的通用加法模型,但我一直收到 model.frame.default 错误:
Error in model.frame.default(formula = Presence ~ Sex + wind_speed + baro + :
attempt to apply non-function
这是我正在使用的代码(由于数据集的大小,我正在使用 "bam()"):
stormGAM <- bam(Presence~Sex+wind_speed+s(wind_direc)+baro+s(SST_C)+as.factor(daynight),
data=PJstorm_alldata, family=binomial, na.action=TRUE)
数据如下:
'data.frame': 31795 obs. of 25 variables:
$ Con_hour : num 20127330 20127340 20127350 20127360 20127370 ...
$ Year : int 2012 2012 2012 2012 2012 2012 2012 2012 2012 2012 ...
$ Month : int 7 7 7 7 7 7 7 7 7 7 ...
$ Day : int 3 3 3 3 3 3 3 3 3 3 ...
$ Hour : int 3 4 5 6 7 8 9 10 11 12 ...
$ Timestamp : POSIXct, format: "2012-07-03 03:00:00" "2012-07-03 04:00:00" "2012-07-03 05:00:00" ...
$ Date : Date, format: "2012-07-03" "2012-07-03" "2012-07-03" ...
$ Region : Factor w/ 1 level "Jervis Bay": 1 1 1 NA NA NA NA NA NA NA ...
$ Station : Factor w/ 17 levels "JB1","JB10","JB11",..: 12 12 12 NA NA NA NA NA NA NA ...
$ ReceiverID : Factor w/ 37 levels "VR2W-100736",..: 5 5 5 NA NA NA NA NA NA NA ...
$ TagID : Factor w/ 54 levels "A69-1303-32577",..: 43 43 43 NA NA NA NA NA NA NA ...
$ Sex : Factor w/ 2 levels "Female","Male": 1 1 1 NA NA NA NA NA NA NA ...
$ wind_speed : num 11 11 10 12 11 11 14 15 20 24 ...
$ wind_direc : num 277 282 278 272 252 269 256 244 220 207 ...
$ sea_level_baro : num 1018 1018 1018 1019 1019 ...
$ baro : num 1018 1018 1018 1019 1019 ...
$ max_wind : num 17 13 13 17 17 21 22 24 33 41 ...
$ SST_C : num 17.4 17.4 17.4 17.4 17.4 ...
$ Presence : int 1 1 1 0 0 0 0 0 0 0 ...
$ gbirowsums : int 1 1 1 0 0 0 0 0 0 0 ...
$ Total_tagged : int 1 1 1 1 1 1 1 1 1 1 ...
$ Prop_Present : num 1 1 1 0 0 0 0 0 0 0 ...
$ sunrise : POSIXct, format: "2012-07-03 07:05:34" "2012-07-03 07:05:34" "2012-07-03 07:05:34" ...
$ sunset : POSIXct, format: "2012-07-03 16:57:00" "2012-07-03 16:57:00" "2012-07-03 16:57:00" ...
$ daynight : chr "night" "night" "night" "night" ...
我似乎找不到我的公式有任何明显的错误。我已检查以确保不存在列长度不匹配的错误,并且我没有看到任何缺少的括号、逗号或 +。我将我的代码与一些使用过 mgcv 包的同事进行了比较,但我无法找出问题所在。有什么建议吗?
感谢您的帮助。
问题是这样的
na.action = TRUE
na.action
需要一个 函数 并且你传递给它一个逻辑,(来自 ?bam
)
na.action
: a function which indicates what should happen when the data containNA
s. The default is set by thena.action
setting ofoptions
, and isna.fail
if that is unset. The factory-fresh default isna.omit
.
本质上,在 model.frame()
内,您基本上是在要求 R 评估
TRUE(df)
正确地抛出错误,因为 TRUE
不是一个函数,但被作为一个函数调用。
如果您想省略带有 NA
的行而不是在它们出现时失败,请使用
na.action = na.omit