[R] Starting estimates for nls Exponential Fit

Prof. John C Nash nashjc at uottawa.ca
Wed Dec 2 17:45:53 CET 2009


Kate Mullen showed one approach to this problem by using DEOptim to get
some good starting values.

However, I believe that the real issue is scaling (Warning: well-ridden
hobby-horse!).

With appropriate scaling, as below, nls does fine. This isn't saying nls
is perfect -- I've been trying to figure out how to do a nice job of
helping folk to scale their problems. Ultimately, it would be nice to
has an nls version that will do the scaling and also watch for some
other situations that give trouble.

Cheers, JN


## JN test
rm(list=ls())

ExponValues <- c(2018.34,2012.54,2018.85,2023.52,2054.58,2132.61,2247.17,
                 2468.32,2778.47)

ExponCycles <- c(17,18,19,20,21,22,23,24,25)

mod <- function(x) x[1] + x[2]*x[3]^ExponCycles

modj <- function(x) (1000*x[1] + 0.001*x[2]*x[3]^ExponCycles)

fun <- function(x) sum((ExponValues-mod(x))^2)



pa<-c(1,2,3)
lo<-c(0,0,0)
up<-c(20,20,20)
names(pa) <- c("Y0", "a", "E")

## fit w/port and GN
Emodjn<- nls(ExponValues ~ (1000*Y0 + 0.001*a*(E^ExponCycles)),
             start=pa, algorithm='port', lower=lo, upper=up,
             control=list(maxiter=1000, trace=TRUE, warnOnly=TRUE))

Emodjn1 <- nls(ExponValues ~ (1000*Y0 + 0.001*a*(E^ExponCycles)), start=pa,
             control=list(maxiter=1000, trace=TRUE, warnOnly=TRUE))

## fit
matplot(cbind(ExponValues, fitted(Emodjn), fitted(Emodjn1)),type="l")




More information about the R-help mailing list