Skip to content

Instantly share code, notes, and snippets.

@jeroen
Forked from timelyportfolio/Readme.md
Last active August 29, 2015 14:15
Show Gist options
  • Save jeroen/a5b07a669285da699056 to your computer and use it in GitHub Desktop.
Save jeroen/a5b07a669285da699056 to your computer and use it in GitHub Desktop.
Linear regression in JavaScript using simple statistics
# Load in simple statistics
library(V8)
ct <- new_context("window")
ct$source("https://raw.githubusercontent.com/tmcw/simple-statistics/master/src/simple_statistics.js")
# Run Regression
ct$assign("mydata", cbind(mtcars$wt, mtcars$mpg))
ct$eval("var lm = ss.linear_regression().data(mydata)")
ct$get("[ lm.b(), lm.m() ]")
# Compare to
coef(lm( mpg ~ wt, mtcars ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment