在R中以递增形式拟合指数衰减

在R中以递增形式拟合指数衰减,r,plot,curve-fitting,exponential,R,Plot,Curve Fitting,Exponential,我想用指数衰减(或渐近曲线)的递增形式拟合一个函数,这样: Richness = C*(1-exp(k*Abundance)) # k < 0 Richness=C*(1-exp(k*丰度))#k

我想用指数衰减(或渐近曲线)的递增形式拟合一个函数,这样:

Richness = C*(1-exp(k*Abundance))  # k < 0
Richness=C*(1-exp(k*丰度))#k<0
我读过关于
expn()
函数的内容,但就是找不到它(或
nls
包)。我只找到了一个NLSTOLS包,但它没有
expn()
。我尝试了通常的
nls
exp
函数,但我只得到了递增的指数

我想拟合下图(用油漆绘制),但我不知道曲线应该稳定在哪里(丰富度=C)。提前谢谢


这应该让你开始。阅读有关
nls(…)
(在命令提示下键入
?nls
)的文档。同时查找
?摘要
预测

set.seed(1)     # so the example is reproduceable
df <- data.frame(Abundance=sort(sample(1:70,30)))
df$Richness <- with(df, 20*(1-exp(-0.03*Abundance))+rnorm(30))  

fit <- nls(Richness ~ C*(1-exp(k*Abundance)),data=df, 
           algorithm="port",
           start=c(C=10,k=-1),lower=c(C=0,k=-Inf), upper=c(C=Inf,k=0))
summary(fit)
# Formula: Richness ~ C * (1 - exp(k * Abundance))
#
# Parameters:
#    Estimate Std. Error t value Pr(>|t|)    
# C 20.004173   0.726344   27.54  < 2e-16 ***
# k -0.030183   0.002334  -12.93  2.5e-13 ***
# ---
# Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#
# Residual standard error: 0.7942 on 28 degrees of freedom
#
# Algorithm "port", convergence message: relative convergence (4)

df$pred <- predict(fit)
plot(df$Abundance,df$Richness)
lines(df$Abundance,df$pred, col="blue",lty=2)
set.seed(1)#因此示例是可复制的

谢谢你,霍华德。在阅读了shujaa发送的链接后,我也得到了类似的东西

R <- function(a, b, abT) a*(1 - exp(-b*abT))
form <- Richness ~ R(a,b,Abundance)
fit <- nls(form, data=d, start=list(a=20,b=0.01))
plot(d$Abundance,d$Richness, xlab="Abundance", ylab="Richness")
lines(d$Abundance, predict(fit,list(x=d$Abundance)))

R你不需要一个奇特的函数(
expn
)来拟合一个相对简单的方程。您应该从
nls
开始学习。