卡方检验

  • 基本用法
PROC FREQ;
TABLES variable-combinations/options;

选项 这里有一些统计选项:

  • AGREE 检测分类性,包括McNemar’s test, Bowker’s test, Cochran’s Q test, and kappa statistics
  • CHISQ 用卡方统计量检测一致性和同类性
  • CL 一致性检测的置信区间
  • CMH Cochran-Mantel-Haenszel statistics
  • EXACT Fisher’s exact test for tables larger than 2X2
  • MEASURES 一致性测量,包括Pearson and Spearman correlation coefficients,gamma,Kendall’s tau-b,Stuart’s tau-c,Somer’s D
  • PLCORR polychoric correlation coefficient
  • RELRISK relative risk measures for 2X2 tables
  • TREND the Cochran-Armitage test for trend

DATA ADR;
    INPUT GRP RESP $ CNT @@;
    DATALINES;
1 YES 22   1 _NO 44
2 YES 28   2 _NO 24
;
 
/* GRP 1 = Test Drug,  GRP 2 = Control */
PROC FREQ DATA = ADR;
    TABLES GRP*RESP / CHISQ NOPERCENT NOCOL;
    WEIGHT CNT;
    TITLE1 'The Chi-Square Test';
    TITLE2 'Example 16.1: ADR Frequency with Antibiotic Treatment';
RUN;

单因素 ANOVA

DATA GAD;
    INPUT PATNO DOSEGRP $ HAMA @@;
    DATALINES;
101 LO 21  104 LO 18
106 LO 19  110 LO  .
112 LO 28  116 LO 22
120 LO 30  121 LO 27
124 LO 28  125 LO 19
130 LO 23  136 LO 22
137 LO 20  141 LO 19
143 LO 26  148 LO 35
152 LO  .  103 HI 16
105 HI 21  109 HI 31
111 HI 25  113 HI 23
119 HI 25  123 HI 18
127 HI 20  128 HI 18
131 HI 16  135 HI 24
138 HI 22  140 HI 21
142 HI 16  146 HI 33
150 HI 21  151 HI 17
102 PB 22  107 PB 26
108 PB 29  114 PB 19
115 PB  .  117 PB 33
118 PB 37  122 PB 25
126 PB 28  129 PB 26
132 PB  .  133 PB 31
134 PB 27  139 PB 30
144 PB 25  145 PB 22
147 PB 36  149 PB 32
;
 
PROC SORT DATA = GAD; BY DOSEGRP;
PROC MEANS MEAN STD N DATA = GAD;
    BY DOSEGRP;
    VAR HAMA;
    TITLE1 'One-Way ANOVA';
    TITLE2 'EXAMPLE 6.1: HAM-A Scores in GAD';
RUN;
 
PROC GLM DATA = GAD;
    CLASS DOSEGRP;
    MODEL HAMA = DOSEGRP;
    MEANS DOSEGRP/T DUNNETT('PB');
    CONTRAST 'ACTIVE vs. PLACEBO' DOSEGRP 0.5 0.5 -1;
RUN;
 

两因素 ANOVA


DATA HGBDS;
    INPUT TRT $  TYPE $  PATNO HGBCH @@;
    DATALINES;
ACT C  1  1.7   ACT C  3 -0.2   ACT C  6  1.7
ACT C  7  2.3   ACT C 10  2.7   ACT C 12  0.4
ACT C 13  1.3   ACT C 15  0.6   ACT P 22  2.7
ACT P 24  1.6   ACT P 26  2.5   ACT P 28  0.5
ACT P 29  2.6   ACT P 31  3.7   ACT P 34  2.7
ACT P 36  1.3   ACT R 42 -0.3   ACT R 45  1.9
ACT R 46  1.7   ACT R 47  0.5   ACT R 49  2.1
ACT R 51 -0.4   ACT R 52  0.1   ACT R 54  1.0
PBO C  2  2.3   PBO C  4  1.2   PBO C  5 -0.6
PBO C  8  1.3   PBO C  9 -1.1   PBO C 11  1.6
PBO C 14 -0.2   PBO C 16  1.9   PBO P 21  0.6
PBO P 23  1.7   PBO P 25  0.8   PBO P 27  1.7
PBO P 30  1.4   PBO P 32  0.7   PBO P 33  0.8
PBO P 35  1.5   PBO R 41  1.6   PBO R 43 -2.2
PBO R 44  1.9   PBO R 48 -1.6   PBO R 50  0.8
PBO R 53 -0.9   PBO R 55  1.5   PBO R 56  2.1
;
RUN;
 
PROC FORMAT;
    VALUE $TYPFMT 'C' = 'CERVICAL  '
                  'P' = 'PROSTATE  '
                  'R' = 'COLORECTAL' ;
RUN;
 
PROC SORT DATA = HGBDS;
    BY TRT TYPE;
 
PROC MEANS MEAN STD N;
    VAR HGBCH;
    BY TRT TYPE;
    FORMAT TYPE $TYPFMT.;
    TITLE1 'Two-Way ANOVA';
    TITLE2 'EXAMPLE 7.1: Hemoglobin Changes in Anemia';
RUN;
 
PROC GLM DATA = HGBDS;
    CLASSES TRT TYPE;
    MODEL HGBCH = TRT TYPE TRT*TYPE / SS3;
        MEANS TYPE / T;
        LSMEANS TYPE / PDIFF STDERR;
    FORMAT TYPE $TYPFMT.;
RUN;

回归模型


/*Example 10.1 (Anti-anginal Response vs. Disease History) */
 
DATA ANGINA;
    INPUT PAT X_DUR Y_IMPR @@;
    DATALINES;
 1 1  40    2 1  90    3 3  30    4 2  30
 5 1  80    6 5  60    7 1  10    8 4 -10
 9 2  50   10 6  40   11 1  60   12 4   0
13 2  50   14 2 110   15 3  20   16 3  70
17 5 -30   18 3  20   19 1  40   20 6   0
;
 
PROC SORT DATA = ANGINA; BY X_DUR Y_IMPR;
PROC PRINT DATA = ANGINA;
    VAR PAT X_DUR Y_IMPR;
    TITLE1 'Linear Regression & Correlation';
    TITLE2 'Example 10.1: Improvement in Angina vs. Disease Duration';
RUN;
 
PROC MEANS MEAN STD N;
    VAR X_DUR Y_IMPR;
RUN;
 
PROC GLM DATA = ANGINA;
    MODEL Y_IMPR = X_DUR / P CLM SS1;
RUN;