0

我正在使用如下简单代码,但出现错误:“函数错误(时间,状态,参数,...):未使用的参数(状态,参数)”。每当我使用“”功能时,似乎都会出现此错误,function(koff_WT)否则模型运行良好。有什么建议可能会出错吗?

library(deSolve)
kon_WT = 1e-4         
kd_WT = 0.01        
koff_WT = kon_WT*kd_WT 
R_WT = 1000       

Complex <- function(koff_WT) {
 function (t,y,parms){
  with(as.list(y,parms), {
    
    dC_WT <-  koff_WT*RL_WT -kon_WT*R_WT*C_WT 
    dRL_WT <- kon_WT*R_WT*C_WT - koff_WT*RL_WT   #nM
    dR_WT <-  koff_WT*RL_WT -kon_WT*R_WT*C_WT 
        
    return(list(c(dC_WT, dRL_WT, dR_WT)))
  })
  }
}

yini <- c(C_WT = 0.1, RL_WT = 0, R_WT= R_WT)
times <- seq(0,40000,100)      
Out <- ode(y = yini, times = times, func=Complex, parms=NULL)

Output <- data.frame(Out)
Result <- Complex(koff_WT =1) ; Result
4

2 回答 2

2

Complex()是一个工厂,即返回ode预期类型的​​函数的函数。所以你需要odefunc=Complex(...)而不是打电话func=Complex

Out <- ode(y = yini, times = times, 
      func=Complex(koff_WT=1), parms=NULL)
于 2020-07-15T16:43:46.057 回答
1

原始代码有几个问题,#1 已经由 Ben Bolker 显示(我只是把它放在单独的一行),#2 缺少c()with 函数和 #3 参数值太大,因此模型立即下降。#1 和 #2 是编程问题,#3 是建模决策。最后一点点代码修饰以提高可读性。

library(deSolve)
kon_WT  <- 1e-4         
kd_WT   <- 0.01        
koff_WT <- kon_WT * kd_WT 
R_WT    <- 1 # 1000                  # (3) R_WT was too high

Complex <- function(koff_WT) {
  function (t, y, parms){
    with(as.list(c(y,parms)), {      # (2) note c() to combine the vectors
      
      dC_WT <-  koff_WT * RL_WT     - kon_WT  * R_WT * C_WT 
      dRL_WT <- kon_WT  * R_WT*C_WT - koff_WT * RL_WT   #nM
      dR_WT <-  koff_WT * RL_WT     - kon_WT  * R_WT * C_WT 
      
      return(list(c(dC_WT, dRL_WT, dR_WT)))
    })
  }
}

yini <- c(C_WT = 0.1, RL_WT = 0, R_WT = R_WT)
times <- seq(0, 40000, 100)

model <- Complex(koff_WT) # (1) Complex is a factory (or closure), returning a function

Out <- ode(y = yini, times = times, func = model, parms = NULL)

plot(Out)
于 2020-07-15T20:33:25.940 回答