How can I fit a logistic regression curve to population data?

28 views (last 30 days)
I am currently trying to fit a logistic curve to my population data. The purpose of this is so that I can be able to extrapolate and forecast out 20 years using the fitted logistic curve. I found the glmfit function, but it will not work unless y is a two column matrix. The only y data I have is the population per year. How do I use this function with my type of data? Can I even use this function? If not, how do I fit a logistic curve to my data? Here is an example of my data: x=[2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014] y=[9749,9789,9862,9877,9950,10087,10222,10349,10498,10553,10592,10646,10793,10914,11069]

Answers (2)

Torsten
Torsten on 5 Aug 2015
Use
x=[1 2 3 4 5 6 7 8 9 10 11 12 13 14]
y=func(x)
with
func(x)=K*9749*exp(r*x)./(K+9749*(exp(r*x)-1))
K and r are the parameters to be fitted.
https://en.wikipedia.org/wiki/Logistic_function
subsection "modeling population growth".
Best wishes
Torsten.
  3 Comments
Torsten
Torsten on 6 Aug 2015
Please show the relevant part of the code you are using.
Best wishes
Torsten.
Gianna Damiano
Gianna Damiano on 20 Aug 2015
x=[1 2 3 4 5 6 7 8 9 10 11 12 13 14]
func(x)=K*9749*exp(r*x)./(k+9749*(exp(r*x)-1))
y=func(x)

Sign in to comment.


Torsten
Torsten on 21 Aug 2015
xdata=[1 2 3 4 5 6 7 8 9 10 11 12 13 14];
ydata=[9789 9862 9877 9950 10087 10222 10349 10498 10553 10592 10646 10793 10914 11069];
x0=[1 ; 0.1];
fun=@(x,xdata)x(1)*9749*exp(x(2)*xdata)./(x(1)+9749*(exp(x(2)*xdata)-1))
[x,resnorm] = lsqcurvefit(fun,x0,xdata,ydata);
Best wishes
Torsten.

Categories

Find more on Biological and Health Sciences in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!