Skip to contents

Test whether the mean vectors of two multivariate normal populations are equal when the covariance matrices are equal or unequal. The null hypothesis is that "H0: mu1 = mu2".

Usage

meanTest.two(
  data1,
  data2,
  alpha = 0.05,
  equal = TRUE,
  method = c("None", "Coupled", "Transformed"),
  verbose = TRUE
)

Arguments

data1

A matrix or data frame of group 1.

data2

A matrix or data frame of group 2.

alpha

The significance level. Default is 0.05.

equal

A boolean value. Default is TRUE. If TRUE, the covariance matrix is equal. If FALSE, the covariance matrix is not equal.

method

A string value. Default is "None". When equal is FALSE, you must choose a method in "Coupled" or "Transformed". Choose "Coupled" when the sample size of two groups is equal. Choose "Transformed" when the sample size of two groups is not equal.

verbose

A boolean value. Default is TRUE. If TRUE, the null hypothesis will be displayed. If FALSE, the test will be carried out silently.

Value

An object of class "testResult", which is a list with the following elements: Return when the param equal is TRUE.

Conclusion

The conclusion of the test.

Stat

A data frame containing the statistics, p value and critical value.

SampMean1

The sample mean of group 1.

SampMean2

The sample mean of group 2.

SampA1

The sample deviation of group 1.

SampA2

The sample deviation of group 2.

MixSampA

The mixed sample deviation.

Df

The degree of freedom.

Return when the param equal is FALSE and method is "Coupled".

Conclusion

The conclusion of the test.

Stat

A data frame containing the statistics, p value and critical value.

SampMeanC

The sample mean of coupled data.

SampAC

The sample deviation of coupled data.

Df

The degree of freedom.

dataC

The coupled data.

Return when the param equal is FALSE and method is "Transformed".

Conclusion

The conclusion of the test.

Stat

A data frame containing the statistics, p value and critical value.

SampMeanT

The sample mean of transformed data.

SampAT

The sample deviation of transformed data.

Df

The degree of freedom.

dataT

The transformed data. Return when the param equal is FALSE and method is "Transformed".

References

Huixuan, Gao. Applied Multivariate Statistical Analysis. Peking University Press, 2005: pp.76-80.

Author

Xifeng Zhang

Examples

data(iris)
X <- iris[1:50, 1:4]
Y <- iris[51:100, 1:4]
# carry out the test
test1 <- meanTest.two(X, Y)
test2 <- meanTest.two(X, Y, verbose = TRUE)
test3 <- meanTest.two(X, Y, equal = FALSE, method = "Coupled")
test4 <- meanTest.two(X, Y, equal = FALSE, method = "Transformed")
# get the elements
test1$Stat
#>                  Value p.value   Critical.Value
#> Hotelling T2 2580.8385                         
#> F             625.4583       0 2.46749362344965
test1$SampMean1
#> Sepal.Length  Sepal.Width Petal.Length  Petal.Width 
#>        5.006        3.428        1.462        0.246 
test3$SampMeanC
#> Sepal.Length  Sepal.Width Petal.Length  Petal.Width 
#>       -0.930        0.658       -2.798       -1.080 
test4$dataT
#>    Sepal.Length Sepal.Width Petal.Length Petal.Width
#> 1          -1.9         0.3         -3.3        -1.2
#> 2          -1.5        -0.2         -3.1        -1.3
#> 3          -2.2         0.1         -3.6        -1.3
#> 4          -0.9         0.8         -2.5        -1.1
#> 5          -1.5         0.8         -3.2        -1.3
#> 6          -0.3         1.1         -2.8        -0.9
#> 7          -1.7         0.1         -3.3        -1.3
#> 8           0.1         1.0         -1.8        -0.8
#> 9          -2.2         0.0         -3.2        -1.1
#> 10         -0.3         0.4         -2.4        -1.3
#> 11          0.4         1.7         -2.0        -0.8
#> 12         -1.1         0.4         -2.6        -1.3
#> 13         -1.2         0.8         -2.6        -0.9
#> 14         -1.8         0.1         -3.6        -1.3
#> 15          0.2         1.1         -2.4        -1.1
#> 16         -1.0         1.3         -2.9        -1.0
#> 17         -0.2         0.9         -3.2        -1.1
#> 18         -0.7         0.8         -2.7        -0.7
#> 19         -0.5         1.6         -2.8        -1.2
#> 20         -0.5         1.3         -2.4        -0.8
#> 21         -0.5         0.2         -3.1        -1.6
#> 22         -1.0         0.9         -2.5        -0.9
#> 23         -1.7         1.1         -3.9        -1.3
#> 24         -1.0         0.5         -3.0        -0.7
#> 25         -1.6         0.5         -2.4        -1.1
#> 26         -1.6         0.0         -2.8        -1.2
#> 27         -1.8         0.6         -3.2        -1.0
#> 28         -1.5         0.5         -3.5        -1.5
#> 29         -0.8         0.5         -3.1        -1.3
#> 30         -1.0         0.6         -1.9        -0.8
#> 31         -0.7         0.7         -2.2        -0.9
#> 32         -0.1         1.0         -2.2        -0.6
#> 33         -0.6         1.4         -2.4        -1.1
#> 34         -0.5         1.5         -3.7        -1.4
#> 35         -0.5         0.1         -3.0        -1.3
#> 36         -1.0        -0.2         -3.3        -1.4
#> 37         -1.2         0.4         -3.4        -1.3
#> 38         -1.4         1.3         -3.0        -1.2
#> 39         -1.2         0.0         -2.8        -1.1
#> 40         -0.4         0.9         -2.5        -1.1
#> 41         -0.5         0.9         -3.1        -0.9
#> 42         -1.6        -0.7         -3.3        -1.1
#> 43         -1.4         0.6         -2.7        -1.0
#> 44          0.0         1.2         -1.7        -0.4
#> 45         -0.5         1.1         -2.3        -0.9
#> 46         -0.9         0.0         -2.8        -0.9
#> 47         -0.6         0.9         -2.6        -1.1
#> 48         -1.6         0.3         -2.9        -1.1
#> 49          0.2         1.2         -1.5        -0.9
#> 50         -0.7         0.5         -2.7        -1.1