drc:使用互动条款时drm中的错误 [英] drc: Error in drm when used interaction terms

查看:94
本文介绍了drc:使用互动条款时drm中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对drc R包中的以下数据进行log-logistic回归拟合,以适应临时性和多样性.但是,我的代码抛出以下错误

I want to fit log-logistic regression for the following data in drc R package for the combination of Temp and Variety. However, my code throws the following error

Error in Temp:Variety : NA/NaN argument

代码:

df2 <-
  structure(list(Temp = c(15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
15L, 20L, 20L, 20L, 20L, 20L, 20L, 25L, 25L, 25L, 25L, 30L, 30L, 
30L, 30L, 35L, 35L, 35L, 35L, 40L, 40L, 40L, 40L, 15L, 15L, 15L, 
15L, 15L, 15L, 15L, 15L, 15L, 20L, 20L, 20L, 20L, 20L, 20L, 25L, 
25L, 25L, 25L, 30L, 30L, 30L, 30L, 35L, 35L, 35L, 35L, 40L, 40L, 
40L, 40L), Variety = c("FH-142", "FH-142", "FH-142", "FH-142", 
"FH-142", "FH-142", "FH-142", "FH-142", "FH-142", "FH-142", "FH-142", 
"FH-142", "FH-142", "FH-142", "FH-142", "FH-142", "FH-142", "FH-142", 
"FH-142", "FH-142", "FH-142", "FH-142", "FH-142", "FH-142", "FH-142", 
"FH-142", "FH-142", "FH-142", "FH-142", "FH-142", "FH-142", "FH-942", 
"FH-942", "FH-942", "FH-942", "FH-942", "FH-942", "FH-942", "FH-942", 
"FH-942", "FH-942", "FH-942", "FH-942", "FH-942", "FH-942", "FH-942", 
"FH-942", "FH-942", "FH-942", "FH-942", "FH-942", "FH-942", "FH-942", 
"FH-942", "FH-942", "FH-942", "FH-942", "FH-942", "FH-942", "FH-942", 
"FH-942", "FH-942"), Start = c(0L, 24L, 48L, 72L, 96L, 120L, 
144L, 168L, 192L, 0L, 24L, 48L, 72L, 96L, 120L, 0L, 24L, 48L, 
72L, 0L, 24L, 48L, 72L, 0L, 24L, 48L, 72L, 0L, 24L, 48L, 72L, 
0L, 24L, 48L, 72L, 96L, 120L, 144L, 168L, 192L, 0L, 24L, 48L, 
72L, 96L, 120L, 0L, 24L, 48L, 72L, 0L, 24L, 48L, 72L, 0L, 24L, 
48L, 72L, 0L, 24L, 48L, 72L), End = c(24, 48, 72, 96, 120, 144, 
168, 192, Inf, 24, 48, 72, 96, 120, Inf, 24, 48, 72, 96, 24, 
48, 72, Inf, 24, 48, 72, Inf, 24, 48, 72, Inf, 24, 48, 72, 96, 
120, 144, 168, 192, Inf, 24, 48, 72, 96, 120, Inf, 24, 48, 72, 
Inf, 24, 48, 72, Inf, 24, 48, 72, Inf, 24, 48, 72, Inf), Germinated = c(0L, 
0L, 1L, 3L, 3L, 12L, 14L, 12L, 15L, 0L, 11L, 27L, 15L, 3L, 4L, 
2L, 30L, 15L, 13L, 6L, 43L, 7L, 4L, 5L, 48L, 3L, 4L, 0L, 31L, 
21L, 8L, 0L, 0L, 0L, 12L, 13L, 6L, 2L, 1L, 26L, 0L, 10L, 13L, 
11L, 13L, 13L, 11L, 21L, 19L, 9L, 7L, 18L, 23L, 12L, 14L, 23L, 
12L, 11L, 12L, 18L, 11L, 19L)), .Names = c("Temp", "Variety", 
"Start", "End", "Germinated"), row.names = c(NA, -62L), class = "data.frame")


