BookmarkSubscribeRSS Feed
dessert_fox
Calcite | Level 5


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

17 REPLIES 17
Reeza
Super User

I think we need more information on what you're looking for.

dessert_fox
Calcite | Level 5

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

Saszealot
Calcite | Level 5

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.

PGStats
Opal | Level 21

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

PG
dessert_fox
Calcite | Level 5

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,

PGStats
Opal | Level 21

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
dessert_fox
Calcite | Level 5

PG,

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

Rommel

dessert_fox
Calcite | Level 5

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

SteveDenham
Jade | Level 19

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

dessert_fox
Calcite | Level 5

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

plf515
Lapis Lazuli | Level 10

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

sirerwin
Calcite | Level 5

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

PGStats
Opal | Level 21

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

PG
sirerwin
Calcite | Level 5

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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