我一直在尝试使用nls函数将实验数据拟合到我拥有的模型中,用3个参数的函数表示,让我们说a,b和c。但是,我想保持b和c固定,因为我知道它们的真实值,并且只适合参数a:
nls(formula=pattern~myfunction(a, b, c), start=list(a=estimate_a), control=list(maxiter=50, tol=5e-8, warnOnly=T), algorithm="port", weights=sqrt(pattern), na.action=na.exclude, lower=0, upper=1)
但显然这不起作用......我怎么能告诉R b和c是固定的?
答案 0 :(得分:4)
要修复参数(1),请在运行nls
之前设置它,并且(2)不要将其包含在start
中。这是一个自包含的示例,显示a
到0:
a <- 0
nls(demand ~ a + b * Time, BOD, start = list(b = 1))
答案 1 :(得分:0)
快速解决方案:
my_new_function <- function(a) myfunction(a, b = b_true, c = c_true)
nls(formula = pattern ~ my_new_function(a), start = list(a = estimate_a),
control = list(maxiter = 50, tol = 5e-8, warnOnly = TRUE), algorithm = "port",
weights = sqrt(pattern), na.action = na.exclude, lower = 0, upper = 1)