I want to use y=a^(b^x)
to fit the data below,
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)
When I use the non-linear least squares procedure,
f <- function(x,a,b) {a^(b^x)}
(m <- nls(y ~ f(x,a,b), data = data, start = c(a=1, b=0.5)))
it produces an error: singular gradient matrix at initial parameter estimates. The result is roughly a = 1.1466, b = 0.6415, so there shouldn't be a problem with intial parameter estimates as I have defined them as a=1, b=0.5.
I have read in other topics that it is convenient to modify the curve. I was thinking about something like log y=log a *(b^x)
, but I don't know how to deal with function specification. Any idea?
(m <- nls(y ~ f(x,a,b), data = data, start = c(a=0.9, b=0.6)))
I do not get an error. I get the same answer if I use:(m <- nls(y ~ f(x,a,b), data = data, start = c(a=1.2, b=0.4)))
I do not know if this helps. – Dacya^b^3 = 1.0385
, i.e.a^b = 1.0385^(1/3) = 1.01267
, which is valid fora= 1.01267
andb=1
. That works with(m <- nls(y ~ f(x,a,b), data = data, start = c(a=1.01267, b=1.0)))
as well. Still, I would rather have it all automatically... – Clientele