Solved
New Contributor
Posts: 2

# Performing a Levene's test and Shapiro Wilk test

Hi, I have a pretty basic question although I am struggling to answer it.  I am new to SAS. I want to carry out a Levene's test and Shapiro Wilk test for variance and normality of some data.  It looks as though the Shapiro Wilk can by done using the Univariate procedure or the Model procedure.  The Univariate seems the more straight forward of the two.  I am having a lot of trouble structuring the data that I want the tests performed on.  To illustrate my question, let's say I have an experiment with two within subject factors, each with two levels.  The dependent variable is performance time to complete a reaction time task.  I have this data collated on a table with four columns: participant_ID, factor_1, factor_2 and Reaction_time.  I have 10 participants.  Each participant has entries on four rows, with a reaction time for each condition/combination of each factor, so "factor_1" can be either "level_1" or "level_2" and "factor_2" can be either "level_1" or "level_2". I want to assess the normality of the 10 participants'' reaction times for each condition, and the equality of variances of the 10 participants' reaction times between the four conditions.  I can't find a simple way to do this.  Can you help? Kind regards, Alexa.

Accepted Solutions
Solution
‎07-21-2016 11:13 PM
Posts: 2,655

## Re: Performing a Levene's test and Shapiro Wilk test

Remember, the assumption for ANOVA is NOT that the data are normally distributed, but that the errors are normally distributed.  A test of the data will probably lead you to a horrible place.  Consider the following:  You measure height in males and females.  If you just test height for normality, it will likely fail, because you have a bimodal distribution.  However, after removing the effect of sex and looking at the residuals for normality, you will likely see that a normal distribution fits pretty well, and so your assumptions are met.

Now, you can do all of this in a straightforward way, using as @Ksharp said, PROC GLM and PROC UNIVARIATE.  Try the following

``````proc glm data=yourdata;
class factor1 factor2;
model reactiontime = factor1*factor2; /* You need to look at a model with only the interaction, as Levene's test only applies to a one-way ANOVA)*/
means agegroup / hovtest=levene(type=abs) welch;
output out=resids r=residual;
run;

proc univariate data=resids normal;
var residual;
run;``````

Now, as far as your data are concerned, this is a good start at looking at some key factors.  However, your design is such that you may want to approach the analysis a bit differently.

But that is a topic for another day.

Steve Denham

All Replies
Super User
Posts: 10,210

## Re: Performing a Levene's test and Shapiro Wilk test

proc univariate can perform Normal Test.

proc glm can perform equal variance test(Levene's test).

proc univariate data=sashelp.class normal;
class sex;
var _numeric_;
run;

proc glm data=upsit;
class agegroup;
model smell = agegroup;
means agegroup / hovtest welch;
run;

Solution
‎07-21-2016 11:13 PM
Posts: 2,655

## Re: Performing a Levene's test and Shapiro Wilk test

Remember, the assumption for ANOVA is NOT that the data are normally distributed, but that the errors are normally distributed.  A test of the data will probably lead you to a horrible place.  Consider the following:  You measure height in males and females.  If you just test height for normality, it will likely fail, because you have a bimodal distribution.  However, after removing the effect of sex and looking at the residuals for normality, you will likely see that a normal distribution fits pretty well, and so your assumptions are met.

Now, you can do all of this in a straightforward way, using as @Ksharp said, PROC GLM and PROC UNIVARIATE.  Try the following

``````proc glm data=yourdata;
class factor1 factor2;
model reactiontime = factor1*factor2; /* You need to look at a model with only the interaction, as Levene's test only applies to a one-way ANOVA)*/
means agegroup / hovtest=levene(type=abs) welch;
output out=resids r=residual;
run;

proc univariate data=resids normal;
var residual;
run;``````

Now, as far as your data are concerned, this is a good start at looking at some key factors.  However, your design is such that you may want to approach the analysis a bit differently.

But that is a topic for another day.

Steve Denham

New Contributor
Posts: 2

## Re: Performing a Levene's test and Shapiro Wilk test

Dear Ksharp and Steve
Thanks for the help. Appreciated.
Kind regards, Alexa.
☑ This topic is solved.

Discussion stats
• 3 replies
• 1172 views
• 2 likes
• 3 in conversation