メモ

  • \sum_{i=1}^n (x_i-\frac{\sum_{j=1}^n x_j}{n})^2
  • =\frac{1}{n^2}\sum_{i=1}^n (n x_i-\sum_{j=1}^n x_j)^2
  • =\frac{1}{n^2}\sum_{i=1}^n ((n-1) x_i -\sum_{j \ne i} x_n)^2
    • x_1-\frac{\sum_{j=1}^3 x_j}{3}
    •  = \frac{3 \times x_1 -(x_1+x_2+x_3)}{3}
    •  = \frac{(3-1)x_1 -(x_2+x_3)}{3}
  • x_ix_jの係数はnのうち、2回は-2(n-1)、残りn-2回は+2なので-2(n-1)\times 2 +2\times (n-2)
  • [tex:=\frac{1}{n^2}\sum_{i=1}^n *1x_i^2 - \sum_{i \ne j}(2(n-1)\times 2-2\times (n-2))x_ix_j]
    • [tex:*2^2]からは
    • (3-1)^2 x_1^2が、
    • [tex:*3^2]からは
    • 1^2 x_1が、
    • [tex:*4^2]からも
    • 1^2 x_1が出てくるので
    • [tex:*5x_1^2]が得られる。これはすべてのx_i;i=1,2,3に共通。
    • 2*(3-1)*(-1)*x_1 x_2 2(3-1)*(-1)*x_2 x_1(-1)*(-1)x_1x_2とがx_1x_2に出てくるので、
    • -2(n-1)\times 2 + 2\times (n-2)i\ne j x_ix_jの係数
  • =\frac{1}{n^2}\sum_{i=1}^n n(n-1)x_i^2 - \sum_{i \ne j} 2nx_ix_j
  • =\frac{1}{n^2}\sum_{i \ne j}n (x_i^2 + x_j^2 - 2x_ix_j)
  • =\frac{1}{n} \sum_{i \ne j} (x_i-x_j)^2
x <- rnorm(167)
sum((x-mean(x))^2)/length(x)
sum((outer(x,x,"-"))^2)/(2*length(x)^2)
  • ちなみに「平均」は
mean(x)
sum(outer(x,x,"+")^1)/(2*length(x)^2)
> x <- rnorm(167)
> sum((x-mean(x))^2)/length(x)
[1] 1.144598
> sum((outer(x,x,"-"))^2)/(2*length(x)^2)
[1] 1.144598
> mean(x)
[1] -0.1518104
> sum(outer(x,x,"+")^1)/(2*length(x)^2)
[1] -0.1518104

*1:n-1)^2 + (n-1

*2:3-1)x_1 - (x_2+x_3

*3:3-1)x_2 -(x_1+x_3

*4:3-1)x_3-(x_1+x_2

*5:3-1)^2 + (3-1