"Simon Blomberg" <[EMAIL PROTECTED]> writes: > One way would be to use the nls package: > > library(nls) > # your y values > foo.dat <- (0.83 * exp(-0.017 * 1:1000) + 0.5) + rnorm(1000,0,0.05) > # create some x values in a data frame > foo.dat <- data.frame(cbind(foo.dat, 0:999)) > names(foo.dat) <- c("y", "x") # give them names > # assume you have reasonable guesses for the starting parameter values > model <- nls( y ~ N * exp(-r * x) + c, > start = list( N = 1, r = .01, c = 0), > data = foo.dat) > > resid(model) # display residuals
Thanks for your answer Simon. I would have suggested a similar approach with two minor modifications: - use the logarithm of the rate constant r instead of r itself - take advantage of N and c being conditionally linear by using the 'plinear' algorithm in nls. The call to nls would be model <- nls(y ~ cbind(exp(-exp(lr) * x), 1), start = c(lr = log(.01)), data = foo.dat, alg = 'plinear') ______________________________________________ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help