Sas 简明教程

SAS - T Tests

执行 T 检验是通过比较样本均值和均差来计算一个样本或两个独立样本的置信限度的。名为 PROC TTEST 的 SAS 程序用于对单个变量和变量对执行 t 检验。

The T-tests are performed to compute the confidence limits for one sample or two independent samples by comparing their means and mean differences. The SAS procedure named PROC TTEST is used to carry out t tests on a single variable and pair of variables.

Syntax

在 SAS 中应用 PROC TTEST 的基本语法是 −

The basic syntax for applying PROC TTEST in SAS is −

PROC TTEST DATA = dataset;
VAR variable;
CLASS Variable;
PAIRED Variable_1 * Variable_2;

以下是所用参数的描述 -

Following is the description of the parameters used −

  1. Dataset is the name of the dataset.

  2. Variable_1 and Variable_2 are the variable names of the dataset used in t test.

Example

下面我们看到一个样本 t 检验,其中找到具有 95% 置信限度的变量马力的 t 检验估计值。

Below we see one sample t test in which find the t test estimation for the variable horsepower with 95 percent confidence limits.

PROC SQL;
create table CARS1 as
SELECT make, type, invoice, horsepower, length, weight
   FROM
   SASHELP.CARS
   WHERE make in ('Audi','BMW')
;
RUN;

proc ttest data = cars1 alpha = 0.05 h0 = 0;
 	var horsepower;
   run;

在执行以上代码后,我们将得到以下结果:

When the above code is executed, we get the following result −

t test 1

Paired T-test

成对 T 检验用于检验两个因变量在统计上是否彼此不同。

The paired T Test is carried out to test if two dependent variables are statistically different from each other or not.

Example

由于汽车的长度和重量将相互依赖,因此我们应用成对 T 检验,如下所示。

As length and weight of a car will be dependent on each other we apply the paired T test as shown below.

proc ttest data = cars1 ;
   paired weight*length;
   run;

在执行以上代码后,我们将得到以下结果:

When the above code is executed, we get the following result −

t test 2

Two sample t-test

此 t 检验旨在比较两组之间相同变量的均值。

This t-test is designed to compare means of same variable between two groups.

Example

在我们的案例中,我们比较了两款不同品牌的汽车(“奥迪”和“宝马”)的变量马力的均值。

In our case we compare the mean of the variable horsepower between the two different makes of the cars("Audi" and "BMW").

proc ttest data = cars1 sides = 2 alpha = 0.05 h0 = 0;
   title "Two sample t-test example";
   class make;
   var horsepower;
   run;

在执行以上代码后,我们将得到以下结果:

When the above code is executed, we get the following result −

t test 3