Reference: 应用多元统计分析 高惠璇 Charter 3
Detailed data attached at the end
Detailed code see github.com

单总体均值检验

mu0=c(4, 50, 10)
Sigma0=var(female.data)
## var known 
result1=mu.test.known(female.data, mu0, Sigma0, alpha=0.05)
result1
## $Reject.area
##             Obs >1-alpha
## Reject 8.135075 7.814728
## 
## $p.value
##            [,1]
## [1,] 0.04330106
## var unknown 
result2=mu.test(female.data, mu0)
result2
## $p.value
##           [,1]
## [1,] 0.1010612

两总体等方差均值检验

result3=two.mu.test(japan, usa)
result3
## $p.value
##             [,1]
## [1,] 0.003705807

多总体等方差均值检验 – 多元方差分析

result4=multi.mu.test(health, 3)  ##3 groups 
result4
## $p.value
## [1] 0.003517917

单总体正态分布方差检验

Sigma0=matrix(c(100,10,0,6,100,-5,0,0,4),nrow=3)
result5=var.test(female.data, Sigma0)
result5
## $p.value
## [1] 2.168687e-11

多总体正态分布方差检验

result6=multi.var.test(health, 3) 
result6
## $p.value
## [1] 0.4373646

多总体正态分布均值方差同时检验

result7=multi.mean.var.test(health, k=3)
result7
## $p.value
## [1] 0.03372988

多元正态独立性检验

Simulation: Run the function for 1000 times, each time generating 200 data which have NID(1, 0; 0.5, 0, 0, 0.5), and proceeding independence test. Record t-value and p-value each time. If p-value is significant, rejects the null hypothesis, i.e. the test fails. The average of the number of failures is calculated to evaluate the test performance.

for(i in 1:times)
{
  mydata <- as.data.frame(mvrnorm(n, mu, Sigma))
  subvector <- c(1,2)
  k=2 # divided into k sub-vector to test independence
  re=norm.independent.test(mydata, subvector, k)
  # If p-value is significant, rejects the null hypothesis, 
  # i.e. the test fails.
  t[i]=re$t
  pi[i]=re$p.value
  if(re$p.value<0.05)
  {
    p[i]=1
  }
}
sum(p) ## total fail times
## [1] 56
t[18]  ## t-value of the 18th result
## [1] 0.2462006
pi[18] ## p-value of the 18th result
## [1] 0.6197632

Example:

subvector <- c(1,2,3)
k=3
result8=norm.independent.test(female.data, subvector, k)
result8
## $t
## [1] 8.400652
## 
## $p.value
## [1] 0.03841802

Appendix: datasets

female.data
X1 X2 X3
3.7 48.5 9.3
3.8 47.2 10.9
3.1 55.5 9.7
2.4 24.8 14.0
6.7 47.4 8.5
3.9 36.9 12.7
3.5 27.8 9.8
1.5 13.5 10.1
4.5 71.6 8.2
4.1 44.1 11.2
4.7 65.1 8.0
3.2 53.2 12.0
4.6 36.1 7.9
7.2 33.1 7.6
5.4 54.1 11.3
4.5 58.8 12.3
4.5 40.2 8.4
8.5 56.4 7.1
6.5 52.8 10.9
5.5 40.9 9.4
japan
X1 X2 X3 X4
65 35 25 60
75 50 20 55
60 45 35 65
75 40 40 70
70 30 30 50
55 40 35 65
60 45 30 60
65 40 25 60
60 50 30 70
55 55 35 75
usa
X1 X2 X3 X4
55 55 40 65
50 60 45 70
45 45 35 75
50 50 50 70
55 50 30 75
60 40 45 60
65 55 45 75
50 60 35 80
40 45 30 65
45 50 45 70
health
X1 X2 X3 X4 ind
260 75 40 18 1
200 72 34 17 1
240 87 45 18 1
170 65 39 17 1
270 110 39 24 1
205 130 34 23 1
190 69 27 15 1
200 46 45 15 1
250 117 21 20 1
200 107 28 20 1
225 130 36 11 1
210 125 26 17 1
170 64 31 14 1
270 76 33 13 1
190 60 34 16 1
280 81 20 18 1
310 119 25 15 1
270 57 31 8 1
250 67 31 14 1
260 135 39 29 1
310 122 30 21 2
310 60 35 18 2
190 40 27 15 2
225 65 34 16 2
170 65 37 16 2
210 82 31 17 2
280 67 37 18 2
210 38 36 17 2
280 65 30 23 2
200 76 40 17 2
200 76 39 20 2
280 94 26 11 2
190 60 33 17 2
295 55 30 16 2
270 125 24 21 2
280 120 32 18 2
240 62 32 20 2
280 69 29 20 2
370 70 30 20 2
280 40 37 17 2
320 64 39 17 3
260 59 37 11 3
360 88 28 26 3
295 100 36 12 3
270 65 32 21 3
380 114 36 21 3
240 55 42 10 3
260 55 34 20 3
260 110 29 20 3
295 73 33 21 3
240 114 38 18 3
310 103 32 18 3
330 112 21 11 3
345 127 24 20 3
250 62 22 16 3
260 59 21 19 3
225 100 34 30 3
345 120 36 18 3
360 107 25 23 3
250 117 36 16 3