0
$\begingroup$

I updated the data which is a table I deleted the first coordinate as it was the quote from the document.

p=Import["Dos.xlsx"][[1]];

m= Import["Uno.xlsx"][[1]];
j=DeleteCases[m,{"año","Población"}];
l=DeleteCases[p,{"AÑO","TOTAL"}];

ListPlot[j]
ListPlot[l]

And now I need to find M,r for my logistic equation but M,r are both equals to 1 in both cases, now t is my year coordinate and I´am not sure the notebook is understanding that.

po=18.5592;
p=3.998\[Times]10^6;
FindFit[j, M/(1+Exp[po+r*t]),{M,r},t]
FindFit[l, S/(1+Exp[p+r*t]),{S,r},t]


j={{1965.,18.5592},{1966.,19.109},{1967.,19.6698},{1968.,20.2349},{1969.,20.7953},{1970.,21.3448},{1971., 21.8802},{1972.,22.4043},{1973.,22.9248},{1974.,23.4527},{1975.,23.9962},{1976.,24.5576},{1977., 25.1346},{1978.,25.7253},{1979.,26.3262},{1980.,26.9346},{1981.,27.5502},{1982.,28.1735},{1983., 28.8033},{1984.,29.438},{1985.,30.0765},{1986.,30.7181},{1987.,31.3625},{1988.,32.009},{1989., 32.6573},{1990.,33.3069},{1991.,33.9573},{1992.,34.6082},{1993.,35.2605},{1994.,35.9154},{1995., 36.5739},{1996.,37.2361},{1997.,37.9014},{1998.,38.5681},{1999.,39.2341},{2000.,39.898},{2001., 40.5586},{2002.,41.2163},{2003.,41.8721},{2004.,42.5276},{2005.,43.184},{2006.,43.8414},{2007., 44.4984},{2008.,45.153},{2009.,45.8026},{2010.,46.4448},{2011.,47.0788},{2012.,47.7044}}

l={{1965.,18.5592},{1966.,19.109},{1967.,19.6698},{1968.,20.2349},{1969.,20.7953},{1970.,21.3448},{1971., 21.8802},{1972.,22.4043},{1973.,22.9248},{1974.,23.4527},{1975.,23.9962},{1976.,24.5576},{1977., 25.1346},{1978.,25.7253},{1979.,26.3262},{1980.,26.9346},{1981.,27.5502},{1982.,28.1735},{1983., 28.8033},{1984.,29.438},{1985.,30.0765},{1986.,30.7181},{1987.,31.3625},{1988.,32.009},{1989., 32.6573},{1990.,33.3069},{1991.,33.9573},{1992.,34.6082},{1993.,35.2605},{1994.,35.9154},{1995., 36.5739},{1996.,37.2361},{1997.,37.9014},{1998.,38.5681},{1999.,39.2341},{2000.,39.898},{2001., 40.5586},{2002.,41.2163},{2003.,41.8721},{2004.,42.5276},{2005.,43.184},{2006.,43.8414},{2007., 44.4984},{2008.,45.153},{2009.,45.8026},{2010.,46.4448},{2011.,47.0788},{2012.,47.7044}}.......
$\endgroup$
  • $\begingroup$ Please show us a few elements of j and l $\endgroup$ – Dr. belisarius Nov 25 '15 at 21:08
  • $\begingroup$ It seems to me that j and l are the same data sets. Why do p0 and p have so different values? Are they given in the correct units? $\endgroup$ – demm Nov 25 '15 at 22:55
  • $\begingroup$ you are right I made a mistake still I don´t know why does my parameters are to be (1,1) when clearly it isn´t the case $\endgroup$ – Juan Valdiri Nov 25 '15 at 22:58
3
$\begingroup$

The problem is a case of the starting values (1.0 for both parameters) being too far away from the solution. (And you should avoid uppercase letters for variable names.)

The following works:

model1 = FindFit[j, m/(1 + Exp[po + r t]), {{m, 500}, {r, -0.008}}, t]
(* {m -> 527.775, r -> -0.00797179} *)

Alternatively, a better long-term approach is to always scale the predictor variables and/or the dependent variable so that the range of values is say from -10 to 10. Or you can subtract the mean and divide by the standard deviation. Or subtract the minimum and divide by the range. Lots of ways work.

Here's what you get using the default starting values by dividing the year (t) by 1,000:

model2 = FindFit[j, m/(1 + Exp[po + r (t/1000)]), {m, r}, t]
(* {m -> 527.775, r -> -7.97179} *)

This is a common issue in fitting models whether it be in Mathematica, R, SAS, SPSS, etc.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.