【发布时间】:2014-12-10 16:01:42
【问题描述】:
我正在尝试使用nlm 拟合两条曲线,但我遇到了一些问题。首先我尝试分别拟合每条曲线,一切正常,得到的参数与模拟曲线所用的参数相似。
每条曲线由不同的方程定义,但它们共享一些参数。所以,我想知道是否可以使用nlm 或其他优化方法同时拟合两条曲线。
x<-seq(0,120, by=5)
y<-100/50*exp(-0.02*x)*rnorm(25, mean=1, sd=0.05)
y2<-(1*100/50)*(0.1/(0.1-0.02))*(exp(-0.02*x)-exp(-0.1*x))*rnorm(25, mean=1, sd=0.05)
xy<-data.frame(x,y)
xy2<-data.frame(x,y2)
fit<-nls(y~100/a*exp(-b*x), data=xy, start=c(a=45, b=0.018), trace=T)
fit
# Nonlinear regression model
# model: y ~ 100/a * exp(-b * x)
# data: xy
# a b
# 51.68688 0.01936
# residual sum-of-squares: 0.01934
#
# Number of iterations to convergence: 4
# Achieved convergence tolerance: 1.395e-07
fit2<-nls(y2~100/a*(c/(c-b))*(exp(-b*x)-exp(-c*x)), data=xy2,
start=c(a=45, b=0.018, c=0.15), trace=T)
fit2
# Nonlinear regression model
# model: y2 ~ 100/a * (c/(c - b)) * (exp(-b * x) - exp(-c * x))
# data: xy2
# a b c
# 49.92938 0.01997 0.09903
# residual sum-of-squares: 0.03024
#
# Number of iterations to convergence: 4
# Achieved convergence tolerance: 2.12e-06
【问题讨论】:
标签: r regression curve-fitting data-fitting nls