[R] nls convergence trouble

Petr PIKAL petr.pikal at precheza.cz
Thu Sep 4 13:40:46 CEST 2008


Well, the model you try to fit is almost independent of "b"

try

plot(Qe,fff1(364,0.0126))
points(Qe,fff1(364,10000), col=2)

So you can quite freely choose b without any substantial improvement to 
fit. I am not an expert in nonlinear fitting but seems to me that your 
data does not follow your model, so you need to change your model or 
change your data, depends on your preference.

Regards
Petr

r-help-bounces at r-project.org napsal dne 04.09.2008 12:11:27:

> Hi,
> 
> I agree with you that Excel is not the best tool for fittings, that's 
why I
> try to handle R.
> 
> But I need to use this specific model ("LgmAltFormula") and not a 
polynomial
> expression with the different parameters even if your method produced
> correct fitting.
> 
> The parameters "a" and "b" are the Langmuir parameters that describe the
> adsorption of a compound onto activated carbon. I need to assess these
> parameters.
> 
> 
> Regards/Cordialement
> 
> 
> Benoit Boulinguiez 
> 
> 
> -----Message d'origine-----
> De : Petr PIKAL [mailto:petr.pikal at precheza.cz] 
> Envoyé : mercredi 3 septembre 2008 17:58
> À : Benoit Boulinguiez
> Cc : r-help at r-project.org
> Objet : Odp: [R] nls convergence trouble
> 
> Hi
> 
> Excel fit is not exceptionally good. Try
> 
>  fff<-function(a,b) (V + b * m * a + C0 * V * b - ((C0 * V * b)^2 + 2 * 
C0 
> *
> +     b * V^2 - 2 * C0 * V * m * a * b^2 + V^2 + 2 * V * m * a *
> +     b + (b * m * a)^2)^(1/2))/(2 * b * m)
> 
> and with attached data frame
> 
> plot(Qe,fff(364,0.0126))
> abline(0,1)
> 
> you clearly see linear relationship in smaller values but quite chaotic 
> behaviour in bigger ones (or big deviation of experimental points from 
> your model).
> 
> So it is up to you if you want any fit (like from Excel) or only a good 
> one (like from R). 
> 
> Seems to me that simple linear could be quite a good choice although 
there 
> is some nelinearity.
> 
> fit<-lm(Qe~Ce+C0+V+m)
> summary(fit)
> 
> Call:
> lm(formula = Qe ~ Ce + C0 + V + m)
> 
> Residuals:
>     Min      1Q  Median      3Q     Max 
> -16.654  -8.653   2.426   9.971  11.912 
> 
> Coefficients:
>               Estimate Std. Error t value Pr(>|t|) 
> (Intercept) -8.148e+02  1.330e+03  -0.613 0.549254 
> Ce          -6.894e-02  4.982e-03 -13.839 6.02e-10 ***
> C0           3.284e-02  1.676e-03  19.589 4.26e-12 ***
> V            2.153e+06  4.607e+05   4.674 0.000300 ***
> m           -4.272e+04  1.218e+04  -3.509 0.003167 ** 
> ---
> Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 
> 
> Residual standard error: 10.87 on 15 degrees of freedom
> Multiple R-squared: 0.9903,     Adjusted R-squared: 0.9877 
> F-statistic: 381.3 on 4 and 15 DF,  p-value: 6.91e-15 
> 
> plot(predict(fit), Qe)
> abline(0,1)
> 
> Regards
> Petr
> 
> 
> r-help-bounces at r-project.org napsal dne 03.09.2008 16:01:36:
> 
> > Hi,
> > 
> > Parameters assessment in R with nls doesn't work, though it works fine 

