我需要测试一组参数条件以找到最佳模型(使用drc
包)。也就是说,我想将函数参数存储在一个列表中,然后将它们调用到drm()
函数中。该drc
软件包有一个函数 ( mselect()
) 来执行此操作,但已知它会因未知原因而失败 ( https://www.reddit.com/r/Rlanguage/comments/a1bu44/any_idea_what_im_doing_wrong_with_the_mselect/ )。
示例数据
library(drc) # This also loads in the S.alba data
data(S.alba)
head(S.alba)
Dose Herbicide DryMatter
1 0 Glyphosate 4.7
2 0 Glyphosate 4.6
3 0 Glyphosate 4.1
4 0 Glyphosate 4.4
5 0 Glyphosate 3.2
6 0 Glyphosate 3.0
尝试失败
# List of function arguments to be assessed e.g. drm(...fct = W1.4(fixed = c(NA, 0.1, NA, NA)
model_list <- list(curve = c(W1.4(fixed = c(NA, 0.1, NA, NA)),
LL.4(fixed = c(NA, 0.1, NA, NA))))
# Failed function, attempting to return a list of results
model_select <- function(data, mlist){
model = data %>%
drm(DryMatter ~ Dose, Herbicide, data = . , fct = mlist)
metric = AIC(model)
return(metric)
}
model_select(data = S.alba, mlist = model_list)
drm 错误(DryMatter ~ Dose, Herbicide, data = ., fct = mlist):“fct”列表中的第一个条目不是函数
半工作尝试
model_select_2 <- function(data){
model = data %>%
drm(DryMatter ~ Dose, Herbicide, data = . , fct = W1.4(fixed = c(NA, 0.1, NA, NA)))
metric = AIC(model)
return(metric)
}
model_select_2(data = S.alba)
model_select_2(data = S.alba)
[1] 106.9226
期望的输出
model_select(data = S.alba, mlist = model_list)
[1] W1.4-106.9226
[2] LL.4-99.54702