statkit
A statistics toolkit for javascript.
Usage
Install using npm:
npm install statkit
Fit a linear regression model using MCMC:
var sk = ; // log-likelihood for the model y ~ N(m*x + b, 1/t) { var m = theta0 b = theta1 t = theta2; var s = 00; for var i = 0; i < xlength; i++ var r = yi - m * xi + b; s += r*r*t - Math; return -05*s;} // uniform log-prior for m, b, t { var m = theta0 b = theta1 t = theta2; if 00 < m && m < 10 && 00 < b && b < 100 && 00 < t && t < 1000 return 00; return -Infinity;} // posterior log-probability function { var lp = ; if ! return -Infinity; return lp + ;} var x = 10 8 13 9 11 14 6 4 12 7 5;var y = 804 695 758 881 833 996 724 426 1084 482 568; var res = sk; consoleconsoleconsoleconsoleconsole
Calculate a confidence interval for a correlation using the bootstrap method:
var sk = ; var lsat = 576 635 558 578 666 580 555 661 651 605 653 575 545 572 594;var gpa = 339 330 281 303 344 307 300 343 336 313 312 274 276 288 296; var corr = sk;var ci = sk; console;
Perform a linear regression on the first data set in Anscombe's quartet:
var sk = ; var x = 10 8 13 9 11 14 6 4 12 7 5;var y = 804 695 758 881 833 996 724 426 1084 482 568; var A = xlength*2;for var i = 0; i < xlength; ++i A2*i = 1; A2*i + 1 = xi;var b = sk; console;
Functions
min(a)
- Minimummax(a)
- Maximumrange(a)
- Rangequantile(a)
- Quantilemedian(a)
- Medianiqr(a)
- Interquartile rangemean(a)
- Meangmean(a)
- Geometric meanhmean(a)
- Harmonic meanvar(a)
- Variancestd(a)
- Standard deviationskew(a)
- Skewnesskurt(a)
- Kurtosiscorr(x, y)
- Correlation between x and yentropy(p)
- Entropykldiv(p, q)
- Kullback–Leibler divergenceshuffle(a)
- Shuffle using the Fisher–Yates shufflesample(a)
- Sample with replacementboot(nboot, bootfun, data...)
- Bootstrap the bootfun statisticbootci(nboot, bootfun, data...)
- Calculate bootstrap confidence intervals using the normal modelrandn()
- Draw random sample from the standard normal distribution using the Marsaglia polar methodnormcdf(x)
- Normal cumulative distribution functionnorminv(p)
- Normal inverse cumulative distribution functionlufactor(A, n)
- Compute pivoted LU decompositionlusolve(LU, p, b)
- SolveAx=b
given the LU factorization ofA
qrfactor(m, n, A)
- Compute QR factorization of Aqrsolve(m, n, QR, tau, b)
- Solve the least squares problemmin ||Ax = b||
using QR factorizationQR
ofA
lstsq(m, n, A, b)
- Solve the least squares problemmin ||Ax = b||
metropolis(lnpost, p, iterations, scale, burn, thin)
- Sample fromlnpost
starting atp
using the Metropolis-Hastings algorithm
Credits
(c) 2015 Erik Rigtorp erik@rigtorp.se. MIT License