Permalink
Browse files

Bump up version and updated README.

  • Loading branch information...
1 parent b107406 commit 55247a21c0c6670c3eb8fcbc392040c682768763 @sethyuan committed Apr 2, 2013
Showing with 53 additions and 1 deletion.
  1. +52 −0 README.md
  2. +1 −1 package.json
View
@@ -75,6 +75,24 @@ var t_ = xtabs.addMargins(t, [0, 1],
[[{ n: "Sum", f: sum }, { n: "Prod", f: prod }], [{ n: "Sum", f: sum }]]);
```
+### Proportions of a table
+
+```js
+var t = xtabs.table(data, "department", "gender");
+
+// Proportions calculated in relation to all data.
+var t_ = xtabs.prop(t);
+console.log(t_.get("RD").array); // [0.4, 0.2]
+
+// Proportions calculated in relation to rows.
+var t_ = xtabs.prop(t, 0);
+console.log(t_.get("RD").array); // [2/3, 1/3]
+
+// Proportions calculated in relation to columns.
+var t_ = xtabs.prop(t, 1);
+console.log(t_.get(undefined, "M").array); // [0.5, 0, 0.5]
+```
+
## API
### xtabs.factor(x, [useNull])
@@ -148,6 +166,40 @@ department M F Sum
You can add multiple margins at once, or apply multiple functions at once, or both. If you want to add multiple margins at once, you pass in an array of margins to be added in order, instead of a single margin. If you want to apply multiple functions, you can provide a list of function objects (See [Adding margins](#adding-margins)) per margin. Functions are applied in the same order the margins are provided.
+### xtabs.prop(table, margin)
+
+Return a new table with proportions according to `margin`. If `margin` is undefined or null, then proportions are calculated in relation of the whole table. See [Proportions of a table](#proportions-of-a-table) for examples of how to use it. Also refer to the following diagrams:
+
+```
+Original table:
+ gender
+department M F
+ RD 2 1
+ HR 0 0
+ GA 2 0
+
+Proportions in relation to rows:
+ gender
+department M F
+ RD 2/3 1/3
+ HR NaN NaN
+ GA 2/2 0/2
+
+Proportions in relation to columns:
+ gender
+department M F
+ RD 2/4 1/1
+ HR 0/4 0/1
+ GA 2/4 0/1
+
+Proportions in relation to whole:
+ gender
+department M F
+ RD 2/5 1/5
+ HR 0/5 0/5
+ GA 2/5 0/5
+```
+
## Class: xtabs.Table
This is what you get when you call [xtabs.table](#xtabstablex-variable--usenull), however, this class is not directly exposed to you.
View
@@ -1,6 +1,6 @@
{
"name": "xtabs",
- "version": "0.2.0",
+ "version": "0.3.0",
"description": "A cross tabulation library for Node.js",
"main": "./lib/xtabs.js",
"scripts": {

0 comments on commit 55247a2

Please sign in to comment.