jorfid wrote on 01/25/2012 04:19:48 AM:

> Hi,
> 
> I have some data I want to fit with a non-linear function using nls, but 
it
> won't solve.
> 
> > regresjon<-nls(lcfu~lN0+log10(1-(1-10^(k*t))^m), data=cfu_data,
> > start=(list(lN0 = 7.6, k = -0.08, m = 2)))
> Error in nls(lcfu ~ lN0 + log10(1 - (1 - 10^(k * t))^m), data = 
cfu_data,  : 
>   step factor 0.000488281 reduced below 'minFactor' of 0.000976562
> 
> Tried to increase minFactor and number of iteration, but resulted in
> extremely high number of iterations
> > regresjon2<-nls(lcfu~lN0+log(1-(1-10^(k*t))^m, base=10), 
data=cfu_data,
> > start=(list(lN0 = 7.6, k = -0.08, m = 2)),
> > control=nls.control(maxiter=50000, minFactor=1/1000000000000000000))
> Error in nls(lcfu ~ lN0 + log(1 - (1 - 10^(k * t))^m, base = 10), data =
> cfu_data,  : 
>   number of iterations exceeded maximum of 50000
> 
> Tried to give the derivatives, but got an error message I don't 
understand:
> > model <- deriv(~lN0+log(1-(1-10^(k*t))^m,base=10), # rhs of model
> + c('lN0', 'k', 't', 'm'), # parameter names
> + function(lN0, k, t, m){} # arguments for result
> + )
> > regresjon2<-nls(lcfu~model(lN0, k, t, m), data=cfu_data, 
start=(list(lN0 =
> > 7.6, k = -0.08, m = 2)), control=nls.control(maxiter=50000,
> > minFactor=1/1000000000000000000))
> Error in qr.default(.swts * attr(rhs, "gradient")) : 
>   NA/NaN/Inf in foreign function call (arg 1)
> 
> I have many datasets, but here is one as an example:
> 
> t      lcfu
> 0      7.344108507
> 1.0625      7.166004379
> 1.958333333   7.317609443
> 3.722222222   7.099456839
> 6.847222222   7.009846065
> 16.95833333   6.7143479
> 28.90625   6.086498408
> 37.9375      5.060249368
> 45.29166667   3.69628886
> 57.29166667   1.008174184
> 
> Thanks
> Jörgen


Where did you get your nonlinear equation?  It doesn't seem to do a good 
job of tracking the shape of the example data you provided.  You can see 
this for yourself by tweaking the input parameters and plotting the 
resulting curves.

cfu_data <- data.frame(t=c(0, 1.0625, 1.958333333, 3.722222222, 
6.847222222, 
        16.95833333, 28.90625, 37.9375, 45.29166667, 57.29166667), 
        lcfu=c(7.344108507, 7.166004379, 7.317609443, 7.099456839, 
7.009846065, 
        6.7143479, 6.086498408, 5.060249368, 3.69628886, 1.008174184))

old.fcn <- function(t, lN0=7.6, k=-0.08, m=2) {lN0 + 
log10(1-(1-10^(k*t))^m)}
plot(cfu_data$t, cfu_data$lcfu)
lines(cfu_data$t, old.fcn(cfu_data$t))
lines(cfu_data$t, old.fcn(cfu_data$t, lN0=5.6), col="green")
lines(cfu_data$t, old.fcn(cfu_data$t, lN0=9.6), col="green")
lines(cfu_data$t, old.fcn(cfu_data$t, k=-0.04), col="red")
lines(cfu_data$t, old.fcn(cfu_data$t, k=-0.16), col="red")
lines(cfu_data$t, old.fcn(cfu_data$t, m=0.05), col="blue")
lines(cfu_data$t, old.fcn(cfu_data$t, m=8), col="blue")

A three-parameter exponential equation does a much better job.

new.fit <- nls(lcfu ~ a*(1 - exp(-b*(c-t))), data=cfu_data, 
        start=(list(a=7, b=0.05, c=60)))
lines(cfu_data$t, predict(new.fit), lwd=2)

Jean

	[[alternative HTML version deleted]]

