## heteroscedastic variances

Occasional Contributor
Posts: 11

# heteroscedastic variances

Does anyone know of a SAS code to generate heteroscedastic variances for two groups (i.e., treatment vs. control)?

Super User
Posts: 23,683

## Re: heteroscedastic variances

Occasional Contributor
Posts: 11

## Re: heteroscedastic variances

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

Contributor
Posts: 46

## Re: heteroscedastic variances

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.

Posts: 5,523

## Re: heteroscedastic variances

Do you want to simulate, estimate or compare variances for two groups? - PG

PG
Occasional Contributor
Posts: 11

## Re: heteroscedastic variances

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,

Posts: 5,523

## Re: heteroscedastic variances

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
Occasional Contributor
Posts: 11

## Re: heteroscedastic variances

PG,

Thanks so much. This would give me a good starting point to learn how to simulate.

Rommel

Occasional Contributor
Posts: 11

## Re: heteroscedastic variances

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

Posts: 2,655

## Re: heteroscedastic variances

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

Occasional Contributor
Posts: 11

## Re: heteroscedastic variances

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.

Thanks Steve!

Rommel

Frequent Contributor
Posts: 147

## Re: heteroscedastic variances

Rick's book on simulation is excellent (not surprising) and starts with the very basics.

Occasional Contributor
Posts: 8

## Re: heteroscedastic variances

Thanks so much PG. One more question if you don't mind, do you have a sample simulation code to generate multilevel data?

Posts: 5,523

## Re: heteroscedastic variances

Please be more precise. What would you like that data to look like?

PG
Occasional Contributor
Posts: 8

## Re: heteroscedastic variances

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.

Discussion stats
• 17 replies
• 786 views
• 3 likes
• 7 in conversation