nls 参数的上限

问题描述 投票:0回答:1

我有以下代码来将 sigmoidal 函数拟合到我的数据:

nlsLM(mepAMP ~ plateau / (1 + exp(slope*(S50 - pMSO))), 
      data = df,
      start = list(plateau = 7, S50 = 100, slope = 0.15)

根据我的理解,

nlsLM
(很像r中可用的基
nls
)可以选择数据的上限和下限。我特别想将
plateau
限制为 ≤8 mV,以提供该参数的生理上合理的近似值。有没有一种方法可以只限制一个参数?我看过一些帖子,其中指定了
upper = c(1000, 1)
或类似的内容,但我不确定这是否会限制所有参数以及如何指定
plateau

我已经尝试过

upper = c(8)
,但这给了我以下错误:

Error in nls.lm(par = start, fn = FCT, jac = jac, control = control, lower = lower,  : 
  length(upper) must be equal to length(par)

我似乎找不到设置上限的正确语法,希望得到任何指导。

r nls
1个回答
0
投票

您需要使用命名向量。该向量必须包含所有参数的上限。如果您只想对其中一个值设置上限参数,请将其他值设置为

Inf

library(minpack.lm)

nlsLM(mepAMP ~ plateau / (1 + exp(slope*(S50 - state))), 
                         data = df, 
                         start = list(plateau = 1, S50 = 1, slope = 1),
                         upper = c(plateau = 3, S50 = Inf, slope = Inf)) 
#> Nonlinear regression model
#>   model: mepAMP ~ plateau/(1 + exp(slope * (S50 - state)))
#>    data: df
#> plateau     S50   slope 
#>   3.000   5.912   1.014 
#>  residual sum-of-squares: 1.259
#> 
#> Number of iterations to convergence: 13 
#> Achieved convergence tolerance: 1.49e-08

创建于 2023-08-25,使用 reprex v2.0.2


使用的数据 - 取自上一个问题

df <- structure(list(mepAMP = c(0.38117575, 0.11300747, 0.37239499, 
0.51321839, 0.56851893, 1.73259296, 2.08146847, 2.80090151, 3.04446933, 
2.67647473, 3.87695509), state = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 
10, 11)), row.names = c(NA, -11L), class = "data.frame")
© www.soinside.com 2019 - 2024. All rights reserved.