Simulating data for linear regression is fairly easy. You generate a vector of X values of some range, you decide on some beta value and you generate random errors, and build a linear equation.
Now I want to do the same for a mixed model, with a random effect, and repeated measures. Why I want to do this ? For sample size estimation, I want to check how large should N be in my coming study. I do not know how to create the simulation. I don't mind using R or SAS, whatever you guys can help me with, fine with me.
Some words on my design. I have a continuous response variable Y. I have a fixed factor with two levels, I will call it X1 (treatment vs. control). These treatments are some operating techniques. There are two kind of operations these treatments can be applied on, A and B. This is a random factor, because there could be more, but only 2 will be examined. I will call the random factor Z1 (A vs. B). Each subject will have 2 operating procedures (repeated measures) of either type A or B (both repeated measures from the SAME type - both using SAME treatment, i.e., the new treatment or control).
I assume a correlation of 0.8 between repeated measures of the same subject, for all subjects. Let's also say I know or predict the means and standard deviations of the groups of X1, and the variance of Z1.
How do I simulate or generate data to fit this description so I can run a mixed model on it using various sample sizes and calculate the power ?
Thank you !
P.S My main problem is generating the correlations and to take into account the random effect.