This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Mastering Corda: Blockchain for Java Developers and have Jamiel Sheikh on-line!
See this thread for details.
Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

How to find a regression estimate on JavaScript?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 71682
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jaakko Seppälä
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 71682
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That sounds like something where you can look up an algorithm. Does JS support exponentiation in its mathematical libraries?
 
Bartender
Posts: 4272
160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Campbell Ritchie
Marshal
Posts: 71682
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you need matrix multiplication if you can draw/impute a graph of time vs. log(population) and do a least squares fit to it?
 
Piet Souris
Bartender
Posts: 4272
160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
About the multiply: as you can see in the result Matrix, there is quite some multiplying involved.

But if you make a graph of the data, then how do you do that regression?

By the way: the example I gave in my method lacks a little. A cow for the first one who corrects it.
 
Campbell Ritchie
Marshal
Posts: 71682
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Piet Souris
Bartender
Posts: 4272
160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My result matrix is exactly that method.
 
Jaakko Seppälä
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the following will do the job:

 
Campbell Ritchie
Marshal
Posts: 71682
312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't use Math.pow when you could write the numbers as literals. I think 1960,&'xa0;2&&xa0;* Math.pow(10, 6) is incorrect.
 
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic