Version of R and packages minpack.lm
and ggplot2
.
R.version.string
#[1] "R version 4.0.1 (2020-06-06)"
packageVersion('minpack.lm')
#[1] ‘1.2.1’
packageVersion('ggplot2')
#[1] ‘3.3.0’
Version of Ubuntu.
rui@rui:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal
rui@rui:~$
While trying the code of reply of
Carlos Eduardo Lagosta did not get the same results, the code gave a notice of non convergence in 50 iterations.
Warning message:
In nls.lm(par = start, fn = FCT, Jac = Jac, control = control, Lower = Lower, :
lmdif: info = -1. Number of iterations has reached `maxiter' == 50.
And therefore the values of the adjusted parameters were different.
fit
#Nonlinear regression model
# model: y ~ a * (1 - exp(-b * x))^c
# data: df
# a b c
# 6.783e+01 1.341e-06 -4.380e-02
# residual sum-of-squares: 605975
#
#Number of iterations till stop: 50
#Achieved convergence tolerance: 1.49e-08
#Reason stopped: Number of iterations has reached `maxiter' == 50.
I tried then with different values to maxiter
and ptol
, which can be passed on to nlsLM
through control = nls.lm.control(.)
.
library(minpack.lm)
library(ggplot2)
eps <- .Machine$double.eps^0.5
fit <- nlsLM(y ~ a*(1 - exp(-b*x))^c, data = df,
start = list(a = max(df$y), b = 0.05, c = 1),
control = nls.lm.control(maxiter = 100, ptol = eps))
summary(fit)
#
#Formula: y ~ a * (1 - exp(-b * x))^c
#
#Parameters:
# Estimate Std. Error t value Pr(>|t|)
#a 1.297e-02 8.481e+01 0.000 1.000
#b 2.372e-05 1.715e-01 0.000 1.000
#c -9.049e-01 2.271e+00 -0.399 0.698
#
#Residual standard error: 231.9 on 11 degrees of freedom
#
#Number of iterations to convergence: 93
#Achieved convergence tolerance: 1.49e-08
#
Now the graph but with the package ggplot
following the example of the this question.
ggplot(df, aes(x = x, y = y)) +
geom_point() +
geom_smooth(method = 'nlsLM',
formula = y ~ a*(1 - exp(-b*x))^c,
se = FALSE,
method.args = list(start = list(a = max(df$y), b = 0.05, c = 1),
algorithm = 'port',
control = nls.lm.control(maxiter = 100, ptol = eps)))
I used your example, but the curve fit the example of Carlos Eduardo Lagosta
– Milton de Paula
@Miltondepaula Apparently there are differences in results if the versions of R are different. What are their versions of R, OS and package?
– Rui Barradas
the version is 1.2.5001, but I’ve noticed here that there is a more updated version, my OS is Windows 10 version 1903 and the version of the package "minpack.lm" is 1.2-1...
– Milton de Paula
@Miltondepaula This is not the R version, it’s the Rstudio version. Mine is 1.2.5042. To get the R version run
R.version
orR.version.string
.– Rui Barradas
Now correct: "version.string R version 3.6.1 (2019-07-05)", @Ruibarradas
– Milton de Paula