Nonlinear logistic regression fitting

17 messages
Open this post in threaded view
|

Nonlinear logistic regression fitting

 Hi I need to fit a logistic regression model using a saturable Michaelis-Menten 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/nonlinear-logistic-regression-package-in-r)... 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/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: 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 R-help < [hidden email]> wrote: > Hi > > I need to fit a logistic regression model using a saturable > Michaelis-Menten 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/nonlinear-logistic-regression-package-in-r)... > 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/r-help> PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. >         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: Nonlinear logistic regression fitting

 Thank you for your subtle input, Bert... as usual! This is literally the search I conducted and spent 2 hours on before posting to R-help. 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 R-help <[hidden email]> wrote: Hi I need to fit a logistic regression model using a saturable Michaelis-Menten 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/nonlinear-logistic-regression-package-in-r)... 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/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: 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 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 R-help. 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 R-help < > [hidden email]> wrote: > > Hi > > I need to fit a logistic regression model using a saturable > Michaelis-Menten 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/nonlinear-logistic-regression-package-in-r)... > 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/r-help> PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. > >         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: Nonlinear logistic regression fitting

Open this post in threaded view
|

Re: Nonlinear logistic regression fitting

Open this post in threaded view
|

Re: Nonlinear logistic regression fitting

 In reply to this post by R help mailing list-2 Hello, glm might not be the right tool for the MM model but nls is meant to fit non-linear models. And, after an on-line 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/fitting-a-michaelis-mentens-curve-using/[2] http://rforbiochemists.blogspot.com/2015/05/plotting-and-fitting-enzymology-data.htmlHope this helps, Rui Barradas Às 15:13 de 28/07/2020, Sebastien Bihorel via R-help escreveu: > Hi > > I need to fit a logistic regression model using a saturable Michaelis-Menten 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/nonlinear-logistic-regression-package-in-r)... 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/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. -- Este e-mail 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/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: Nonlinear logistic regression fitting

Open this post in threaded view
|

Re: Nonlinear logistic regression fitting

Open this post in threaded view
|

Re: Nonlinear logistic regression fitting

 In reply to this post by R help mailing list-2 Dear Sebastien, On 2020-07-28 14:13 +0000, Sebastien Bihorel wrote: | Hi | | I need to fit a logistic regression | model using a saturable | Michaelis-Menten 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/nonlinear-logistic-regression-package-in-r)... | 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/nonlinear-least-square-nonlinear-regression-r/[2] https://www.rdocumentation.org/packages/cardioModel/versions/1.4/topics/cardioModel[3] https://v8.dev/[4] https://cran.r-project.org/web/packages/rstanemax/vignettes/emaxmodel.html______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: Nonlinear logistic regression fitting

 In reply to this post by R help mailing list-2 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 2020-07-28 10:13 a.m., Sebastien Bihorel via R-help wrote: > Hi > > I need to fit a logistic regression model using a saturable Michaelis-Menten 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/nonlinear-logistic-regression-package-in-r)... 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/r-help> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: Nonlinear logistic regression fitting

Open this post in threaded view
|

Re: Nonlinear logistic regression fitting

 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 2020-07-29 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/(1-0.2)) > b <- log(0.7/(1-0.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/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

Re: Nonlinear logistic regression fitting

Open this post in threaded view
|

Re: Nonlinear logistic regression fitting

Open this post in threaded view
|

Re: Nonlinear logistic regression fitting

Open this post in threaded view
|