使用cencorregr函数(NADA2)的意外错误消息



我试图检查一个左删减变量(数据框中名为met的鱼的金属浓度)是否由不同的因素(年龄,性别和采样区域)解释。为此,我使用了NADA2包中的cencorreg函数。我附上下面一个可修复的例子。cens列表示met值是低于(TRUE)还是高于(FALSE)检测限制。我使用R版本4.2.2 (2022-10-31 ucrt) -平台:x86_64-w64-mingw32/x64(64位)

# My dataframe
dfr <-
structure(list(cens = c(FALSE, FALSE, FALSE, FALSE, TRUE, FALSE,FALSE, TRUE, TRUE, FALSE, TRUE, FALSE,                          FALSE, FALSE, FALSE, FALSE,TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,  TRUE,                      FALSE, FALSE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, 
FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, 
TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, 
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, TRUE, FALSE, 
TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE), 
met = c(0.770, 1.147, 0.278,0.172, 0.136, 0.567,0.2614, 0.1749, 0.151, 1.7154, 
0.158, 1.532, 3.758, 2.634, 0.606,8.216, 0.184, 17.517, 2.046, 
0.151, 0.2326, 2.7239, 0.948,2.947, 0.147, 0.265, 
0.304, 0.147, 0.146, 0.134, 0.22, 0.816, 0.140, 
0.158, 0.154, 3.854, 0.157, 0.129, 0.355,2.125, 0.332, 0.165, 0.159, 0.148, 
0.125, 0.114, 0.144, 0.2574, 0.170,0.11, 0.805, 0.324, 2.852, 
0.841, 0.265, 0.237,0.349, 1.921, 0.394, 0.299, 
3.829, 0.122, 0.105, 0.482, 0.141,0.365, 0.108, 0.639, 0.327, 
0.296, 0.197, 0.316, 0.116), 
age = c("yo", "ad", "subad", "ad", "yo", "ad", "subad", 
"yo", "yo", "subad", "yo", "yo", "yo", "subad", "yo", "subad", 
"yo", "yo", "yo", "ad", "ad", "subad", "ad", "subad", "yo", 
"subad", "subad", "yo", "yo", "yo", "yo", "yo", "yo", "yo", 
"yo", "yo", "subad", "yo", "ad", "subad", "ad", "yo", "yo", 
"yo", "yo", "ad", "ad", "yo", "yo", "ad", "subad", "subad", 
"ad", "ad", "ad", "ad", "ad", "subad", "ad", "ad", "subad", 
"ad", "ad", "ad", "ad", "subad", "subad", "ad", "subad", 
"subad", "ad", "subad", "ad"), 
gend = c("f", "f", "f", "f",
"m", "m", "f", "m", "f", "m", "f", "f", "m", "f", "m", "f", 
"f", "m", "f", "m", "f", "m", "f", "m", "m", "f", "f", "f", 
"f", "m", "m", "f", "f", "f", "f", "m", "f", "m", "f", "f", 
"m", "f", "f", "f", "m", "m", "f", "f", "m", "m", "m", "m", 
"f", "f", "m", "m", "m", "f", "f", "f", "f", "f", "m", "f", 
"f", "m", "m", "f", "f", "m", "m", "m", "f"), 
area = c("A","B", "A", "B", "A", "B", "B", "C", "A", "B", "C", "B", "B",
"B", "A", "C", "C", "A", "B", "B", "A", "B", "B", "A", "C", 
"A", "B", "A", "B", "B", "A", "B", "B", "A", "A", "B", "B", 
"C", "C", "C", "A", "B", "B", "B", "B", "C", "B", "B", "A", 
"B", "A", "B", "A", "B", "C", "B", "B", "A", "B", "B", "B", 
"B", "A", "B", "C", "A", "A", "A", "B", "A", "B", "A", "A")), 
class = "data.frame", row.names = c(NA, -73L))

# Analysis using cencorreg
library(NADA2)
cencorreg(dfr$met,dfr$cens,dfr[, c("age","gend","area")]) 
cencorreg(dfr$met,dfr$cens,dfr[, c("age","gend")]) 
cencorreg(dfr$met,dfr$cens,dfr[, c("age","area")])
cencorreg(dfr$met,dfr$cens,dfr$age) # I get an error message "Error in log(nonas[, 1]) : non-numeric argument to mathematical function"
cencorreg(dfr$met,dfr$cens,dfr[, c("age")])# I get an error message "Error in log(nonas[, 1]) : non-numeric argument to mathematical function"
cencorreg(dfr$met,dfr$cens,dfr$gend) # I get an error message "Error in log(nonas[, 1]) : non-numeric argument to mathematical function"

我不明白为什么只有一个因素的校正不起作用,而当包括两个或更多因素时却不是这样。似乎nonas[, 1]被认为是最后3个cencoreg中的非数字参数(因此不可能对y进行对数变换),但在前3个中并非如此?

如果你有任何可以帮助我的意见,请告诉我。提前感谢 迈克尔

您的帖子在R-package GitHub页面中被复制。我们在包的开发版本(即GitHub)中更新了cencorreg(...)函数,并期望尽快将此版本提交给CRAN。

一个主要问题是,解释变量必须作为数据帧输入,而不仅仅是作为cbind矩阵。我们将在元文本中更明确地说明这一点。

最新更新