# Original data created
library(MASS)
mu <- c(1,2,3,4)
Sigma <- matrix(c(1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1), nrow = 4, ncol = 4, byrow = TRUE)
seed = 1
n_sample = 100
# Create original simulated dataset
df = mvrnorm(n_sample, mu = mu, Sigma = Sigma)
# Synthetic data created
df_s = simSynthData(df)
# Gather the 0.95 quantile
p = dim(df_s)[2]
T_sph <- Sphdist(nsample = n_sample, pvariates = p, iterations = 10000)
q95 <- quantile(T_sph, 0.95)
# Compute the observed value of T from the synthetic dataset
S_star = cov(df_s*(n_sample-1))
T_obs = (det(S_star)^(1/p))/(sum(diag(S_star))/p)
print(q95)
print(T_obs)
#Since the observed value is bigger than the 95% quantile,
#we don't have statistical evidences to reject the Sphericity property.
#
#Note that the value is very close to one
Run the code above in your browser using DataLab