

Hi
I need to fit a logistic regression model using a saturable MichaelisMenten function of my predictor x. The likelihood could be expressed as:
L = intercept + emax * x / (EC50+x)
Which I guess could be expressed as the following R model
~ emax*x/(ec50+x)
As far as I know (please, correct me if I am wrong), fitting such a model is to not doable with glm, since the function is not linear.
A Stackoverflow post recommends the bnlr function from the gnlm ( https://stackoverflow.com/questions/45362548/nonlinearlogisticregressionpackageinr)... I would be grateful for any opinion on this package or for any alternative recommendation of package/function.
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Search!
... for "nonlinear logistic regression" at rseek.org.
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
 Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Tue, Jul 28, 2020 at 7:25 AM Sebastien Bihorel via Rhelp <
[hidden email]> wrote:
> Hi
>
> I need to fit a logistic regression model using a saturable
> MichaelisMenten function of my predictor x. The likelihood could be
> expressed as:
>
> L = intercept + emax * x / (EC50+x)
>
> Which I guess could be expressed as the following R model
>
> ~ emax*x/(ec50+x)
>
> As far as I know (please, correct me if I am wrong), fitting such a model
> is to not doable with glm, since the function is not linear.
>
> A Stackoverflow post recommends the bnlr function from the gnlm (
> https://stackoverflow.com/questions/45362548/nonlinearlogisticregressionpackageinr)...
> I would be grateful for any opinion on this package or for any alternative
> recommendation of package/function.
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide
> http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Thank you for your subtle input, Bert... as usual!
This is literally the search I conducted and spent 2 hours on before posting to Rhelp. I was asking for expert opinions, not for search engine FAQ!
Thank anyways
________________________________
From: Bert Gunter < [hidden email]>
Sent: Tuesday, July 28, 2020 11:12
To: Sebastien Bihorel < [hidden email]>
Cc: [hidden email] < [hidden email]>
Subject: Re: [R] Nonlinear logistic regression fitting
Search!
... for "nonlinear logistic regression" at rseek.org< http://rseek.org>.
Bert Gunter
"The trouble with having an open mind is that people keep coming along and sticking things into it."
 Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Tue, Jul 28, 2020 at 7:25 AM Sebastien Bihorel via Rhelp < [hidden email]<mailto: [hidden email]>> wrote:
Hi
I need to fit a logistic regression model using a saturable MichaelisMenten function of my predictor x. The likelihood could be expressed as:
L = intercept + emax * x / (EC50+x)
Which I guess could be expressed as the following R model
~ emax*x/(ec50+x)
As far as I know (please, correct me if I am wrong), fitting such a model is to not doable with glm, since the function is not linear.
A Stackoverflow post recommends the bnlr function from the gnlm ( https://stackoverflow.com/questions/45362548/nonlinearlogisticregressionpackageinr)... I would be grateful for any opinion on this package or for any alternative recommendation of package/function.
______________________________________________
[hidden email]<mailto: [hidden email]> mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


You said:
"As far as I know (please, correct me if I am wrong), fitting such a model
is to not doable with glm, since the function is not linear."
My reply responded to that.
AFAIK, opinions on packages are off topic here. Try stats.stackexchange.com
for that.
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
 Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Tue, Jul 28, 2020 at 8:19 AM Sebastien Bihorel <
[hidden email]> wrote:
> Thank you for your subtle input, Bert... as usual!
>
> This is literally the search I conducted and spent 2 hours on before
> posting to Rhelp. I was asking for expert opinions, not for search engine
> FAQ!
>
> Thank anyways
>
> 
> *From:* Bert Gunter < [hidden email]>
> *Sent:* Tuesday, July 28, 2020 11:12
> *To:* Sebastien Bihorel < [hidden email]>
> *Cc:* [hidden email] < [hidden email]>
> *Subject:* Re: [R] Nonlinear logistic regression fitting
>
> Search!
> ... for "nonlinear logistic regression" at rseek.org.
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
>  Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Tue, Jul 28, 2020 at 7:25 AM Sebastien Bihorel via Rhelp <
> [hidden email]> wrote:
>
> Hi
>
> I need to fit a logistic regression model using a saturable
> MichaelisMenten function of my predictor x. The likelihood could be
> expressed as:
>
> L = intercept + emax * x / (EC50+x)
>
> Which I guess could be expressed as the following R model
>
> ~ emax*x/(ec50+x)
>
> As far as I know (please, correct me if I am wrong), fitting such a model
> is to not doable with glm, since the function is not linear.
>
> A Stackoverflow post recommends the bnlr function from the gnlm (
> https://stackoverflow.com/questions/45362548/nonlinearlogisticregressionpackageinr)...
> I would be grateful for any opinion on this package or for any alternative
> recommendation of package/function.
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide
> http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
>
>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


I hardly see how your reply addressed my question or any part of it. It looks to me that it was simply assumed that I did not perform any search before posting.
________________________________
From: Bert Gunter < [hidden email]>
Sent: Tuesday, July 28, 2020 11:30
To: Sebastien Bihorel < [hidden email]>
Cc: [hidden email] < [hidden email]>
Subject: Re: [R] Nonlinear logistic regression fitting
You said:
"As far as I know (please, correct me if I am wrong), fitting such a model is to not doable with glm, since the function is not linear."
My reply responded to that.
AFAIK, opinions on packages are off topic here. Try stats.stackexchange.com< http://stats.stackexchange.com> for that.
Bert Gunter
"The trouble with having an open mind is that people keep coming along and sticking things into it."
 Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Tue, Jul 28, 2020 at 8:19 AM Sebastien Bihorel < [hidden email]<mailto: [hidden email]>> wrote:
Thank you for your subtle input, Bert... as usual!
This is literally the search I conducted and spent 2 hours on before posting to Rhelp. I was asking for expert opinions, not for search engine FAQ!
Thank anyways
________________________________
From: Bert Gunter < [hidden email]<mailto: [hidden email]>>
Sent: Tuesday, July 28, 2020 11:12
To: Sebastien Bihorel < [hidden email]<mailto: [hidden email]>>
Cc: [hidden email]<mailto: [hidden email]> < [hidden email]<mailto: [hidden email]>>
Subject: Re: [R] Nonlinear logistic regression fitting
Search!
... for "nonlinear logistic regression" at rseek.org< http://rseek.org>.
Bert Gunter
"The trouble with having an open mind is that people keep coming along and sticking things into it."
 Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Tue, Jul 28, 2020 at 7:25 AM Sebastien Bihorel via Rhelp < [hidden email]<mailto: [hidden email]>> wrote:
Hi
I need to fit a logistic regression model using a saturable MichaelisMenten function of my predictor x. The likelihood could be expressed as:
L = intercept + emax * x / (EC50+x)
Which I guess could be expressed as the following R model
~ emax*x/(ec50+x)
As far as I know (please, correct me if I am wrong), fitting such a model is to not doable with glm, since the function is not linear.
A Stackoverflow post recommends the bnlr function from the gnlm ( https://stackoverflow.com/questions/45362548/nonlinearlogisticregressionpackageinr)... I would be grateful for any opinion on this package or for any alternative recommendation of package/function.
______________________________________________
[hidden email]<mailto: [hidden email]> mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


In reply to this post by R help mailing list2
Did you try searching for "Michaelis" on rseek.org?
It seems like there are many hits that might be pertinent to your query.
If none is pertinent, maybe saying why they are not sufficient will help others see how their "expert opinions" can help you.
HTH,
Chuck
> On Jul 28, 2020, at 8:19 AM, Sebastien Bihorel via Rhelp < [hidden email]> wrote:
>
> Thank you for your subtle input, Bert... as usual!
>
> This is literally the search I conducted and spent 2 hours on before posting to Rhelp. I was asking for expert opinions, not for search engine FAQ!
>
> Thank anyways
>
> ________________________________
> From: Bert Gunter < [hidden email]>
> Sent: Tuesday, July 28, 2020 11:12
> To: Sebastien Bihorel < [hidden email]>
> Cc: [hidden email] < [hidden email]>
> Subject: Re: [R] Nonlinear logistic regression fitting
>
> Search!
> ... for "nonlinear logistic regression" at rseek.org< http://rseek.org>.
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and sticking things into it."
>  Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Tue, Jul 28, 2020 at 7:25 AM Sebastien Bihorel via Rhelp < [hidden email]<mailto: [hidden email]>> wrote:
> Hi
>
> I need to fit a logistic regression model using a saturable MichaelisMenten function of my predictor x. The likelihood could be expressed as:
>
> L = intercept + emax * x / (EC50+x)
>
> Which I guess could be expressed as the following R model
>
> ~ emax*x/(ec50+x)
>
> As far as I know (please, correct me if I am wrong), fitting such a model is to not doable with glm, since the function is not linear.
>
> A Stackoverflow post recommends the bnlr function from the gnlm ( https://stackoverflow.com/questions/45362548/nonlinearlogisticregressionpackageinr)... I would be grateful for any opinion on this package or for any alternative recommendation of package/function.
> ______________________________________________
> [hidden email]<mailto: [hidden email]> mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
>
> [[alternative HTML version deleted]]
>
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


In reply to this post by R help mailing list2
Hello,
glm might not be the right tool for the MM model but nls is meant to fit
nonlinear models.
And, after an online search, there is also package drc, function drm.
I will use the data and examples in the links below. (The second gave me
right, it uses nls.)
#install.packages("drc")
library(drc)
# data
# substrate
S < c(0,1,2,5,8,12,30,50)
# reaction rate
v < c(0,11.1,25.4,44.8,54.5,58.2,72.0,60.1)
kinData < data.frame(S, v)
# package drc fit
# use the two parameter MM model (MM.2)
drm_fit < drm(v ~ S, data = kinData, fct = MM.2())
# nls fit
MMcurve < formula(v ~ Vmax*S/(Km + S))
nls_fit < nls(MMcurve, kinData, start = list(Vmax = 50, Km = 2))
coef(drm_fit)
coef(nls_fit)
# plot
SconcRange < seq(0, 50, 0.1)
nls_Line < predict(nls_fit, list(S = SconcRange))
plot(drm_fit, log = '', pch = 17, col = "red", main = "Fitted MM curve")
lines(SconcRange, nls_Line, col = "blue", lty = "dotted")
[1]
https://davetang.org/muse/2013/05/17/fittingamichaelismentenscurveusing/[2]
http://rforbiochemists.blogspot.com/2015/05/plottingandfittingenzymologydata.htmlHope this helps,
Rui Barradas
Às 15:13 de 28/07/2020, Sebastien Bihorel via Rhelp escreveu:
> Hi
>
> I need to fit a logistic regression model using a saturable MichaelisMenten function of my predictor x. The likelihood could be expressed as:
>
> L = intercept + emax * x / (EC50+x)
>
> Which I guess could be expressed as the following R model
>
> ~ emax*x/(ec50+x)
>
> As far as I know (please, correct me if I am wrong), fitting such a model is to not doable with glm, since the function is not linear.
>
> A Stackoverflow post recommends the bnlr function from the gnlm ( https://stackoverflow.com/questions/45362548/nonlinearlogisticregressionpackageinr)... I would be grateful for any opinion on this package or for any alternative recommendation of package/function.
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.

Este email foi verificado em termos de vírus pelo software antivírus Avast.
https://www.avast.com/antivirus______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Hi Rui,
Thanks for your input.
In my analysis, the MM model is not intended to fit continuous data but must be used within a logistic regression model of binary data. So, while useful in itself, the suggested example does not exactly apply.
I appreciate your time
________________________________
From: Rui Barradas < [hidden email]>
Sent: Tuesday, July 28, 2020 12:42
To: Sebastien Bihorel < [hidden email]>; [hidden email] < [hidden email]>
Subject: Re: [R] Nonlinear logistic regression fitting
Hello,
glm might not be the right tool for the MM model but nls is meant to fit
nonlinear models.
And, after an online search, there is also package drc, function drm.
I will use the data and examples in the links below. (The second gave me
right, it uses nls.)
#install.packages("drc")
library(drc)
# data
# substrate
S < c(0,1,2,5,8,12,30,50)
# reaction rate
v < c(0,11.1,25.4,44.8,54.5,58.2,72.0,60.1)
kinData < data.frame(S, v)
# package drc fit
# use the two parameter MM model (MM.2)
drm_fit < drm(v ~ S, data = kinData, fct = MM.2())
# nls fit
MMcurve < formula(v ~ Vmax*S/(Km + S))
nls_fit < nls(MMcurve, kinData, start = list(Vmax = 50, Km = 2))
coef(drm_fit)
coef(nls_fit)
# plot
SconcRange < seq(0, 50, 0.1)
nls_Line < predict(nls_fit, list(S = SconcRange))
plot(drm_fit, log = '', pch = 17, col = "red", main = "Fitted MM curve")
lines(SconcRange, nls_Line, col = "blue", lty = "dotted")
[1]
https://davetang.org/muse/2013/05/17/fittingamichaelismentenscurveusing/[2]
http://rforbiochemists.blogspot.com/2015/05/plottingandfittingenzymologydata.htmlHope this helps,
Rui Barradas
�s 15:13 de 28/07/2020, Sebastien Bihorel via Rhelp escreveu:
> Hi
>
> I need to fit a logistic regression model using a saturable MichaelisMenten function of my predictor x. The likelihood could be expressed as:
>
> L = intercept + emax * x / (EC50+x)
>
> Which I guess could be expressed as the following R model
>
> ~ emax*x/(ec50+x)
>
> As far as I know (please, correct me if I am wrong), fitting such a model is to not doable with glm, since the function is not linear.
>
> A Stackoverflow post recommends the bnlr function from the gnlm ( https://stackoverflow.com/questions/45362548/nonlinearlogisticregressionpackageinr)... I would be grateful for any opinion on this package or for any alternative recommendation of package/function.
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.

Este email foi verificado em termos de v�rus pelo software antiv�rus Avast.
https://www.avast.com/antivirus [[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Hello,
Glad it can be of help.
Post example data then, like this it's rather difficult to answer
accurately.
Rui Barradas
�s 17:59 de 28/07/2020, Sebastien Bihorel escreveu:
> Hi Rui,
>
> Thanks for your input.
>
> In my analysis, the MM model is not intended to fit continuous data
> but must be used within a logistic regression model of binary data.
> So, while useful in itself, the suggested example does not exactly apply.
>
> I appreciate your time
>
> 
> *From:* Rui Barradas < [hidden email]>
> *Sent:* Tuesday, July 28, 2020 12:42
> *To:* Sebastien Bihorel < [hidden email]>;
> [hidden email] < [hidden email]>
> *Subject:* Re: [R] Nonlinear logistic regression fitting
> Hello,
>
> glm might not be the right tool for the MM model but nls is meant to fit
> nonlinear models.
> And, after an online search, there is also package drc, function drm.
>
> I will use the data and examples in the links below. (The second gave me
> right, it uses nls.)
>
>
> #install.packages("drc")
> library(drc)
>
> # data
>
> # substrate
> S < c(0,1,2,5,8,12,30,50)
>
> # reaction rate
> v < c(0,11.1,25.4,44.8,54.5,58.2,72.0,60.1)
> kinData < data.frame(S, v)
>
>
> # package drc fit
>
> # use the two parameter MM model (MM.2)
> drm_fit < drm(v ~ S, data = kinData, fct = MM.2())
>
> # nls fit
> MMcurve < formula(v ~ Vmax*S/(Km + S))
> nls_fit < nls(MMcurve, kinData, start = list(Vmax = 50, Km = 2))
>
> coef(drm_fit)
> coef(nls_fit)
>
> # plot
>
> SconcRange < seq(0, 50, 0.1)
> nls_Line < predict(nls_fit, list(S = SconcRange))
>
> plot(drm_fit, log = '', pch = 17, col = "red", main = "Fitted MM curve")
> lines(SconcRange, nls_Line, col = "blue", lty = "dotted")
>
>
> [1]
> https://davetang.org/muse/2013/05/17/fittingamichaelismentenscurveusing/> [2]
> http://rforbiochemists.blogspot.com/2015/05/plottingandfittingenzymologydata.html>
>
> Hope this helps,
>
> Rui Barradas
>
> �s 15:13 de 28/07/2020, Sebastien Bihorel via Rhelp escreveu:
> > Hi
> >
> > I need to fit a logistic regression model using a saturable
> MichaelisMenten function of my predictor x. The likelihood could be
> expressed as:
> >
> > L = intercept + emax * x / (EC50+x)
> >
> > Which I guess could be expressed as the following R model
> >
> > ~ emax*x/(ec50+x)
> >
> > As far as I know (please, correct me if I am wrong), fitting such a
> model is to not doable with glm, since the function is not linear.
> >
> > A Stackoverflow post recommends the bnlr function from the gnlm
> ( https://stackoverflow.com/questions/45362548/nonlinearlogisticregressionpackageinr)...
> I would be grateful for any opinion on this package or for any
> alternative recommendation of package/function.
> > ______________________________________________
> > [hidden email] mailing list  To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/rhelp> > PLEASE do read the posting guide
> http://www.Rproject.org/postingguide.html
> < http://www.Rproject.org/postingguide.html>
> > and provide commented, minimal, selfcontained, reproducible code.
>
>
> 
> Este email foi verificado em termos de v�rus pelo software antiv�rus
> Avast.
> https://www.avast.com/antivirus>

Este email foi verificado em termos de v�rus pelo software antiv�rus Avast.
https://www.avast.com/antivirus [[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


In reply to this post by R help mailing list2
Dear Sebastien,
On 20200728 14:13 +0000, Sebastien Bihorel wrote:
 Hi

 I need to fit a logistic regression
 model using a saturable
 MichaelisMenten function of my
 predictor x. The likelihood could be
 expressed as:

 L = intercept + emax * x / (EC50+x)

 Which I guess could be expressed as
 the following R model

 ~ emax*x/(ec50+x)

 As far as I know (please, correct me
 if I am wrong), fitting such a model
 is to not doable with glm, since the
 function is not linear.

 A Stackoverflow post recommends the
 bnlr function from the gnlm
 ( https://stackoverflow.com/questions/45362548/nonlinearlogisticregressionpackageinr)...
 I would be grateful for any opinion on
 this package or for any alternative
 recommendation of package/function.
I found base stats has the function
stats::SSmicmen, also this page[1]
mentions stats::nls ...
I found cardioModel::cardioModel ...
You need Google V8[3] which takes
forever to build.
Also the emaxmodel vignette[4] might be
useful, as it mentions both EC50 and
Emax.
Best,
Rasmus
[1] https://dataconomy.com/2017/08/nonlinearleastsquarenonlinearregressionr/[2] https://www.rdocumentation.org/packages/cardioModel/versions/1.4/topics/cardioModel[3] https://v8.dev/[4] https://cran.rproject.org/web/packages/rstanemax/vignettes/emaxmodel.html______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


In reply to this post by R help mailing list2
There is a large literature on nonlinear logistic models and similar
curves. Some of it is referenced in my 2014 book Nonlinear Parameter
Optimization Using R Tools, which mentions nlxb(), now part of the
nlsr package. If useful, I could put the Bibtex refs for that somewhere.
nls() is now getting long in the tooth. It has a lot of flexibility and
great functionality, but it did very poorly on the Hobbs problem that
rather forced me to develop the codes that are 3/5ths of optim() and
also led to nlsr etc. The Hobbs problem dated from 1974, and with only
12 data points still defeats a majority of nonlinear fit programs.
nls() poops out because it has no LM stabilization and a rather weak
forward difference derivative approximation. nlsr tries to generate
analytic derivatives, which often help when things are very badly scaled.
Another posting suggests an example problem i.e., some data and a
model, though you also need the loss function (e.g., Max likelihood,
weights, etc.). Do post some data and functions so we can provide more
focussed advice.
JN
On 20200728 10:13 a.m., Sebastien Bihorel via Rhelp wrote:
> Hi
>
> I need to fit a logistic regression model using a saturable MichaelisMenten function of my predictor x. The likelihood could be expressed as:
>
> L = intercept + emax * x / (EC50+x)
>
> Which I guess could be expressed as the following R model
>
> ~ emax*x/(ec50+x)
>
> As far as I know (please, correct me if I am wrong), fitting such a model is to not doable with glm, since the function is not linear.
>
> A Stackoverflow post recommends the bnlr function from the gnlm ( https://stackoverflow.com/questions/45362548/nonlinearlogisticregressionpackageinr)... I would be grateful for any opinion on this package or for any alternative recommendation of package/function.
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
>
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Thank your, Pr. Nash, for your perspective on the issue.
Here is an example of binary data/response (resp) that were simulated and reestimated assuming a non linear effect of the predictor (x) on the likelihood of response. For reestimation, I have used gnlm::bnlr for the logistic regression. The accuracy of the parameter estimates is soso, probably due to the low number of data points (8*nx). For illustration, I have also include a glm call to an incorrect linear model of x.
#install.packages(gnlm)
#require(gnlm)
set.seed(12345)
nx < 10
x < c(
rep(0, 3*nx),
rep(c(10, 30, 100, 500, 1000), each = nx)
)
rnd < runif(length(x))
a < log(0.2/(10.2))
b < log(0.7/(10.7))  a
c < 30
likelihood < a + b*x/(c+x)
p < exp(likelihood) / (1 + exp(likelihood))
resp < ifelse(rnd <= p, 1, 0)
df < data.frame(
x = x,
resp = resp,
nresp = 1 resp
)
head(df)
# glm can only assume linear effect of x, which is the wrong model
glm_mod < glm(
resp~x,
data = df,
family = 'binomial'
)
glm_mod
# Using gnlm package, estimate a model model with just intercept, and a model with predictor effect
int_mod < gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a, pmu = c(a) )
emax_mod < gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a + p_b*x/(p_c+x), pmu = c(a, b, c) )
int_mod
emax_mod
________________________________
From: J C Nash < [hidden email]>
Sent: Tuesday, July 28, 2020 14:16
To: Sebastien Bihorel < [hidden email]>; [hidden email] < [hidden email]>
Subject: Re: [R] Nonlinear logistic regression fitting
There is a large literature on nonlinear logistic models and similar
curves. Some of it is referenced in my 2014 book Nonlinear Parameter
Optimization Using R Tools, which mentions nlxb(), now part of the
nlsr package. If useful, I could put the Bibtex refs for that somewhere.
nls() is now getting long in the tooth. It has a lot of flexibility and
great functionality, but it did very poorly on the Hobbs problem that
rather forced me to develop the codes that are 3/5ths of optim() and
also led to nlsr etc. The Hobbs problem dated from 1974, and with only
12 data points still defeats a majority of nonlinear fit programs.
nls() poops out because it has no LM stabilization and a rather weak
forward difference derivative approximation. nlsr tries to generate
analytic derivatives, which often help when things are very badly scaled.
Another posting suggests an example problem i.e., some data and a
model, though you also need the loss function (e.g., Max likelihood,
weights, etc.). Do post some data and functions so we can provide more
focussed advice.
JN
On 20200728 10:13 a.m., Sebastien Bihorel via Rhelp wrote:
> Hi
>
> I need to fit a logistic regression model using a saturable MichaelisMenten function of my predictor x. The likelihood could be expressed as:
>
> L = intercept + emax * x / (EC50+x)
>
> Which I guess could be expressed as the following R model
>
> ~ emax*x/(ec50+x)
>
> As far as I know (please, correct me if I am wrong), fitting such a model is to not doable with glm, since the function is not linear.
>
> A Stackoverflow post recommends the bnlr function from the gnlm ( https://stackoverflow.com/questions/45362548/nonlinearlogisticregressionpackageinr)... I would be grateful for any opinion on this package or for any alternative recommendation of package/function.
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


My earlier posting on this thread was misleading. I thought the OP was trying to
fit a sigmoid to data. The problem is about fitting 0,1 responses.
The reproducible example cleared this up. Another strong demonstration that
a "simple reproducible example" can bring clarity so much more quickly than
general discussion.
JN
On 20200729 8:56 a.m., Sebastien Bihorel wrote:
> #install.packages(gnlm)
> #require(gnlm)
> set.seed(12345)
>
> nx < 10
> x < c(
> rep(0, 3*nx),
> rep(c(10, 30, 100, 500, 1000), each = nx)
> )
> rnd < runif(length(x))
> a < log(0.2/(10.2))
> b < log(0.7/(10.7))  a
> c < 30
> likelihood < a + b*x/(c+x)
> p < exp(likelihood) / (1 + exp(likelihood))
> resp < ifelse(rnd <= p, 1, 0)
>
> df < data.frame(
> x = x,
> resp = resp,
> nresp = 1 resp
> )
>
> head(df)
>
> # glm can only assume linear effect of x, which is the wrong model
> glm_mod < glm(
> resp~x,
> data = df,
> family = 'binomial'
> )
> glm_mod
>
> # Using gnlm package, estimate a model model with just intercept, and a model with predictor effect
> int_mod < gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a, pmu = c(a) )
> emax_mod < gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a + p_b*x/(p_c+x), pmu = c(a, b, c) )
>
> int_mod
> emax_mod
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


In reply to this post by R help mailing list2
Just a quick note about jargon: you are using the word "likelihood" in
a way that I (and maybe some others) find confusing. (In fact, I think
you used it two different ways, but maybe I'm just confused.) I would
say that likelihood is the probability of observing the entire data set,
considered as a function of the parameters. You appear to be using it
(at first) as the probability that a particular observation is equal to
1, and then as the argument to a logit function to give that probability.
What you probably want to do is find the parameters that maximize the
likelihood (in my sense). The usual practice is to maximize the log of
the likelihood; it tends to be easier to work with. In your notation
below, the log likelihood would be
loglik < sum( resp*log(p) + (1resp)*log1p(p) )
When you have a linear logistic regression model, this simplifies a bit,
and there are fast algorithms that are usually stable to optimize it.
With a nonlinear model, you lose some of that, and I'd suggest directly
optimizing it.
Duncan Murdoch
On 29/07/2020 8:56 a.m., Sebastien Bihorel via Rhelp wrote:
> Thank your, Pr. Nash, for your perspective on the issue.
>
> Here is an example of binary data/response (resp) that were simulated and reestimated assuming a non linear effect of the predictor (x) on the likelihood of response. For reestimation, I have used gnlm::bnlr for the logistic regression. The accuracy of the parameter estimates is soso, probably due to the low number of data points (8*nx). For illustration, I have also include a glm call to an incorrect linear model of x.
>
> #install.packages(gnlm)
> #require(gnlm)
> set.seed(12345)
>
> nx < 10
> x < c(
> rep(0, 3*nx),
> rep(c(10, 30, 100, 500, 1000), each = nx)
> )
> rnd < runif(length(x))
> a < log(0.2/(10.2))
> b < log(0.7/(10.7))  a
> c < 30
> likelihood < a + b*x/(c+x)
> p < exp(likelihood) / (1 + exp(likelihood))
> resp < ifelse(rnd <= p, 1, 0)
>
> df < data.frame(
> x = x,
> resp = resp,
> nresp = 1 resp
> )
>
> head(df)
>
> # glm can only assume linear effect of x, which is the wrong model
> glm_mod < glm(
> resp~x,
> data = df,
> family = 'binomial'
> )
> glm_mod
>
> # Using gnlm package, estimate a model model with just intercept, and a model with predictor effect
> int_mod < gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a, pmu = c(a) )
> emax_mod < gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a + p_b*x/(p_c+x), pmu = c(a, b, c) )
>
> int_mod
> emax_mod
>
> ________________________________
> From: J C Nash < [hidden email]>
> Sent: Tuesday, July 28, 2020 14:16
> To: Sebastien Bihorel < [hidden email]>; [hidden email] < [hidden email]>
> Subject: Re: [R] Nonlinear logistic regression fitting
>
> There is a large literature on nonlinear logistic models and similar
> curves. Some of it is referenced in my 2014 book Nonlinear Parameter
> Optimization Using R Tools, which mentions nlxb(), now part of the
> nlsr package. If useful, I could put the Bibtex refs for that somewhere.
>
> nls() is now getting long in the tooth. It has a lot of flexibility and
> great functionality, but it did very poorly on the Hobbs problem that
> rather forced me to develop the codes that are 3/5ths of optim() and
> also led to nlsr etc. The Hobbs problem dated from 1974, and with only
> 12 data points still defeats a majority of nonlinear fit programs.
> nls() poops out because it has no LM stabilization and a rather weak
> forward difference derivative approximation. nlsr tries to generate
> analytic derivatives, which often help when things are very badly scaled.
>
> Another posting suggests an example problem i.e., some data and a
> model, though you also need the loss function (e.g., Max likelihood,
> weights, etc.). Do post some data and functions so we can provide more
> focussed advice.
>
> JN
>
> On 20200728 10:13 a.m., Sebastien Bihorel via Rhelp wrote:
>> Hi
>>
>> I need to fit a logistic regression model using a saturable MichaelisMenten function of my predictor x. The likelihood could be expressed as:
>>
>> L = intercept + emax * x / (EC50+x)
>>
>> Which I guess could be expressed as the following R model
>>
>> ~ emax*x/(ec50+x)
>>
>> As far as I know (please, correct me if I am wrong), fitting such a model is to not doable with glm, since the function is not linear.
>>
>> A Stackoverflow post recommends the bnlr function from the gnlm ( https://stackoverflow.com/questions/45362548/nonlinearlogisticregressionpackageinr)... I would be grateful for any opinion on this package or for any alternative recommendation of package/function.
>> ______________________________________________
>> [hidden email] mailing list  To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/rhelp>> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html>> and provide commented, minimal, selfcontained, reproducible code.
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
>
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Thanks Duncan,
People working in my field are frequently (and rightly) accused of butchering statistical terminology. So I guess I'm guilty as charged 😄
I will look into the suggested path. One question though in your expression:
loglik < sum( resp*log(p) + (1resp)*log1p(p) )
a + b*x/(c+x)
________________________________
From: Duncan Murdoch < [hidden email]>
Sent: Wednesday, July 29, 2020 16:04
To: Sebastien Bihorel < [hidden email]>; J C Nash < [hidden email]>; [hidden email] < [hidden email]>
Subject: Re: [R] Nonlinear logistic regression fitting
Just a quick note about jargon: you are using the word "likelihood" in
a way that I (and maybe some others) find confusing. (In fact, I think
you used it two different ways, but maybe I'm just confused.) I would
say that likelihood is the probability of observing the entire data set,
considered as a function of the parameters. You appear to be using it
(at first) as the probability that a particular observation is equal to
1, and then as the argument to a logit function to give that probability.
What you probably want to do is find the parameters that maximize the
likelihood (in my sense). The usual practice is to maximize the log of
the likelihood; it tends to be easier to work with. In your notation
below, the log likelihood would be
loglik < sum( resp*log(p) + (1resp)*log1p(p) )
When you have a linear logistic regression model, this simplifies a bit,
and there are fast algorithms that are usually stable to optimize it.
With a nonlinear model, you lose some of that, and I'd suggest directly
optimizing it.
Duncan Murdoch
On 29/07/2020 8:56 a.m., Sebastien Bihorel via Rhelp wrote:
> Thank your, Pr. Nash, for your perspective on the issue.
>
> Here is an example of binary data/response (resp) that were simulated and reestimated assuming a non linear effect of the predictor (x) on the likelihood of response. For reestimation, I have used gnlm::bnlr for the logistic regression. The accuracy of the parameter estimates is soso, probably due to the low number of data points (8*nx). For illustration, I have also include a glm call to an incorrect linear model of x.
>
> #install.packages(gnlm)
> #require(gnlm)
> set.seed(12345)
>
> nx < 10
> x < c(
> rep(0, 3*nx),
> rep(c(10, 30, 100, 500, 1000), each = nx)
> )
> rnd < runif(length(x))
> a < log(0.2/(10.2))
> b < log(0.7/(10.7))  a
> c < 30
> likelihood < a + b*x/(c+x)
> p < exp(likelihood) / (1 + exp(likelihood))
> resp < ifelse(rnd <= p, 1, 0)
>
> df < data.frame(
> x = x,
> resp = resp,
> nresp = 1 resp
> )
>
> head(df)
>
> # glm can only assume linear effect of x, which is the wrong model
> glm_mod < glm(
> resp~x,
> data = df,
> family = 'binomial'
> )
> glm_mod
>
> # Using gnlm package, estimate a model model with just intercept, and a model with predictor effect
> int_mod < gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a, pmu = c(a) )
> emax_mod < gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a + p_b*x/(p_c+x), pmu = c(a, b, c) )
>
> int_mod
> emax_mod
>
> ________________________________
> From: J C Nash < [hidden email]>
> Sent: Tuesday, July 28, 2020 14:16
> To: Sebastien Bihorel < [hidden email]>; [hidden email] < [hidden email]>
> Subject: Re: [R] Nonlinear logistic regression fitting
>
> There is a large literature on nonlinear logistic models and similar
> curves. Some of it is referenced in my 2014 book Nonlinear Parameter
> Optimization Using R Tools, which mentions nlxb(), now part of the
> nlsr package. If useful, I could put the Bibtex refs for that somewhere.
>
> nls() is now getting long in the tooth. It has a lot of flexibility and
> great functionality, but it did very poorly on the Hobbs problem that
> rather forced me to develop the codes that are 3/5ths of optim() and
> also led to nlsr etc. The Hobbs problem dated from 1974, and with only
> 12 data points still defeats a majority of nonlinear fit programs.
> nls() poops out because it has no LM stabilization and a rather weak
> forward difference derivative approximation. nlsr tries to generate
> analytic derivatives, which often help when things are very badly scaled.
>
> Another posting suggests an example problem i.e., some data and a
> model, though you also need the loss function (e.g., Max likelihood,
> weights, etc.). Do post some data and functions so we can provide more
> focussed advice.
>
> JN
>
> On 20200728 10:13 a.m., Sebastien Bihorel via Rhelp wrote:
>> Hi
>>
>> I need to fit a logistic regression model using a saturable MichaelisMenten function of my predictor x. The likelihood could be expressed as:
>>
>> L = intercept + emax * x / (EC50+x)
>>
>> Which I guess could be expressed as the following R model
>>
>> ~ emax*x/(ec50+x)
>>
>> As far as I know (please, correct me if I am wrong), fitting such a model is to not doable with glm, since the function is not linear.
>>
>> A Stackoverflow post recommends the bnlr function from the gnlm ( https://stackoverflow.com/questions/45362548/nonlinearlogisticregressionpackageinr)... I would be grateful for any opinion on this package or for any alternative recommendation of package/function.
>> ______________________________________________
>> [hidden email] mailing list  To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/rhelp>> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html>> and provide commented, minimal, selfcontained, reproducible code.
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


Thanks Duncan,
(Sorry for the repeated email)
People working in my field are frequently (and rightly) accused of butchering statistical terminology. So I guess I'm guilty as charged 😄
I will look into the suggested path. One question though in your expression of loglik, p is "a + b*x/(c+x)". Correct?
Thanks
________________________________
From: Duncan Murdoch < [hidden email]>
Sent: Wednesday, July 29, 2020 16:04
To: Sebastien Bihorel < [hidden email]>; J C Nash < [hidden email]>; [hidden email] < [hidden email]>
Subject: Re: [R] Nonlinear logistic regression fitting
Just a quick note about jargon: you are using the word "likelihood" in
a way that I (and maybe some others) find confusing. (In fact, I think
you used it two different ways, but maybe I'm just confused.) I would
say that likelihood is the probability of observing the entire data set,
considered as a function of the parameters. You appear to be using it
(at first) as the probability that a particular observation is equal to
1, and then as the argument to a logit function to give that probability.
What you probably want to do is find the parameters that maximize the
likelihood (in my sense). The usual practice is to maximize the log of
the likelihood; it tends to be easier to work with. In your notation
below, the log likelihood would be
loglik < sum( resp*log(p) + (1resp)*log1p(p) )
When you have a linear logistic regression model, this simplifies a bit,
and there are fast algorithms that are usually stable to optimize it.
With a nonlinear model, you lose some of that, and I'd suggest directly
optimizing it.
Duncan Murdoch
On 29/07/2020 8:56 a.m., Sebastien Bihorel via Rhelp wrote:
> Thank your, Pr. Nash, for your perspective on the issue.
>
> Here is an example of binary data/response (resp) that were simulated and reestimated assuming a non linear effect of the predictor (x) on the likelihood of response. For reestimation, I have used gnlm::bnlr for the logistic regression. The accuracy of the parameter estimates is soso, probably due to the low number of data points (8*nx). For illustration, I have also include a glm call to an incorrect linear model of x.
>
> #install.packages(gnlm)
> #require(gnlm)
> set.seed(12345)
>
> nx < 10
> x < c(
> rep(0, 3*nx),
> rep(c(10, 30, 100, 500, 1000), each = nx)
> )
> rnd < runif(length(x))
> a < log(0.2/(10.2))
> b < log(0.7/(10.7))  a
> c < 30
> likelihood < a + b*x/(c+x)
> p < exp(likelihood) / (1 + exp(likelihood))
> resp < ifelse(rnd <= p, 1, 0)
>
> df < data.frame(
> x = x,
> resp = resp,
> nresp = 1 resp
> )
>
> head(df)
>
> # glm can only assume linear effect of x, which is the wrong model
> glm_mod < glm(
> resp~x,
> data = df,
> family = 'binomial'
> )
> glm_mod
>
> # Using gnlm package, estimate a model model with just intercept, and a model with predictor effect
> int_mod < gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a, pmu = c(a) )
> emax_mod < gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a + p_b*x/(p_c+x), pmu = c(a, b, c) )
>
> int_mod
> emax_mod
>
> ________________________________
> From: J C Nash < [hidden email]>
> Sent: Tuesday, July 28, 2020 14:16
> To: Sebastien Bihorel < [hidden email]>; [hidden email] < [hidden email]>
> Subject: Re: [R] Nonlinear logistic regression fitting
>
> There is a large literature on nonlinear logistic models and similar
> curves. Some of it is referenced in my 2014 book Nonlinear Parameter
> Optimization Using R Tools, which mentions nlxb(), now part of the
> nlsr package. If useful, I could put the Bibtex refs for that somewhere.
>
> nls() is now getting long in the tooth. It has a lot of flexibility and
> great functionality, but it did very poorly on the Hobbs problem that
> rather forced me to develop the codes that are 3/5ths of optim() and
> also led to nlsr etc. The Hobbs problem dated from 1974, and with only
> 12 data points still defeats a majority of nonlinear fit programs.
> nls() poops out because it has no LM stabilization and a rather weak
> forward difference derivative approximation. nlsr tries to generate
> analytic derivatives, which often help when things are very badly scaled.
>
> Another posting suggests an example problem i.e., some data and a
> model, though you also need the loss function (e.g., Max likelihood,
> weights, etc.). Do post some data and functions so we can provide more
> focussed advice.
>
> JN
>
> On 20200728 10:13 a.m., Sebastien Bihorel via Rhelp wrote:
>> Hi
>>
>> I need to fit a logistic regression model using a saturable MichaelisMenten function of my predictor x. The likelihood could be expressed as:
>>
>> L = intercept + emax * x / (EC50+x)
>>
>> Which I guess could be expressed as the following R model
>>
>> ~ emax*x/(ec50+x)
>>
>> As far as I know (please, correct me if I am wrong), fitting such a model is to not doable with glm, since the function is not linear.
>>
>> A Stackoverflow post recommends the bnlr function from the gnlm ( https://stackoverflow.com/questions/45362548/nonlinearlogisticregressionpackageinr)... I would be grateful for any opinion on this package or for any alternative recommendation of package/function.
>> ______________________________________________
>> [hidden email] mailing list  To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/rhelp>> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html>> and provide commented, minimal, selfcontained, reproducible code.
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list  To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/rhelp> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html> and provide commented, minimal, selfcontained, reproducible code.
>
[[alternative HTML version deleted]]
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.


On 29/07/2020 4:16 p.m., Sebastien Bihorel wrote:
> Thanks Duncan,
>
> (Sorry for the repeated email)
>
> People working in my field are frequently (and rightly) accused of
> butchering statistical terminology. So I guess I'm guilty as charged 😄
>
> I will look into the suggested path. One question though in your
> expression of loglik, p is "a + b*x/(c+x)". Correct?
p should be the probability of observing 1, so I would guess it is what
you calculated below, i.e. exp(likelihood)/(1 + exp(likelihood)) (in
your notation, not mine).
Duncan Murdoch
>
> Thanks
>
> 
> *From:* Duncan Murdoch < [hidden email]>
> *Sent:* Wednesday, July 29, 2020 16:04
> *To:* Sebastien Bihorel < [hidden email]>; J C Nash
> < [hidden email]>; [hidden email] < [hidden email]>
> *Subject:* Re: [R] Nonlinear logistic regression fitting
> Just a quick note about jargon: you are using the word "likelihood" in
> a way that I (and maybe some others) find confusing. (In fact, I think
> you used it two different ways, but maybe I'm just confused.) I would
> say that likelihood is the probability of observing the entire data set,
> considered as a function of the parameters. You appear to be using it
> (at first) as the probability that a particular observation is equal to
> 1, and then as the argument to a logit function to give that probability.
>
> What you probably want to do is find the parameters that maximize the
> likelihood (in my sense). The usual practice is to maximize the log of
> the likelihood; it tends to be easier to work with. In your notation
> below, the log likelihood would be
>
> loglik < sum( resp*log(p) + (1resp)*log1p(p) )
>
> When you have a linear logistic regression model, this simplifies a bit,
> and there are fast algorithms that are usually stable to optimize it.
> With a nonlinear model, you lose some of that, and I'd suggest directly
> optimizing it.
>
> Duncan Murdoch
>
> On 29/07/2020 8:56 a.m., Sebastien Bihorel via Rhelp wrote:
>> Thank your, Pr. Nash, for your perspective on the issue.
>>
>> Here is an example of binary data/response (resp) that were simulated and reestimated assuming a non linear effect of the predictor (x) on the likelihood of response. For reestimation, I have used gnlm::bnlr for the logistic regression. The accuracy of the parameter estimates is soso, probably due to the low number of
> data points (8*nx). For illustration, I have also include a glm call to
> an incorrect linear model of x.
>>
>> #install.packages(gnlm)
>> #require(gnlm)
>> set.seed(12345)
>>
>> nx < 10
>> x < c(
>> rep(0, 3*nx),
>> rep(c(10, 30, 100, 500, 1000), each = nx)
>> )
>> rnd < runif(length(x))
>> a < log(0.2/(10.2))
>> b < log(0.7/(10.7))  a
>> c < 30
>> likelihood < a + b*x/(c+x)
>> p < exp(likelihood) / (1 + exp(likelihood))
>> resp < ifelse(rnd <= p, 1, 0)
>>
>> df < data.frame(
>> x = x,
>> resp = resp,
>> nresp = 1 resp
>> )
>>
>> head(df)
>>
>> # glm can only assume linear effect of x, which is the wrong model
>> glm_mod < glm(
>> resp~x,
>> data = df,
>> family = 'binomial'
>> )
>> glm_mod
>>
>> # Using gnlm package, estimate a model model with just intercept, and a model with predictor effect
>> int_mod < gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a, pmu = c(a) )
>> emax_mod < gnlm::bnlr( y = df[,2:3], link = 'logit', mu = ~ p_a + p_b*x/(p_c+x), pmu = c(a, b, c) )
>>
>> int_mod
>> emax_mod
>>
>> ________________________________
>> From: J C Nash < [hidden email]>
>> Sent: Tuesday, July 28, 2020 14:16
>> To: Sebastien Bihorel < [hidden email]>; [hidden email] < [hidden email]>
>> Subject: Re: [R] Nonlinear logistic regression fitting
>>
>> There is a large literature on nonlinear logistic models and similar
>> curves. Some of it is referenced in my 2014 book Nonlinear Parameter
>> Optimization Using R Tools, which mentions nlxb(), now part of the
>> nlsr package. If useful, I could put the Bibtex refs for that somewhere.
>>
>> nls() is now getting long in the tooth. It has a lot of flexibility and
>> great functionality, but it did very poorly on the Hobbs problem that
>> rather forced me to develop the codes that are 3/5ths of optim() and
>> also led to nlsr etc. The Hobbs problem dated from 1974, and with only
>> 12 data points still defeats a majority of nonlinear fit programs.
>> nls() poops out because it has no LM stabilization and a rather weak
>> forward difference derivative approximation. nlsr tries to generate
>> analytic derivatives, which often help when things are very badly scaled.
>>
>> Another posting suggests an example problem i.e., some data and a
>> model, though you also need the loss function (e.g., Max likelihood,
>> weights, etc.). Do post some data and functions so we can provide more
>> focussed advice.
>>
>> JN
>>
>> On 20200728 10:13 a.m., Sebastien Bihorel via Rhelp wrote:
>>> Hi
>>>
>>> I need to fit a logistic regression model using a saturable MichaelisMenten function of my predictor x. The likelihood could be expressed as:
>>>
>>> L = intercept + emax * x / (EC50+x)
>>>
>>> Which I guess could be expressed as the following R model
>>>
>>> ~ emax*x/(ec50+x)
>>>
>>> As far as I know (please, correct me if I am wrong), fitting such a model is to not doable with glm, since the function is not linear.
>>>
>>> A Stackoverflow post recommends the bnlr function from the gnlm ( https://stackoverflow.com/questions/45362548/nonlinearlogisticregressionpackageinr)...
> I would be grateful for any opinion on this package or for any
> alternative recommendation of package/function.
>>> ______________________________________________
>>> [hidden email] mailing list  To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/rhelp>>> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html>>> and provide commented, minimal, selfcontained, reproducible code.
>>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] mailing list  To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/rhelp>> PLEASE do read the posting guide http://www.Rproject.org/postingguide.html>> and provide commented, minimal, selfcontained, reproducible code.
>>
>
______________________________________________
[hidden email] mailing list  To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/rhelpPLEASE do read the posting guide http://www.Rproject.org/postingguide.htmland provide commented, minimal, selfcontained, reproducible code.

