Does anyone know of a SAS code to generate heteroscedastic variances for two groups (i.e., treatment vs. control)?
I think we need more information on what you're looking for.
Sorry I did not provide that much information to my earlier question. So basically, I want to simulate data where I can estimate and compare the variance between two groups (i.e., treatment vs. control) and it could be a simple t test, or ANOVA, or a multilevel model.
Thanks Reeza!
Rommel
You should be looking at contrast or estimate statements with hovtest= bf welch lavene .
These options will give you different variance tests. A good book with examples is analysis of messy data volume 1 by milliken and johnson.
Do you want to simulate, estimate or compare variances for two groups? - PG
Yes, I wanted to simulate where the treatment group has a greater variance compared to the control group. Any model could do: t-test, ANOVA, or better yet a multilvel model.
Thanks,
OK, here is a simulation of ANOVA with two groups, in the equal and unequal variances cases :
data test;
length case $16;
call streaminit(384239);
case = "EQUAL VARIANCES";
do group = "A", "B";
do _n_ = 1 to 50;
x = rand("NORMAL", 10, 2);
output;
end;
end;
case = "UNEQUAL VARIANCES";
group = "A";
do _n_ = 1 to 50;
x = rand("NORMAL", 10, 2);
output;
end;
group = "B";
do _n_ = 1 to 50;
x = rand("NORMAL", 10, 3);
output;
end;
run;
proc glm data=test;
by case;
class group;
model x = group;
means group / hovtest welch;
run;
PG
PG,
Thanks so much. This would give me a good starting point to learn how to simulate.
Rommel
PGStats,
I've strated writing simulation codes for multilevel mediation model for normal and non-normal combined with heteroscedastic variance. Would you be kind enough to take a look at my codes when you happen to have time?
Thanks so much for the help.
Rommel
Rommel,
Do you have SAS/IML licensed? If so, then take a look through 's blog, and find a wealth of information regarding simulation, with special parts on simulating from multivariable normal distributions, and correlated/clustered observations. IML is so much more powerful for simulation than DATA step programming that if simulation is going to be a major part of your work, you should consider getting a license.
Steve Denham
Yes Steve I have a SAS-IML license. And I have already looked through Rick Wicklin's blog and it's been very helpful. But right I would say I'm still at the very basic level of doing simulation. I wonder if at this point it's already ok to learn simulation in SAS-IML. I never knew it was more powerful though. But yes, I will start learnin SAS-IML. In fact, I already pre-ordered his book on simulation.
I really appreciate your advice.
Thanks Steve!
Rommel
Rick's book on simulation is excellent (not surprising) and starts with the very basics.
Thanks so much PG. One more question if you don't mind, do you have a sample simulation code to generate multilevel data?
Please be more precise. What would you like that data to look like?
Specifically, I want to generate a multilevel data where I have a treatment and a control group with the following
conditions:
a) two levels of clusters (20 and 40 groups)
b) two levels of sample size (10 for small sample and 20 for medium-sized sample)
c) for each sample size, 1/2 is assigned to treatment and 1/2 is to control
Given these, I want to generate data from a nonnormal distribution (chi-square dist with df=1) and a
heteroscedastic variance where treatment to control variance ratio is 8:1.
From there I want to assess how nonnormality and heteroscedasticity affects the power and type I error of a statistical test.
Thanks so much, PG! Let me know if you need more details.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.