Processing math: 100%

2017年10月2日月曜日

学習環境

Head First Statistics (Dawn Griffiths (著)、黒川 利明 (翻訳)、木下 哲也 (翻訳)、黒川 洋 (翻訳)、黒川 めぐみ (翻訳)、オライリージャパン)の7章(幾何分布、二項分布、ポアソン分布 - いろいろな離散確率分布)、長いエクササイズ(p. 320)を取り組んでみる。

長いエクササイズ(p. 320)


  1. 二項分布。

    期待値はE(X) = 10 × 0.3 = 3

    分散はVar(X) = 10 × 0.3 × 0.7 = 2.1。

    P(X=0)+P(X=1)+P(X=2)=(100)0.30·0.710+(101)0.31·0.79+(102)0.32·0.78=0.710+10·0.3·0.79+45·0.32·0.78

  2. ポアソン分布。

    期待値はE(X) = 1。

    分散はVar(X) = 1。

    P(X=0)=e1·100!=e1

  3. 幾何分布。

    期待値はE(X) = 1 / 0.2 = 0.05。

    分散はVar(X) = (1 - 0.2) / 0.2^2 = 0.8 / 0.04 = 20。

    P(X<4)=P(X=1)+P(X=2)+P(X=3)=0.2+0.8·0.2+0.82·0.2

コード(Emacs)

HTML5

<pre id="output0"></pre>

<button id="run">run</button>
<button id="clear0">clear</button>

<script src="sample11.js"></script>    

JavaScript

let pre0 = document.querySelector('#output0'),
    btn0 = document.querySelector('#run'),
    btn1 = document.querySelector('#clear0'),
    p = (x) => pre0.textContent += x + '\n',
    range = (start, end, step=1) => {
        let res = [];
        for (let i = start; i < end; i += step) {
            res.push(i);
        }
        return res;
    };


let factorial = (n) => range(1, n + 1).reduce((prev, next) => prev * next, 1);

let output = () => {
    p('1.')
    p(0.7 ** 10 + 10 * 0.3 * 0.7 ** 9 + 45 * 0.3 ** 2 * 0.7 ** 8);

    p('2.');
    p(Math.exp(-1));

    p('3.');
    p(0.2 + 0.8 * 0.2 + 0.8 ** 2 * 0.2);
};

btn0.onclick = output;
btn1.onclick = () => pre0.textContent = '';
output();
1.
0.3827827863999998
2.
0.36787944117144233
3.
0.4880000000000001

0 コメント:

コメントを投稿