r - R 中的指数回归

标签 r regression exponential-distribution

我有一些点看起来像对数曲线。我试图获得的曲线如下所示: y = a * exp(-b*x) + c

我的代码:

x <- c(1.564379666,1.924250092,2.041559879,2.198696382,2.541267447,2.666400433,2.922534874,2.965726615,3.009969443,3.248480245,3.32927682,3.371404563,3.423759668,3.713001284,3.841419166,3.847632349,3.947993339,4.024541136,4.030779671,4.118849343,4.154008445,4.284232251,4.491359108,4.585182188,4.643299476,4.643299476,4.643299476,4.684369939,4.84424144,4.867973977,5.144490521,5.324298915,5.324298915,5.988637637,6.146599422,6.674937463)
y <- c(25600,23800,11990,14900,15400,19000,9850,7500,10000,12500,11400,8950,10900,3600,11500,9990,4000,3500,4000,3000,8000,5500,6000,7900,2800,2800,2800,2950,4990,4999,3500,6001,6000,1100,1200,6000)

df <- data.frame(x, y)
m <- nls(y ~ I(a*exp(-b*x)+c), data=df, start=list(a=max(y), b=0, c=10), trace=T)

输出:

Error en nlsModel(formula, mf, start, wts) : 
    singular gradient matrix at initial parameter estimates

我做错了什么?

最佳答案

我认为当 b = 0 时,nls 无法计算相对于 a 和 c 的梯度,因为 b=0 从方程中删除了 x。从不同的 b 值开始(哎呀,我看到上面的评论)。这是示例...

m <- nls(y ~ I(a*exp(-b*x)+c), data=df, start=list(a=max(y), b=1, c=10), trace=T)
y_est<-predict(m,df$x)
plot(x,y)
lines(x,y_est)
summary(m)

Formula: y ~ I(a * exp(-b * x) + c)

Parameters:
   Estimate Std. Error t value Pr(>|t|)    
a 6.519e+04  1.761e+04   3.702 0.000776 ***
b 6.646e-01  1.682e-01   3.952 0.000385 ***
c 1.896e+03  1.834e+03   1.034 0.308688    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2863 on 33 degrees of freedom

Number of iterations to convergence: 5 
Achieved convergence tolerance: 5.832e-06

enter image description here

关于r - R 中的指数回归,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26475326/

相关文章:

r - 如何确定一个点是高于还是低于 R 中连接点的线?

python - 类型错误 : unsupported operand type(s) for -: ‘str’ and ‘int’ in PyCaret regression

java - 在java中生成随机数,使其平均值为特定值

r - 在 R 中定义指数分布来估计概率

mysql - 如何将变量从r程序传递到mysql函数

r - 为数据表中的每个唯一值仅选择第一个或最后一个值?

python - scikit-learn 中的随机森林解释

c++ - 是否有记录的方法来重置现有 std::exponential_distribution 对象上的 lambda 参数?

r - Ubuntu 18.04 上的 RcppNumerical 和 RcppEigen 中的警告

r - CRAN 上所有包中的所有函数列表?