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.
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 < r-help at r-project.org> 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. > ______________________________________________ > R-help at r-project.org 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]]
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 <bgunter.4567 at gmail.com> Sent: Tuesday, July 28, 2020 11:12 To: Sebastien Bihorel <Sebastien.Bihorel at cognigencorp.com> Cc: r-help at r-project.org <r-help at r-project.org> 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 R-help <r-help at r-project.org<mailto:r-help at r-project.org>> 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. ______________________________________________ R-help at r-project.org<mailto:R-help at r-project.org> 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]]
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.html Hope 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. > ______________________________________________ > R-help at r-project.org 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
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 <ruipbarradas at sapo.pt> Sent: Tuesday, July 28, 2020 12:42 To: Sebastien Bihorel <Sebastien.Bihorel at cognigencorp.com>; r-help at r-project.org <r-help at r-project.org> 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 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.html Hope 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. > ______________________________________________ > R-help at r-project.org 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 [[alternative HTML version deleted]]
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
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. > ______________________________________________ > R-help at r-project.org 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. >
Thank your, Pr. Nash, for your perspective on the issue. Here is an example of binary data/response (resp) that were simulated and re-estimated assuming a non linear effect of the predictor (x) on the likelihood of response. For re-estimation, I have used gnlm::bnlr for the logistic regression. The accuracy of the parameter estimates is so-so, 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/(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 ________________________________ From: J C Nash <profjcnash at gmail.com> Sent: Tuesday, July 28, 2020 14:16 To: Sebastien Bihorel <Sebastien.Bihorel at cognigencorp.com>; r-help at r-project.org <r-help at r-project.org> 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 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. > ______________________________________________ > R-help at r-project.org 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]]