Published on :
Statistics INTERNAL_CREATION

Statistical Power Analysis (GLM and T-test)

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by creating a 'sleep' dataset simulating recall scores for different durations ('hours'). It then executes PROC GLMPOWER to determine the necessary sample size in a general linear model (ANOVA) to achieve powers of 0.7, 0.8, and 0.9. Finally, it uses PROC POWER to calculate the sample size required for a two-sample means comparison test (t-test) with a mean difference of 3 and a standard deviation of 30.
Data Analysis

Type : INTERNAL_CREATION


Data is generated via a DATA step with DATALINES statements (values 30 and 33).

1 Code Block
DATA STEP Data
Explanation :
Creation of the 'sleep' dataset containing an explanatory variable 'hours' (1 and 2) and a response variable 'recall' read from the datalines.
Copied!
1DATA sleep;
2 DO hours = 1 to 2;
3 INPUT recall;
4 OUTPUT;
5 END;
6 DATALINES;
730
833
9;
10RUN;
2 Code Block
PROC GLMPOWER
Explanation :
Power analysis for a general linear model (here, a one-way ANOVA with factor 'hours'). The script requests the calculation of the total sample size (ntotal = .) for target powers of 0.7, 0.8, and 0.9, with an assumed standard deviation of 30. A plot of power versus sample size is generated.
Copied!
1PROC GLMPOWER DATA=sleep;
2 class hours;
3 model recall = hours;
4 power
5 stddev = 30
6 ntotal = .
7 power = 0.7 0.8 0.9;
8 plot x=power min=0.7 max=0.95;
9RUN;
3 Code Block
PROC POWER
Explanation :
Power calculation for a two-sample means comparison test (t-test). Parameters: expected mean difference of 3, alpha of 0.05, standard deviation of 30. The code requests the required sample size for the specified power levels.
Copied!
1PROC POWER;
2 twosamplemeans
3 meandiff=3
4 alpha=0.05
5 ntotal = .
6 power = 0.7 0.8 0.9
7 stddev = 30
8 ;
9RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.