6

我想用来y=a^(b^x)拟合下面的数据,

y <- c(1.0385, 1.0195, 1.0176, 1.0100, 1.0090, 1.0079, 1.0068, 1.0099, 1.0038)
x <- c(3,4,5,6,7,8,9,10,11)
data <- data.frame(x,y)

当我使用非线性最小二乘法时,

f <- function(x,a,b) {a^(b^x)}
(m <- nls(y ~ f(x,a,b), data = data, start = c(a=1, b=0.5)))

它会产生一个错误:初始参数估计处的奇异梯度矩阵。结果大致是 a = 1.1466,b = 0.6415,所以初始参数估计应该没有问题,因为我将它们定义为 a=1,b=0.5。

我在其他主题中阅读过修改曲线很方便。我在考虑类似的东西log y=log a *(b^x),但我不知道如何处理函数规范。任何想法?

4

1 回答 1

7

我会将我的评论扩展为答案。

如果我使用以下内容:

y <- c(1.0385, 1.0195, 1.0176, 1.0100, 1.0090, 1.0079, 1.0068, 1.0099, 1.0038)
x <- c(3,4,5,6,7,8,9,10,11)
data <- data.frame(x,y)

f <- function(x,a,b) {a^b^x}

(m <- nls(y ~ f(x,a,b), data = data, start = c(a=0.9, b=0.6)))

或者

(m <- nls(y ~ f(x,a,b), data = data, start = c(a=1.2, b=0.4)))

我得到:

Nonlinear regression model
  model: y ~ f(x, a, b)
   data: data
     a      b 
1.0934 0.7242 
 residual sum-of-squares: 0.0001006

Number of iterations to convergence: 10 
Achieved convergence tolerance: 3.301e-06

如果我将1用作 的起始值a,我总是会得到一个错误,这可能是因为1提升到任何东西都是1

至于自动生成起始值,我不熟悉这样做的过程。我读过的一种方法是模拟曲线并使用生成曲线的起始值来近似您的数据。

这是使用以下代码使用上述参数估计生成的图。我承认这条线的右下部分可能更适合一点:

setwd('c:/users/mmiller21/simple R programs/')

jpeg(filename = "nlr.plot.jpeg")

plot(x,y) 
curve(1.0934^(0.7242^x), from=0, to=11, add=TRUE)

dev.off()

在此处输入图像描述

于 2014-02-17T00:59:45.553 回答