47  t检验

import saspy
sas = saspy.SASsession(
    results='HTML'
)

说明: 以上代码在render时老是报ERROR: Expecting value: line 1 column 1 (char 0)

47.1 单样本t检验

%%SAS sas
data time;
      input time @@;
      datalines;
43  90  84  87  116   95  86   99   93  92
   121  71  66  98   79  102  60  112  105  98
;
run;

ods graphics on;
proc ttest h0=80 plots(showh0) sides=u alpha=0.1;  /*与给定值h0比较, alpha=0.05,则得到95%CI*/
      var time;
run;  
ods graphics off;

h0在90%CI以外,也印证了差异的存在。

SIDES=2 (the default) specifies two-sided tests and confidence intervals for means.

SIDES=L specifies lower one-sided tests, in which the alternative hypothesis indicates a mean less than the null value, and lower one-sided confidence intervals between minus infinity and the upper confidence limit.

SIDES=U specifies upper one-sided tests, in which the alternative hypothesis indicates a mean greater than the null value, and upper one-sided confidence intervals between the lower confidence limit and infinity.

47.2 两独立样本t检验

If you want to compare values obtained from two different groups, and if the groups are independent of each other and the data are normally or lognormally distributed in each group, then a group test can be used.

%%SAS sas
data scores;
input Gender$ Score @@;
datalines;
f 75  f 76  f 80  f 77  f 80  f 77  f 73
m 82  m 80  m 85  m 85  m 78  m 87  m 82
   ;
run;


ods graphics on;
proc ttest data=scores cochran ci=equal umpu;
    class Gender;
    var Score;
run;
ods graphics off;

The dollar sign ($) following Gender in the INPUT statement indicates that Gender is a character variable. The trailing at signs (@@) enable the procedure to read more than one observation per line.

For the mean differences, both pooled (assuming equal variances for males and females) and Satterthwaite (assuming unequal variances) 95% intervals are shown. The confidence limits for the standard deviations are of the equal-tailed variety.

The Method column denotes which test is being used for that row, and the Variances column indicates what assumption about variances is being made. The pooled test assumes that the two populations have equal variances and uses degrees of freedom , where and are the sample sizes for the two populations. The remaining two tests do not assume that the populations have equal variances. The Satterthwaite test uses the Satterthwaite approximation for degrees of freedom, while the Cochran test uses the Cochran and Cox approximation for the -value. All three tests result in highly significant -values, supporting the conclusion of a significant difference between males’ and females’ golf scores.

The “Equality of Variances” test in Figure 92.7 reveals insufficient evidence of unequal variances (the Folded F statistic F‘=1.53, with p value=0.6189).

47.3 配对t检验

%%SAS sas
data pressure;
         input SBPbefore SBPafter @@;
         datalines;
120 128   124 131   130 131   118 127
   140 132   128 125   140 141   135 137
126 118   130 132   126 129   127 135
   ;
run;

ods graphics on;
   
proc ttest;
      paired SBPbefore*SBPafter;
run;
   
ods graphics off;

The PAIRED statement is used to test whether the mean change in systolic blood pressure is significantly different from zero.

The variables SBPbefore and SBPafter are the paired variables with a sample size of 12. The summary statistics of the difference are displayed (mean, standard deviation, and standard error) along with their confidence limits. The minimum and maximum differences are also displayed. The test is not significant , indicating that the stimuli did not significantly affect systolic blood pressure.

The agreement plot in Output 92.3.3 reveals that only three men have higher blood pressure before the stimulus than after.

But the differences for these men are relatively large, keeping the mean difference only slightly negative.

The profiles plot in Output 92.3.4 is a different view of the same information contained in Output 92.3.3, plotting the blood pressure from before to after the stimulus.

The Q-Q plot shows no obvious deviations from normality. You can check the assumption of normality more rigorously by using PROC UNIVARIATE with the NORMAL option.

sas.disconnect()