nls问题:评估模型时产生的缺失值或无穷大

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

我是一个 R 新手,试图将曲线拟合到以下数据

LOEC = c(1.15, 1.28, 1.29, 1.30, 1.72, 2.08, 2.18, 2.21, 2.24, 2.24, 2.26, 2.28, 2.37, 2.50, 2.52, 2.60, 2.63, 3.58, 3.91, 3.94, 4.17, 4.29, 4.46, 4.50, 5.29)
PAF = c(0.000385, 0.0769, 0.154, 0.231, 0.308, 0.346, 0.385, 0.410, 0.436, 0.462, 0.487, 0.513, 0.538, 0.554, 0.631, 0.646, 0.692, 0.769, 0.795, 0.846, 0.859, 0.872, 0.897, 0.923, 1)

问题模型如下:

PAF(LOEC)= 1/(1+e−((log LOEC−a)/b))

剧情:

ggplot(pol_loec, aes(x = LOEC, y = PAF)) +
  geom_point()

代码:

> pol1 <- nls(PAF ~ 1/(1 + exp(-log(LOEC-a)/b)),
>            data = pol_loec,
>            start = c(a=0.39 , b=0.11),
>            trace=TRUE)

错误:

Error in numericDeriv(form[[3L]], names(ind), env, central = nDcentral) : 
  Missing value or an infinity produced when evaluating the model
In addition: Warning message:
In log(LOEC - a) : NaNs produced

我尝试更改起始值但没有成功,并使用 trace=TRUE 查找最后尝试的参数值。有帮助吗?

r nls
1个回答
0
投票

您收到的错误通常是您的模型不正确的一个很好的线索。在这种情况下,我认为您的括号不正确。我想这就是你要找的:

pol1 <- nls(PAF ~ 1/(1 + exp(-(log(LOEC)-a)/b)),
                       data = pol_loec,
                        start = c(a=.39 , b=0.11),
                       trace=TRUE)
summary(pol1)

Formula: PAF ~ 1/(1 + exp(-(log(LOEC) - a)/b))

Parameters:
  Estimate Std. Error t value Pr(>|t|)    
a  0.83985    0.01612   52.10  < 2e-16 ***
b  0.29878    0.02002   14.92 2.55e-13 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.05105 on 23 degrees of freedom

Number of iterations to convergence: 5 
Achieved convergence tolerance: 4.931e-07
© www.soinside.com 2019 - 2024. All rights reserved.