![](/img/trans.png)
[英]How to fit logarithmic regression to a “negative exponential” scatterplot in R
[英]exponential regression with R ( and negative values)
我试图将曲线拟合到一组数据点,但是没有成功。 所以我问你。
plot(time,val) # look at data
exponential.model <- lm(log(val)~ a) # compute model
fit <- exp(predict(exponential.model,list(Time=time))) # create the fitted curve
plot(time,val)#plot it again
lines(time, fit,lwd=2) # show the fitted line
我唯一的问题是,我的数据包含负值,因此log(val)会产生大量NA,从而导致模型计算崩溃。 我知道我的数据不一定看起来像指数,但无论如何我都想看一看。 我还使用了另一个程序,该程序向我显示val = 27.1331 * exp(-time / 2.88031)非常合适,但我不知道我在做什么错。 我想用R进行计算。我有转移数据的想法,因此不会残留任何负值,但是结果很差,而且肯定会出错。
plot(time,val+20) # look at data
exponential.model <- lm(log(val+20)~ a) # compute model
fit <- exp(predict(exponential.model,list(Time=time))) # create the fitted curve
plot(time,val)#plot it again
lines(time, fit-20,lwd=2) # show the (BAD) fitted line
谢谢!
我想出了一些办法,并找到了令人满意的解决方案。
exponential.model <- lm(log(val)~ a) # compute model
log(val)项试图重新缩放值,因此可以应用线性模型。 由于这对我的值来说是不可能的,因此您必须使用非线性模型(nls)。
exponential.model <- nls(val ~ a*exp(b*time), start=c(b=-0.1,h=30))
这对我来说很好。 令人满意的适合
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.