library(drc)
fm2 <-
  drm(
        formula   = Germinated ~ Start + End
      , curveid   = Temp:Variety
  #   , pmodels   = 
  #   , weights   = 
      , data      = df2
  #   , subset    = 
      , fct       = LL.2()
      , type      = "event"
      , bcVal     = NULL
      , bcAdd     = 0
  #   , start     =
      , na.action = na.fail
      , robust    = "mean"
      , logDose   = NULL
      , control   = drmc(
                            constr      = FALSE
                            , errorm      = TRUE
                            , maxIt       = 1500
                            , method      = "BFGS"
                            , noMessage   = FALSE
                            , relTol      = 1e-07
                            , rmNA        = FALSE
                            , useD        = FALSE
                            , trace       = FALSE
                            , otrace      = FALSE
                            , warnVal     = -1
                            , dscaleThres = 1e-15
                            , rscaleThres = 1e-15
                            )
      , lowerl    = NULL
      , upperl    = NULL
      , separate  = FALSE
      , pshifts   = NULL 
      )

推荐答案

有两种方法可以做到这一点.一种方法是使用apply遍历因素之一.但是,可能最简单,最整洁的方法是基于要分组的所有变量的唯一组合来创建分组因子(称为grp).然后,您可以使用curveid=grp在该列上对drm进行简单分组.

There are a couple of ways to do this. One would be to use apply to loop over one of the factors. But, probably the simplest and neatest way is to create a grouping factor (lets call it grp), based on unique combinations of all the variables you want to group by. Then, you can simply group drm on that column using curveid=grp.

df2$grp <- factor(paste(df2$Temp, df2$Variety, sep = ","))
fm <-drm(data = df2, curveid = grp,
          formula = Germinated ~ Start + End,  fct = LL.2(), type = "event", 
          control = drmc(constr = FALSE, errorm = TRUE, maxIt = 1500, method = "BFGS", 
                         noMessage = FALSE, relTol = 1e-07, rmNA = FALSE, useD = FALSE, 
                         trace = FALSE, otrace = FALSE, warnVal = -1, dscaleThres = 1e-15, rscaleThres = 1e-15))


summary(fm)

Model fitted: Log-logistic (ED50 as parameter) with lower limit at 0 and upper limit at 1 (2 parms)

Parameter estimates:

             Estimate Std. Error   t-value p-value
b:15,FH-142  -6.03042    0.78914  -7.64179       0
b:20,FH-142  -4.96487    0.60745  -8.17333       0
b:25,FH-142  -4.43982    0.54905  -8.08634       0
b:30,FH-142  -4.80965    0.60804  -7.91014       0
b:35,FH-142  -5.45881    0.69145  -7.89477       0
b:40,FH-142  -5.43884    0.79770  -6.81819       0
b:15,FH-942  -2.92989    0.42582  -6.88058       0
b:20,FH-942  -3.32332    0.42392  -7.83949       0
b:25,FH-942  -2.89164    0.39282  -7.36123       0
b:30,FH-942  -3.23898    0.45011  -7.19602       0
b:35,FH-942  -2.43731    0.35084  -6.94698       0
b:40,FH-942  -1.95940    0.31456  -6.22908       0
e:15,FH-142 162.33560    6.10484  26.59130       0
e:20,FH-142  64.71878    3.08661  20.96757       0
e:25,FH-142  48.23889    2.68275  17.98115       0
e:30,FH-142  36.38342    2.04231  17.81486       0
e:35,FH-142  35.07645    1.85565  18.90249       0
e:40,FH-142  48.44619    2.21382  21.88352       0
e:15,FH-942 158.03982   13.25750  11.92079       0
e:20,FH-942  83.69820    5.80435  14.41991       0
e:25,FH-942  43.00616    3.49778  12.29527       0
e:30,FH-942  50.04317    3.60182  13.89387       0
e:35,FH-942  39.25428    3.76747  10.41925       0
e:40,FH-942  48.40065    5.74681   8.42217       0

这篇关于drc:使用互动条款时drm中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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