# 訊息

## English

``````> m=5
> sd = 2
> xmat = matrix(rnorm(10*5, m, sd), nrow=10, ncol=5)
> xmat
[,1]     [,2]     [,3]     [,4]      [,5]
[1,] 6.217661 5.450117 4.494195 4.605279 7.3158346
[2,] 7.296856 4.081226 2.962462 8.904754 5.6031118
[3,] 5.564640 4.031601 3.790188 4.901844 0.4362374
[4,] 3.886422 5.193430 6.901971 6.598526 3.9460606
[5,] 7.199686 7.795072 5.393850 8.464249 4.7914653
[6,] 6.112477 6.433343 5.041161 3.006464 4.7378036
[7,] 5.169029 6.162387 5.013237 2.774931 5.4353647
[8,] 3.654506 4.156485 6.270920 9.691209 6.2991443
[9,] 7.332289 2.693996 3.928056 3.625593 5.2263779
[10,] 2.847031 5.699145 4.365228 5.783563 6.3769525
> xbar = apply(xmat, 2, mean)
> xbar
[1] 5.528060 5.169680 4.816127 5.835641 5.016835
> xlow = xbar - qnorm(0.025)*1/sqrt(10)
> xhigh = xbar + qnorm(0.025)*1/sqrt(10)
> xlow
[1] 6.147855 5.789475 5.435922 6.455436 5.636630
> xhigh
[1] 4.908265 4.549885 4.196332 5.215846 4.397040
> xlow = xbar + qnorm(0.025)*1/sqrt(10)
> xlow
[1] 4.908265 4.549885 4.196332 5.215846 4.397040
> xhigh = xbar + qnorm(0.975)*1/sqrt(10)
> xhigh
[1] 6.147855 5.789475 5.435922 6.455436 5.636630```
```

# R 程式碼

``````meanRange = function(m, sd) {
groups = 100
n = 50
xmat = matrix(rnorm(n*groups, m, sd), nrow=n, ncol=groups)
xbar <- apply(xmat, 2, mean)
xlow = xbar + qnorm(0.025)*1/sqrt(n)
xhigh = xbar + qnorm(0.975)*1/sqrt(n)
inRange = count(xlow <= m && xhigh >= m)
rate = inRange / groups
return rate
}```
```