# Generating a dataset satisfying / violating the RM-ANOVA sphericity assumption

I was reading a research paper where they had a 2x3 repeated measures factorial design with a single DV. A suitable approach to this analysis would be a univariate repeated measures ANOVA. However, its possible that sphericity is violated (and a GG/HF adjustment required). They chose to use a MANOVA instead.

I'm writing a term paper on how F test results/interpretations could differ between a sphericity violated case (both with and without adjustment) and a non-violated case, between the univariate and multivariate approaches.

I want to base my paper on the paper that I read (same design), but I dont have access to the original dataset (lets assume for this question that I'm unable to get it from the authors). How do I generate a dataset, of the same design as outlined above, where I can guarantee that sphericity will be violated? And likewise, a dataset where sphericity is guaranteed to not be violated?

I'd be happy to generate this using R, MATLAB, or Python

The expected layout should be something like this:

I'd like a way to control the means of these sub groups so I can manually make sure that factorx_1 and factorx_2 are significantly different for example

• An immediate, just basic, untested by simulations, idea. Let's have a RM dependent factor with levels 1,2,3. Sphericity assumption implies the difference variables between the levels are uncorrelated, that is, cov("1-2","1-3")=cov("1-2","2-3")=cov("1-3","2-3")=0. Because the difference variables are natively related it is suffice to write var instead of cov in this equation: if their variances are equal, covariances are equal too. You should generate such difference variables somehow first. Then violate. – ttnphns Feb 19 '16 at 13:53

You say you have two whole plot factor levels and three sub plot factor levels (the repetitions).

Sphericity means that the covariance matrix of the effect estimators has equal positive eigenvalues. (As you know, the set $\{x|x'Ax = r\}$ is a sphere iff $A$ has equal positive eigenvalues. That's where the name comes from.) Then this eigenvalue is the only nuisance parameter, you'll automatically get rid of it by cancellation in the usual univariate ANOVA-$F$-statistic.

Assuming $\hat{\mu}$ to be the three-dimensional mean vector, the effect estimator is $H \hat{\mu}$, where $H$ is a hypothesis matrix centering matrix $C_3 = [\delta_{ij}-\frac{1}{3}]_{ij}$). Let $\Sigma$ be the 6x6-covariance matrix in both groups. Then you'll have sphericity iff $H\Sigma H'$ is spherical. Popular spherical choices are e.g. due to $\Sigma =I_6$ with hypotheses $H=I_6$ (would test if all measurements are 0, not interesting) or $H=P_2 \otimes P_3$ (would test the interaction of both factors) or $H=I_2 \otimes P_3$ (would test the effect only of the factor which has 3 levels) or due to a compound symmetry covariance matrix, that is in R-code

Sigma <- sigmavar*diag(6) + sigmacov


sigmacov and sigmavar are arbitrary positive real values. You can think of sigmacov as the variance of the (random) subject effect and sigmavar as the variance of all the n*d error terms. In fact, that's the rationale of the classical spherical ANOVA model from the textbooks.

Just check by

eigen(H %*% Sigma %*% t(H))$values  that the eigenvalues are in fact positive or (numerically close to) zero. Maybe there are even more possible spherical constellations with (somehow) meaningful hypotheses matrices; I don't know. Popular nonspherical constellations are e.g. if you take autoregressive covariance matrices: for (i in 1:6){for (j in 1:6) {Sigma[i,j] <- 0.2**abs(i-j)}} #0<rho<1  You will not have any problem in finding more of them. Ahe random data set for one sample can be generated by L <- chol(Sigma) Y1 <- matrix(rnorm(n*6),n,6) %*% t(L) + rep(1,n) %*% t(mu)  The noncentrality parameter will be sum((H %*% mu)**2). Note that the covariance matrix doesn't appear there. That's a difference to the MANOVA-approach. • Don't forget to play a bit with$\mu_1 -\mu_2$and$\Sigma$. For which alternative (somehow relative to certain eigenvectors of$H\Sigma H'$) has which procedure (MANOVA, GG-F-test) better power? I think they are not substitutes for each other. – Horst Grünbusch Feb 22 '16 at 23:42 • What do sigmacov and sigmavar represent? i.e. what are the values that should be used there? And how do you set the number of samples (rows?) in the generated dataset? – Simon Feb 22 '16 at 23:55 • I edited my answer. The variance components are arbitrary. n is the number of simulated independent replications aka individuals. For your simulation study, take plausible sample sizes. Maybe >5 per group, maybe 100. You'll notice what it means. (You wrote it's your term paper, so I'll treat it a bit as a self study question.) – Horst Grünbusch Feb 23 '16 at 3:15 • Finally, is it possible to set the degree of non centrality for the hypothesis test? I want to be able to control how different the means of these 3 groups are so I can generate some dataset that will result in a significant F test (or at least be able to control the degree of significance) – Simon Feb 23 '16 at 19:53 • Oops! But what is a 2x3 repeated measures? I thought 2 samples, 3 time points, and I answered about the interaction between group and time point. But the one sample case is not so different: Just forget the other sample (as in my earlier version) and replace the difference$\hat{\mu_1} - \hat{\mu_2}$by${\mu}$. Then the ncp is$\mu' H' H \mu\$. – Horst Grünbusch Feb 26 '16 at 23:38