【发布时间】:2020-09-28 13:15:39
【问题描述】:
我有以下功能:
Proposed <- function(N_b,Lanes,m,A,x.sqr,e_1,e_2,e_3,e_4,e_5) {
e <- data.frame(e_1,e_2,e_3,e_4,e_5)
CSi <- m * ((Lanes/N_b) + (max(A * combn(e,Lanes,sum)) / x.sqr))
return(CSi)
}
我想编写一个类似的函数,但不是将函数 combn 与 sum 函数一起使用,而是编写一个循环来遍历与 Lanes 一样多的 e_1, e_2, e_3, e_4, e_5 变量列,然后选择 max A * combn(...)。这是因为我后来尝试通过 nls 来提供它,它不喜欢我定义 combn 的方式。
我需要类似于问题Error when running nlsLM but works for nls的函数Proposed。
下面给出了一个带有变量的示例数据框。
> dput(DATA)
structure(list(Lanes = c(3, 3, 3, 3, 3, 3, 3), N_b = c(5, 5,
5, 5, 5, 5, 5), A = c(-12, -12, -15, -9, -9, -15, -9), x.sqr =
c(1440, 1440, 2250, 810, 810, 2250, 810), e_1 = c(21.8, 21.8,
29, 14.6, 14.6, 29, 14.6), e_2 = c(9.8, 9.8, 17, 2.6, 2.6, 17,
2.6), e_3 = c(-2.2, -2.2, 5, -9.4, -9.4, 5, -9.4), e_4 =
c(-14.2, -14.2, -7, 0, 0, -7, 0), e_5 = c(0, 0, -19, 0, 0, -19, 0),
m = c(0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85)), row.names = c(1L,
7L, 20L, 25L, 26L, 53L, 89L), class = "data.frame")
【问题讨论】:
标签: r function loops non-linear-regression nls