通用加性模型data.frame.default错误:尝试应用非功能 [英] Generalized additive model data.frame.default error: attempting to apply nonfunction

查看:124
本文介绍了通用加性模型data.frame.default错误:尝试应用非功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用mgcv软件包运行通用的加性模型,但我不断收到model.frame.default错误:

I am trying to run a general additive model using the mgcv package, but I keep getting a model.frame.default error:

Error in model.frame.default(formula = Presence ~ Sex + wind_speed + baro +  : 
attempt to apply non-function

这是我正在使用的代码(由于数据集的大小,我正在使用"bam()"):

Here is the code I am using (I am using "bam()" because of the size of the dataset):

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软件包的一些同事进行了比较,但我无法弄清问题所在.有什么建议吗?

I cannot seem to find anything obvious wrong with my formula. I have checked to make sure there are not errors with column lengths not matching, and I don't see any missing parentheses, commas, or +'s. I compared my code to some of my colleagues who have used the mgcv package, but I cannot figure out the issue. Any suggestions?

谢谢您的帮助.

推荐答案

问题是这个

na.action = TRUE

na.action需要一个功能,并且您从?bam传递了一个逻辑()

na.action requires a function and you passed it a logical, (from ?bam)

na.action:指示当数据出现时应该发生什么的功能 包含NA个.默认值由na.action设置设置 options的值,如果未设置,则为na.fail.这 出厂新鲜的默认值为na.omit.

na.action: a function which indicates what should happen when the data contain NAs. 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进行评估

Essentially, within model.frame() you were basically asking R to evaluate

TRUE(df)

正确地引发错误,因为TRUE不是一个函数,而被称为一个函数.

which rightly throws an error as TRUE isn't a function yet was being called as one.

如果要省略带有NA的行,而不是在出现行失败时失败,请使用

If you want to omit rows with NAs rather than fail if they occur, use

na.action = na.omit

这篇关于通用加性模型data.frame.default错误:尝试应用非功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