Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to understand how this webpage uses javascript to produce a growth rate

I'm very limited in my JS and even mathematics knowledge for that matter so I turn to you. I'm using a site linked here to find annual population growth rates for individual Nigerian states. When you click on a state, say Abia, it will give you the annual growth rate. I'm trying to figure out the exact formula that they're using to produce said growth rates. Here is the .js file that containing the code to do this. I believe the block we want is this:

cp.data.computeAnnualChange=function(a,b,c,d){
   if(!a||!b)return null;a=this.dateDiffInYears(a,b);
   return 0<c&&0<a&&0<d?Math.round(1E4*(Math.exp(Math.log(d/c)/a)-1))/100:null};
   cp.data.INT_MODE="i";

Some context: The formula is supposed to take the population of a state from 1991 and the population from 2006 and provide you with the annual rate of growth. I recognize that basic equation on line 4, it's a geometric growth rate. I can make that in excel, but when I do the number I come up with is about .13 percent off, which is significant. My ultimate goal is to make this into a formula I can use in excel.

like image 486
Tomulent Avatar asked Nov 13 '22 01:11

Tomulent


1 Answers

Closing this question since someone's comment helped me figure it out.

Basically, I had it right with the formula I posted in the original question, it's just that I wasn't precise enough with the data range. The two censuses were 14.32 years apart and I was just using 14.

The correct formula is (EXP((LN(pn/p0)/14.32))-1) where pn and p0 are the newest and oldest censuses respectively.

like image 143
Tomulent Avatar answered Nov 15 '22 00:11

Tomulent