> with
> > MS Excel with the internal solver :(
> > 
> > 
> > I use nls in R to determine two parameters (a,b) from experimental 
data. 
> 
> > 
> >         m         V        C0         Ce        Qe
> > 1  0.0911 0.0021740  3987.581   27.11637  94.51206
> > 2  0.0911 0.0021740  3987.581   27.41915  94.50484
> > 3  0.0911 0.0021740  3987.581   27.89362  94.49352
> > 4  0.0906 0.0021740  5981.370   82.98477 189.37739
> > 5  0.0906 0.0021740  5981.370   84.46435 189.34188
> > 6  0.0906 0.0021740  5981.370   85.33213 189.32106
> > 7  0.0911 0.0021740  7975.161  192.54276 233.30310
> > 8  0.0911 0.0021740  7975.161  196.52891 233.20797
> > 9  0.0911 0.0021740  7975.161  203.07467 233.05176
> > 10 0.0906 0.0021872  9968.951  357.49157 328.29824
> > 11 0.0906 0.0021872  9968.951  368.47609 328.03306
> > 12 0.0906 0.0021872  9968.951  379.18904 327.77444
> > 13 0.0904 0.0021740 13956.532 1382.61955 350.33391
> > 14 0.0904 0.0021740 13956.532 1389.64915 350.16485
> > 15 0.0904 0.0021740 13956.532 1411.87726 349.63030
> > 16 0.0902 0.0021740 15950.322 2592.90486 367.38460
> > 17 0.0902 0.0021740 15950.322 2606.34599 367.06064
> > 18 0.0902 0.0021740 15950.322 2639.54301 366.26053
> > 19 0.0906 0.0021872 17835.817 3894.12224 336.57036
> > 20 0.0906 0.0021872 17835.817 3950.35273 335.21289
> > 21 0.0906 0.0021872 17835.817 3972.29367 334.68320
> > 
> > the model "LgmAltformula" is
> > 
> > Qe ~ (V + b * m * a + C0 * V * b - ((C0 * V * b)^2 + 2 * C0 * 
> >     b * V^2 - 2 * C0 * V * m * a * b^2 + V^2 + 2 * V * m * a * 
> >     b + (b * m * a)^2)^(1/2))/(2 * b * m)
> > 
> > the command in R is
> > 
> > 
> > 
> 
nls(formula=LgmAltFormula,data=bois.DATA,start=list(a=300,b=0.01),trace=TRUE
> > ,control=nls.control(minFactor=0.000000009))
> > 
> > R has difficulties to converge and stops after the maximum of 
iterations
> > 
> > 64650.47 :  2.945876e+02 3.837609e+08 
> > 64650.45 :  2.945876e+02 4.022722e+09 
> > 64650.45 :  2.945876e+02 1.695669e+09 
> > 64650.45 :  2.945876e+02 5.103971e+08 
> > 64650.44 :  2.945876e+02 8.497431e+08 
> > 64650.41 :  2.945876e+02 1.515243e+09 
> > 64650.36 :  2.945877e+02 5.482744e+09 
> > 64650.36 :  2.945877e+02 2.152294e+09 
> > 64650.36 :  2.945877e+02 7.953167e+08 
> > 64650.35 :  2.945877e+02 7.625555e+07 
> > Erreur dans nls(formula = LgmAltFormula, data = bois.DATA, start = 
> list(a =
> > 300,  : 
> >   le nombre d'itérations a dépassé le maximum de 50
> > 
> > 
> > The parameters "a" and "b" are estimated to be 364 and 0.0126 with 
Excel
> > with the same data set.
> > I tried with the algorithm="port" with under and upper limits. One of 
> the
> > parameter reaches the limit and the regression stops.
> > 
> > How can I succeed with R to make this regression? 
> > 
> > 
> > Regards/Cordialement
> > 
> > -------------
> > Benoit Boulinguiez
> > Ph.D
> > Ecole de Chimie de Rennes (ENSCR) Bureau 1.20
> > Equipe CIP UMR CNRS 6226 "Sciences Chimiques de Rennes"
> > Campus de Beaulieu, 263 Avenue du Général Leclerc
> > 35700 Rennes, France
> > Tel 33 (0)2 23 23 80 83
> > Fax 33 (0)2 23 23 81 20
> > http://www.ensc-rennes.fr/ 
> > 
> > 
> > 
> >    [[alternative HTML version deleted]]
> > 
> > ______________________________________________
> > 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.
> 
> ______________________________________________
> 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