nls 参数的上限约束

Upper constraints for nls parameters

提问人:A.R. 提问时间:8/26/2023 最后编辑:A.R. 更新时间:8/26/2023 访问量:108

问:

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

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

根据我的理解,(很像 r 中可用的基数)可以选择为数据选择上限和下限。我特别想将该参数限制在 ≤8 mV,以提供该参数的生理上合理的近似值。有没有办法只约束一个参数?我看过一些他们指定或类似内容的帖子,但我不确定这是否限制了所有参数以及我如何指定.nlsLMnlsplateauupper = 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)

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

编辑:

谢谢艾伦的帮助。当我有多个主题时,我包括在内,然而,这似乎不仅改变了模型拟合了高原确实超过 8 的位置,还改变了那些远未接近的模型。这正常吗?我认为它不会触及那些平台已经低于约束的人的模型拟合。upper = c(plateau = 8, S50 = Inf, slope = Inf)

以前:enter image description here

后:enter image description here

R NLS

评论


答:

1赞 Allan Cameron 8/26/2023 #1

您需要使用命名向量。向量必须包含所有参数的上限。如果只想在其中一个值上设置一个上限参数,请将其他值设置为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")

评论

0赞 A.R. 8/26/2023
再次感谢您的帮助。我已经编辑了我的原始帖子,并出现了一个因此而出现的问题(或者可能不是问题,只是模型如何在约束下工作?