未使用的参数问题
Unused argument issue
我正在使用下面的简单代码,但出现错误:“func(time, state, parms, ...) 错误:未使用的参数 (state, parms)”。看起来每当我使用“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
Complex()
是一个 factory,即 returns 是 ode
所期望类型的函数。所以你需要用 func=Complex(...)
调用 ode
而不是 func=Complex
.
Out <- ode(y = yini, times = times,
func=Complex(koff_WT=1), parms=NULL)
原始代码有几个问题,#1 已经由 Ben Bolker 展示(我只是把它放在单独的一行),#2 在 with 函数中缺少 c()
,#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)
我正在使用下面的简单代码,但出现错误:“func(time, state, parms, ...) 错误:未使用的参数 (state, parms)”。看起来每当我使用“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
Complex()
是一个 factory,即 returns 是 ode
所期望类型的函数。所以你需要用 func=Complex(...)
调用 ode
而不是 func=Complex
.
Out <- ode(y = yini, times = times,
func=Complex(koff_WT=1), parms=NULL)
原始代码有几个问题,#1 已经由 Ben Bolker 展示(我只是把它放在单独的一行),#2 在 with 函数中缺少 c()
,#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)