[R] Problem fitting a non-linear regression model with nls

Gabor Grothendieck ggrothendieck at gmail.com
Wed Jan 13 16:02:07 CET 2010


You could try the brute force of nls2 package; however, note that you
have 8 parameters and only 16 points so you might look for a more
parsimonious model.  Plotting it it seems somewhat gaussian in shape
so:

mod <- nls(y ~ a * dnorm(x, b, c), start = c(a = mean(y)/dnorm(0, 0,
sd(x)), b = mean(x), c = sd(x)))
matplot(x, cbind(y, fitted(mod)), type = c("p", "l"), pch = 20)



On Wed, Jan 13, 2010 at 9:02 AM, Nathalie Yauschew-Raguenes
<nathalie.yauschew-Raguenes at bordeaux.inra.fr> wrote:
> Hi,
>
> I'm trying to make a regression of the form :
>
> formula <- y ~ Asym_inf  + Asym_sup * ( (1 / (1 + (n1 * (exp( (tmid1-x) /
> scal1) )^(1/n1) ) ) ) - (1 / (1 + (n2 * (exp( (tmid2-x) / scal2) )^(1/n2) )
> ) ) )
> which is a sum of the generalized logistic model proposed by richards.
>
> with data such as these:
>
> x <- c(88,113,128,143,157,172,184,198,210,226,240,249,263,284,302,340)
> y <-
> c(0.04,0.16,1.09,2.65,2.46,2.43,1.88,2.42,1.51,1.70,1.92,1.35,0.89,0.34,0.13,0.10)
>
> I use the nls function to fit my data to the model.
>
> nls(formule, data=cbind.data.frame(x,y), start=list(Asym_inf
> =min(y),Asym_inf =max(y)-min(y),
> n1=1,n2=1,tmid1=120,tmid2=250,scal1=11,scal2=30))
>
> and it always finished by one of those answers (even if I change the initial
> values) :
> - "Error in nls(formule, data = cbind.data.frame(x, y), start =
> list(Asym_inf =min(y),  : \n  le pas 0.000488281 est devenu inférieur à
>  'minFactor' de 0.000976562\n"
> - "Error in nls(formule, data = cbind.data.frame(x, y), start = list(miny =
> min(y),  : \n  gradient singulier\n"
> - "Error in numericDeriv(form[[3]], names(ind), env) : \n  Valeur manquante
> ou infinie obtenue au cours du calcul du modèle\n")
> - "Error in nlsModel(formula, mf, start, wts) : \n  singular gradient matrix
> at initial parameter estimates\n"
> So it seems that I reach a local extremum each time. I know that most of
>  the problem comes from the choice of the initial values of the parameters
> Asym_inf, Asym_inf, n1, n2, tmid1, tmid2, scal1and scal2.
>
> My question is how could I estimate those initial values so that the nls
> fitting works.
>
> Thanks in advance
>
> --
> Nathalie YAUSCHEW-RAGUENES
> Ph.D Student
>
> Unité de Recherches Ecologie Fonctionnelle et Physique de l'Environnement
> (EPHYSE)
> INRA, Centre de Bordeaux - Aquitaine
> 71 Av Edouard Bourlaux
> 33883 Villenave d'Ornon Cedex
> France
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list