README.md (5545B)
1 [jStat](http://www.jstat.org/) - JavaScript Statistical Library 2 =============================================================== 3 4 [](https://badge.fury.io/js/jstat) 5 6 jStat provides native javascript implementations of statistical functions. 7 Full details are available in the [docs](https://jstat.github.io/all.html). 8 jStat provides more functions than most libraries, including the weibull, 9 cauchy, poisson, hypergeometric, and beta distributions. For most 10 distributions, jStat provides the pdf, cdf, inverse, mean, mode, variance, and 11 a sample function, allowing for more complex calculations. 12 13 **NOTICE:** The previous case sensitive `jStat` module will no longer be 14 updated. Instead use the all lowercase `jstat` when doing an `npm install` or 15 similar. 16 17 Using jStat in a Browser 18 ------------------------ 19 20 jStat can be used in the browser. The `jStat` object will be added to the 21 window. For example: 22 23 ``` 24 <script src="components/jstat.js"></script> <!-- include jStat, from the CDN or otherwise --> 25 26 <script> 27 ... 28 var jstat = this.jStat(dataset); // jStat will be added to the window 29 ... 30 data[i]['cum'] = jstat.normal(jstat.mean(), jstat.stdev()).cdf(data[i].x); 31 ... 32 </script> 33 34 ``` 35 36 CDN [](https://www.jsdelivr.com/package/npm/jstat) 37 --- 38 39 The library is hosted on [jsDelivr](http://www.jsdelivr.com/) using the following 40 url: 41 ``` 42 //cdn.jsdelivr.net/npm/jstat@latest/dist/jstat.min.js 43 ``` 44 Note that `'latest'` can be replaced with any released verion of jStat. 45 46 Module Loaders 47 -------------- 48 49 Currently jStat is exposed as `j$` and `jStat` inside an object, rather than 50 exported directly. This may confuse some module loaders, however should be 51 easily remedied with the correct configuration. 52 53 NodeJS & NPM 54 ------------ 55 To install via npm: 56 57 ``` 58 npm install --save jstat 59 ``` 60 61 When loading under Node be sure to reference the child object. 62 63 ``` 64 var { jStat } = require('jstat'). 65 ``` 66 67 RequireJS Shim 68 -------------- 69 70 For RequireJS not only `exports` but also `init` function must be specified. 71 ``` 72 requirejs.config({ 73 paths: { 74 'jstat': 'path/to/jstat/dist/jstat.min' 75 }, 76 shim: { 77 jstat: { 78 exports: ['j$', 'jStat'], 79 init: function () { 80 return { 81 j$: j$, 82 jStat: jStat 83 }; 84 } 85 } 86 } 87 }); 88 ``` 89 90 Build Prerequisites 91 ------------------- 92 93 In order to build jStat, you need to have GNU make 3.8 or later, Node.js 0.2 or 94 later, and git 1.7 or later. (Earlier versions might work OK, but are not 95 tested.) 96 97 Windows users have two options: 98 99 1. Install [msysgit](https://code.google.com/p/msysgit/) (Full installer for official Git), 100 [GNU make for Windows](http://gnuwin32.sourceforge.net/packages/make.htm), and a 101 [binary version of Node.js](http://node-js.prcn.co.cc/). Make sure all three packages are installed to the same 102 location (by default, this is C:\Program Files\Git). 103 2. Install [Cygwin](http://cygwin.com/) (make sure you install the git, make, and which packages), then either follow 104 the [Node.js build instructions](https://github.com/ry/node/wiki/Building-node.js-on-Cygwin-%28Windows%29) or install 105 the [binary version of Node.js](http://node-js.prcn.co.cc/). 106 107 Mac OS users should install Xcode (comes on your Mac OS install DVD, or downloadable from 108 [Apple's Xcode site](http://developer.apple.com/technologies/xcode.html)) and 109 [http://mxcl.github.com/homebrew/](Homebrew). Once Homebrew is installed, run `brew install git` to install git, 110 and `brew install node` to install Node.js. 111 112 Linux/BSD users should use their appropriate package managers to install make, git, and node, or build from source 113 if you swing that way. 114 115 116 Building jStat 117 -------------- 118 119 First, clone a copy of the jStat git repo by running `git clone git://github.com/jstat/jstat.git`. 120 121 To download all necessary libraries run `npm install`. 122 123 Then, to get a complete, minified version of jStat and all documentation, 124 simply `cd` to the `jstat` directory and type `make`. If you don't have Node 125 installed and/or want to make a basic, uncompressed, unlinted version of jstat, 126 use `make jstat` instead of `make`. 127 128 The built version of jStat will be put in the `dist/` subdirectory. 129 130 Generate just the documentation by running `make doc`. Documentation will be 131 placed in `dist/docs` by default. 132 133 To remove all built files, run `make clean`. 134 135 136 Running Tests 137 ------------- 138 139 Execute all tests by running `make test`. 140 141 Or if you wish to run a specific test, `cd` to `test/<subdir>` and run `node <some_test>-test.js`. 142 143 144 Get the Code 145 ------------ 146 147 Both the minified and unminified source are located in the `dist/` directory. 148 For those who don't want to build it themselves. 149 150 151 Contribute 152 ---------- 153 154 jStat is now going to follow most of the v8 155 [JavaScript](https://google.github.io/styleguide/jsguide.html) 156 guidelines. There will be plenty of source that uses the old style, but we're 157 going to work away from that. 158 159 Also, we'll be going through and reimplementing a good portion of the code to 160 run faster. Hopefully it won't take too long to get the project on one basic 161 standard. 162 163 When submitting pull requests, no need to check in `dist/*.js`. They'll be 164 recompiled for distribution anyway. 165 166 Join the Community 167 ------------------ 168 169 We always like discussion of how to improve jStat. 170 Join us at our [mailing list](http://groups.google.com/group/jstat-discuss/) 171 and let us know what you'd like to see. Also come ask questions in the #jstat 172 channel on irc.freenode.net.