T2.test = function(X,mu0){
n = nrow(X);p = ncol(X)
C = data.frame(c(1,0),c(0,1),c(-6,-4))
Xbar = colMeans(X);S = cov(X);
T2 = n*t(C*Xbar-mu0)%*%solve(C*S*t(C))%*%(C*Xbar-mu0)
T2.adj = (n-p)*T2/(p*(n-1))
pval = 1-pf(T2.adj,p,n-p)
cat("Hotelling T-squared test for unknown covariance",fill=T)
data.frame(T2 = T2,T2.adj = T2.adj,p.value=pval)
}
df<-data.frame(height = c(78,76,92,81,81,84),
leight1 = c(60.6,58.1,63.2,59.0,60.8,59.5),
leight2 = c(16.5,12.5,14.5,14,15.5,14))
print(df)
mu0 = c(0,0)
T2.test(df,mu0)