In JavaScript, how can I do regression estimates from data? I mean, I have data of the form
1960: 200000
1970: 400000
1980: 600000
1990: 1000000
2000: 1800000
2010: 3300000
My goal is to predict what is the value of 2020 if the growth remains the same. The problem was given as how a population of particular artificial country will grow so I am not sure if the exponential model describes the growth well enough.
Do you mean, how do you write a linear regression formula, or how do you verify that the historical population figures for a country do show exponential growth?
Can you work out the logarithms of those numbers and do regression on them? If you were doubling those numbers every ten years, you would have reached 6,400,000 by now.
You mentioned JS, which we already have a forum for, but I think I should add you to our general computing forum because such algorithms are language‑neutral.
I mean that it would be nice to see what kind of regression models the data a good way, and what are the coefficients of such a model. If this is too hard, it is sufficient to find real numbers a and b such that e^(a+bx) fits to the data the best way is sense of ordinary least squares approximation. I try to learn how to implement regression and matrix algebra to JavaScript.
The three important things are Matrix multiplication, transpose a Matrix and invert a Matrix. Look for Gaussian elimination for the inversion. I always used Excel too, to see graphically what kind of model I had to use (direct lineat, log-log, quadratic, et cetera.
Another way is to look up the formulas that involve terms line x, x^2, x*y, y^2 et cetera, no linear algebra required.
I have this method in my Matrix class: (it's in java)
There are three kinds of actuaries: those who can count, and those who can't.
There is a method called least squares which gives the closest possible straight line fit to the data. If they are supposed to be exponential, you can do a regression to their logarithm.