1

I'm working through some textbook exercises on fitting models to data, including exponential, logarithmic and now logistic regression.

About a 3rd of the way down this page is the section on logistic regression. Using a model of the form $y=\frac{c}{1+ae^{-bx}}$ we have to fit a logistic model.

I'm using R and any searching for logistic regression in r returns results about binary classification whereas here I'm seeking a numerical result based on a logistic curve.

For the 'try it' exercise #3 on the page I linked to above, a data frame is provided:

ti3_df <- data.frame(
  x = 0:15,
  y = c(3.493, 5.282, 6.357, 9.201, 11.224, 12.964, 16.226, 18.137,
        19.590, 21.955, 22.862, 23.869, 24.243, 24.344, 24.919, 25.108)
)

Along with the question:

Let x represent time in years starting with x=0 for the year 1997. Let  y  represent the number of seals in thousands. Use logistic regression to fit a model to these data.

How can I do this in R?


(Incase someone asks, 'why not just write a custom function based on the model definition above?', I would like to and that's what I'm building to because I don't fully understand how to do that 'by hand' at this stage. My initial goal is to get a result with an out of the box function in r before trying to recreate it myself with a custom function)

Doug Fir
  • 1,218
  • 1
  • 13
  • 27
  • 3
    This is **not** a logistic regression, it is a nonlinear regression with a logistic/logit response. See for instance https://stats.stackexchange.com/questions/47802/whats-the-most-pain-free-way-to-fit-logistic-growth-curves-in-r, https://stats.stackexchange.com/questions/67049/non-linear-mixed-effects-regression-in-r. Please edit title & tags, and explain beter your applied context! – kjetil b halvorsen Mar 18 '21 at 11:45
  • 1
    I find it really interesting that both the links you shared refer to Google issues finding a solution here "This isn't as easy to Google as some other things as" and "Surprisingly, I was unable to find an answer to the following question using Google". Then, in my own post "... any searching for logistic regression in r returns results about binary classification ". All 3 of us had search engine issues with this one! Stack Exchange Google indexing is pretty strong, maybe there's merit in leaving these tags and title as is for anyone struggling with this search term@kjetilbhalvorsen – Doug Fir Mar 18 '21 at 12:20
  • Also, if it's not a logistic regression, someone should tell the authors of my textbook! They titled the exercise 'Using Logistic Regression to Fit a Model to Data' (Example 3 and 'Try it #3) here https://openstax.org/books/algebra-and-trigonometry/pages/6-8-fitting-exponential-models-to-data – Doug Fir Mar 18 '21 at 12:24
  • The second link is for mixed effects modeling, quite a step away from what my question is about. I think the folk on this forum sometimes have blind spots where it's easy to forget what it's like trying to learn from the beginning. – Doug Fir Mar 18 '21 at 12:34
  • 2
    You have many good points. I was also surprised that I needed longer than usual to find those linked posts ... Probably the use of *logistic regression* in the binary generalized linear model sense so overshadows the use as a logistic growth curve*. *That* is a good search term: [stored search](https://stats.stackexchange.com/search?q=logist*+growth+answers%3A1). For R examples add R to that search. Another search term is *sigmoid* and the tags [tag:sigmoid-curve], [tag:logistic-curve], [tag:growth-model] . Do you find answer to your Q in this links? – kjetil b halvorsen Mar 18 '21 at 13:03
  • 2
    I am with @kjetilbhalvorsen that the authors are using poor terminology. Perhaps that could have been called "logistic regression" when the term first got assigned to a method (that could be defended), but now, "logistic regression" means a binomial response variable. – Dave Mar 18 '21 at 13:28
  • I think the first link has it with `nls(density ~ SSlogis(log(conc), Asym, xmid, scal), + DNase1)` – Doug Fir Mar 18 '21 at 13:46
  • 1
    I do not know what you mean by v4 of R but when I fire up R 4.0.3 and type ?nls it opens the help page for nls for me. – mdewey Mar 18 '21 at 14:13
  • 1
    We have a great many examples of fitting nonlinear functions using `R`. Look at these search results: https://stats.stackexchange.com/search?q=nls+fit+exp. The duplicates give three different solutions in `R` for your logistic model, but there are many more answers whose solutions can be directly applied. – whuber Mar 19 '21 at 13:42

0 Answers0