The script begins by creating an internal dataset 'toxoplasmosis' via a DATA STEP and datalines, including variables for the number of successes (t), the total number of trials (m), and a 'rain' variable which is copied to 'z'. Then, the 'z' variable is standardized using PROC STDIZE. A PROC GLIMMIX is used to fit a generalized linear mixed model with a logit link and binomial distribution, modeling 't/m' as a function of 'z', 'z*z' and 'z*z*z'. Model predictions are exported for score statistic calculation. A subsequent DATA STEP calculates intermediate terms necessary for the test. PROC MEANS aggregates these terms, and a final DATA STEP calculates the Z-statistic of the score test and its associated p-value. Finally, PROC PRINT displays the results in formatted HTML output.
Data Analysis
Type : INTERNAL_CREATION
Data is created directly within the script via a DATA STEP and 'datalines'.
1 Code Block
DATA STEP Data
Explanation : This DATA STEP block creates the 'toxoplasmosis' dataset by reading raw data (t, m, rain) directly from 'datalines'. A new variable 'z' is created as a copy of the 'rain' variable.
Explanation : This procedure standardizes the 'z' variable in the 'toxoplasmosis' dataset. The output dataset overwrites the original, ensuring that subsequent calculations use the standardized version of 'z'.
Copied!
proc stdize data=toxoplasmosis out=toxoplasmosis;
var z;
run;
1
2
PROC STDIZE
3
DATA=toxoplasmosis out=toxoplasmosis;
4
var z;
5
6
RUN;
7
3 Code Block
PROC GLIMMIX
Explanation : PROC GLIMMIX is used to fit a generalized linear mixed model. The model specifies a binomial response (t/m), a logit link function, and includes 'z', 'z*z', and 'z*z*z' as predictors. The 's' option requests summary statistics. The 'output' clause creates a new dataset 'pdata' containing predicted probabilities ('pi') without random effects (noblup) and on the response scale (ilink).
Explanation : This DATA STEP reads the 'pdata' dataset (created by GLIMMIX) and calculates several intermediate variables ('pic', 'pipic', 'mpi', 't_mpi', 'pit_mpi', 'tpic', 'mm_1', 'aux') necessary for Dean's score test statistic formula. Only 'aux' and 'mm_1' are kept for subsequent steps.
Copied!
data pdata;
set pdata;
pic = 1 - pi;
pipic = pi * pic;
mpi = m * pi;
t_mpi = t - mpi;
pit_mpi = pi * t_mpi;
tpic = t * pic;
mm_1 = m * (m-1);
aux = ( t_mpi*t_mpi + pit_mpi - tpic ) / pipic;
keep aux mm_1;
run;
1
DATA pdata;
2
SET pdata;
3
pic = 1 - pi;
4
pipic = pi * pic;
5
mpi = m * pi;
6
t_mpi = t - mpi;
7
pit_mpi = pi * t_mpi;
8
tpic = t * pic;
9
mm_1 = m * (m-1);
10
aux = ( t_mpi*t_mpi + pit_mpi - tpic ) / pipic;
11
keep aux mm_1;
12
RUN;
5 Code Block
PROC MEANS
Explanation : PROC MEANS is used here to calculate the sum of 'aux' and 'mm_1' variables across the entire 'pdata' dataset. The result is stored in a new dataset called 'new', and the 'noprint' option suppresses the display of PROC MEANS' default output.
Copied!
proc means data=pdata sum noprint;
var aux mm_1;
output out=new sum=aux mm_1;
run;
1
PROC MEANSDATA=pdata sum noprint;
2
var aux mm_1;
3
OUTPUT out=new sum=aux mm_1;
4
RUN;
6 Code Block
DATA STEP
Explanation : This DATA STEP reads the 'new' dataset (containing the sums of 'aux' and 'mm_1') and calculates the Z-statistic of the score test as well as its p-value ('pval'). Formats and labels are applied to the variables for better presentation.
Copied!
data new;
set new;
label Z = "GOF Test";
label PVal = "P-Value";
format Z 8.2 Pval pvalue6.;
z = aux / sqrt( 2*mm_1 );
pval = 1 - probnorm( z );
run;
1
DATA new;
2
SET new;
3
label Z = "GOF Test";
4
label PVal = "P-Value";
5
FORMAT Z 8.2 Pval pvalue6.;
6
z = aux / sqrt( 2*mm_1 );
7
pval = 1 - probnorm( z );
8
RUN;
7 Code Block
PROC PRINT
Explanation : This block generates the final output. ODS HTML is enabled to direct output to an HTML file (or the SAS Studio environment). A title is set. PROC PRINT is used to display the 'z' (test statistic) and 'pval' (p-value) variables from the 'new' dataset. The 'noobs' option suppresses the observation number, and 'label' uses the defined labels for column headers. ODS HTML is then closed.
Copied!
ods html;
title "Score Test Statistic, Dean (1992)";
proc print data=new noobs label;
var z pval;
run;
ods html close;
1
ods html;
2
title "Score Test Statistic, Dean (1992)";
3
PROC PRINTDATA=new noobs label;
4
var z pval;
5
RUN;
6
ods html close;
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.
Copyright Info : Score Test Statistic, Dean (1992). Example from Efron (1978, 1986).
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.