【问题标题】:Paired T Test With a Class与班级配对 T 检验
【发布时间】:2015-04-05 11:48:15
【问题描述】:

我有一些看起来像这样的数据:

Date    Close   
12/31/2014  222.41  
12/30/2014  222.23  
12/29/2014  225.71
12/26/2014  227.82
12/24/2014  222.26
12/23/2014  220.97
12/22/2014  222.6
12/19/2014  219.29
12/18/2014  218.26

日期范围涵盖 2013 年至 14 年的整整两年。

我想在关闭时进行配对 T 测试,但我的语法很困难。大概我需要将日期转换为年份?还是我? 2013 年的每个日期都与 2014 年的另一个日期相匹配。

我可以在 csv 中更改我的数据并将其设置为:

   Date  | 2013_Close | 2014_Close
    Jan 1|  101       |  204
    Jan 2| 105        |  210

但如果我想避免这种情况,有没有办法对数据进行配对 T 检验?

这是我尝试过的,但收到了错误:

proc ttest data=tsla sides=2 alpha=0.05 h0=0;
class Date;
format Date year.;
var Close;
paired 2014*2013;
run;
ERROR 22-322: Syntax error, expecting one of the following: a name, (.
ERROR 76-322: Syntax error, statement will be ignored.

但即便如此,SAS 怎么会知道 2013 年和 14 年呢?在英语中,我需要告诉 SAS 在 Close 时运行配对 T 检验,其中配对日期为每年。

这有意义吗?我该怎么做?

【问题讨论】:

    标签: sas


    【解决方案1】:

    为了进行配对 T 检验,我认为您需要让数据看起来像这样:

    DayofYear   Close2013 Close2014
    365         222.41    222.26   
    364         222.23    220.97   
    363         225.71    222.6    
    362         227.82    219.29   
    361         222.26    222.41 
    360         220.97    222.23
    359         222.6     225.71
    358         219.29    227.82
    357         218.26    222.26
    

    执行此操作的一种方法是为DayofYear 创建一个变量,然后使用proc sql 将表的2013 部分自连接到表的2014 部分,如下所示:

    proc sql;
    select
      coalesce(t1.dayofyear,t2.dayofyear) as dayofyear,
      t1.close as close2013,
      t2.close as close2014
    from
      (select * from tsla where year(date)=2013) t1
      full outer join (select * from tsla where year(date)=2014) t2
      on t1.dayofyear = t2.dayofyear
    ;
    quit;
    ;
    quit;
    

    要运行测试,我认为您不需要 classvarformat 语句。只需 paired close2013*close2014; 声明即可。

    【讨论】:

    • 我不确定您的评论是什么意思。你说这行不通?如果不是,为什么?
    猜你喜欢
    • 2015-05-17
    • 2017-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-23
    • 2019-04-26
    相关资源
    最近更新 更多