UNPKG

1.65 kBJavaScriptView Raw
1var R = require("../rlab");
2var M = R.M;
3var c = console;
4
5var dice = R.steps(1,6);
6c.log("dice=", dice);
7
8var x = R.samples(dice, 6, {replace:false});
9c.log("x=", x);
10
11var x = R(dice).samples(6, {replace:false}).value();
12c.log("chain1:x=", x);
13
14var x = R(dice).samples(10).str();
15c.log("chain2:x=", x);
16
17var x = R.samples(dice, 10);
18c.log("x=", x, "max=", R.max(x), "min=", R.min(x),
19 "mean=", R.mean(x), "sd=", R.sd(x));
20
21c.log("cov(x,x)=", R.cov(x,x));
22c.log("cor(x,x)=", R.cor(x,x)); // 相關係數
23c.log("factorial(10)=", R.factorial(10)); // 階層 n!
24c.log("lfactorial(10)=", R.lfactorial(10).toFixed(4)); // log(n!)
25c.log("choose(5,2)=", R.choose(5,2)); // 組合 C(n,m)
26c.log("lchoose(5,2)=", R.lchoose(5,2)); // log C(n,m)
27c.log("permutation(5,2)=", R.permutation(5,2)); // P(n,m)
28c.log("runif(10, -5, -1)=", R.runif(10, -5, -1).str());
29// c.log(".chain(10).runif(-5,-1)=", R.chain(10).runif(-5,-1));
30c.log("dunif(-3, -5, -1)=", R.dunif(-3, -5, -1));
31c.log("punif(-3, -5, -1)=", R.punif(-3, -5, -1));
32c.log("qunif(0.5, -5, -1)=", R.qunif(0.5, -5, -1));
33
34var x = R.rnorm(10, 0, 1);
35c.log("x=", R.str(x));
36c.log("x.sort()=", x.sort().str());
37
38c.log("rbinom(10, 5, 0.5)=", R.rbinom(10,5,0.5));
39c.log("dbinom(4, 5, 0.5)=", R.dbinom(4,5,0.5));
40c.log("dbinom(5, 5, 0.5)=", R.dbinom(5,5,0.5));
41c.log("pbinom(4, 5, 0.5)=", R.pbinom(4,5,0.5));
42c.log("qbinom(0.9, 5, 0.5)=", R.qbinom(0.9,5,0.5));
43
44var t1=R.ttest({x:x, mu:0} );
45R.report(t1);
46
47var A = [[1,2,3],[4,5,6],[7,3,9]];
48var iA = M.inv(A);
49c.log("A=", R.str(A));
50c.log("iA=", R.str(iA));
51var AiA = M.dot(A, iA);
52
53c.log("AiA=", R.str(AiA));
54
55c.log("====iA=====\n", M.str(iA))
56