## Checking Normality

Solved
Occasional Contributor
Posts: 12

# Checking Normality

I AM GOING TO DO A SIMULATION CHECKING NORMALITY. UNIVARIATE PROCEDURE WAS USED. THEN OUTPUT GIVES MULTIPLE TEST  STATISTICS VALUES(4). I WANT TO FIND THE POWER OR TYPE 1 ERROR.

HOW CAN I DO THIS?

HOW CAN I USE ONLY VALUES OF 2 TEST STATISTICS FROM THE OUTPUT. IT MEANS SUPPOSE I NEED TO USE P VALUE AND TEST STATISTICS VALUE OF Shapiro-Wilk AND Cramer-von Mises. HOW CAN I CHOOSE ONLY THESE TWO VALUES FROM THE TEST FOR NORMALITY TABLE.

Accepted Solutions
Solution
‎11-02-2015 06:13 PM
Super Contributor
Posts: 301

## Re: Checking Normality

If you want to simulate power you can use the univariate procedure with "by" on the iterator variable from the simulation. Afterwards, you calculate the chance of reject the hypothesis (which is the same as power). In the code below I calculate the power of rejecting that data from a t(4) distribution is not Normal.

Be aware that the p-values from the univariate procedure is just checking for normality, not a specific normal distriution (N(0,1) for instance)

*simulate data from t-distributions with 4 degrees of freedom:

data simulation;

do sim=1 to 1000;

do i=1 to 100;

y=rand('t',4);

output;

end;

end;

run;

*Test for normality;

ods listing close;

proc univariate data=simulation normaltest;

var y;

ods output TestsForNormality=normaltest;

by sim;

run;

ods listing;

*create 0/1 variable for rejection of hyphotesis;

data normaltest;

set normaltest;

reject=(pValue<0.05);

run;

*calculate the chance of rejection;

proc means data=normaltest mean;

var reject;

class Test;

run;

All Replies
Posts: 5,054

## Re: Checking Normality

Use ODS to get statistics and p-values:

``````proc univariate data=sashelp.class normal;
var weight;
ods output TestsForNormality=tn(where=(TestLab in ("W","W-Sq")));
run;
``````
PG
Occasional Contributor
Posts: 12

## Re: Checking Normality

PGStats, Thank you very much for your help. It is very helpfull for my other program too.

Thank you Again!

Solution
‎11-02-2015 06:13 PM
Super Contributor
Posts: 301

## Re: Checking Normality

If you want to simulate power you can use the univariate procedure with "by" on the iterator variable from the simulation. Afterwards, you calculate the chance of reject the hypothesis (which is the same as power). In the code below I calculate the power of rejecting that data from a t(4) distribution is not Normal.

Be aware that the p-values from the univariate procedure is just checking for normality, not a specific normal distriution (N(0,1) for instance)

*simulate data from t-distributions with 4 degrees of freedom:

data simulation;

do sim=1 to 1000;

do i=1 to 100;

y=rand('t',4);

output;

end;

end;

run;

*Test for normality;

ods listing close;

proc univariate data=simulation normaltest;

var y;

ods output TestsForNormality=normaltest;

by sim;

run;

ods listing;

*create 0/1 variable for rejection of hyphotesis;

data normaltest;

set normaltest;

reject=(pValue<0.05);

run;

*calculate the chance of rejection;

proc means data=normaltest mean;

var reject;

class Test;

run;

SAS Super FREQ
Posts: 3,839

## Re: Checking Normality

Jacob has the right approach. If you would like to see another example that has more explanatory text, see the article "Using simulation to estimate the power of a statistical test."

Occasional Contributor
Posts: 12

## Re: Checking Normality

Dr.Wicklin,

Thank you so much for your comment. You always help and give good reference for us. I like very mcuh your simulation and programming book too.

Thank you again!

Occasional Contributor
Posts: 12

## Re: Checking Normality

Jacob,
Thank you very much for your time and help. This is perfect and you save my time...
Than you Again!
Occasional Contributor
Posts: 12

## Re: Checking Normality

I used above program that work well. But, Its print univariate out put. I use 100000 simulation and take too much time to get the power. When I use "noprint" it doesn't work. Says "variable TEST not found". Can I stop printing the univariate output and get the power only? I greately appriciate your help, Jacob, or anybody

Super Contributor
Posts: 301

## Re: Checking Normality

Maybe, the problem is that you have per default get your output printed to html. In that case, use the program above, but with no html output from the univariate procedure (I had html turned off per default).

Like this:

``````ods listing close;
ods html close;
proc univariate data=simulation normaltest;
var y;
ods output TestsForNormality=normaltest;
by sim;
run;
ods listing;
ods html;``````
Occasional Contributor
Posts: 12

## Re: Checking Normality

Dear Jacob, Thank you very very much for your quick reply and great help.This work now. I spent about a week for this.
You save my time. Again, I greatly appreciate your great help.
SAS Super FREQ
Posts: 3,839

## Re: Checking Normality

To see how to exclude ODS output, see the following articles:

Turn of ODS for simulation: http://blogs.sas.com/content/iml/2013/05/24/turn-off-ods-for-simulations.html

Why ODS EXCLUDE is best: http://blogs.sas.com/content/iml/2015/05/28/five-reasons-ods-exclude.html

Occasional Contributor
Posts: 12

## Re: Checking Normality

Thank you very much!
🔒 This topic is solved and locked.