SAS中文论坛

标题: 请教:TRIPLES [打印本页]

作者: shiyiming    时间: 2011-2-1 08:02
标题: 请教:TRIPLES
在做symmetry test时需要用到triples, 就是说,任意组合的不重复的三个观测。
比如4个观测1 2 3 4 那么所有的triples就是:1 2 3, 12 4, 1 3 4, 234 四组。如果是1 2 3 4 5, 那么123 124 125 134 135 145 234 235 245 345 十组.如果n很大,组数将会很多很多(3Pn?)。
以下为例:
data have;
do i =1 to 5000;
x =rannor(11); output;
end;
run;
得到的数据集应该是:
i1 i2 i3
1 2 3
1 2 4
...
1 2 5000
1 3 4
...
4998 4999 5000
总共应该是20,820,835,000个观测
作者: shiyiming    时间: 2011-2-1 09:16
标题: Re: 请教:TRIPLES
to jingju11
你这招已经杀死了PROC PLAN,不过死扛DATA STEP还勉强能活

data x;
        do j=1 to 5000-2;
                    do i=(j+1) to 5000-1;  
                            do k=i+1 to 5000;
                                    output;
                                end;
                        end;
                end;
run;

准备喝一上午的茶吧
作者: shiyiming    时间: 2011-2-1 11:39
标题: Re: 请教:TRIPLES
谢谢。另外我的本意如此:我是要把数据have转化生triples的形式,而不是纯粹创造一个数据集。说的具体些这个数据应该是

i1 i2 i3 X1 X2 X3

1 2 3 0.354 0.222 -1.21
1 2 4 0.665 2.00 -0.05
....
其中(i1,x1)对应了一列数据(i,x)。。。
我的目标最后是要检验已有数据have的对称程度,而triples只是其中permutation计算所需要的。。。(also called distribution-free symmetry test)
作者: shiyiming    时间: 2011-2-1 14:37
标题: Re: 请教:TRIPLES
to jingju11
easy, man
[code:xyu6fc2j]
data triple;
        array _x{5000} _temporary_;
        array _x2{3}  x1-x3;
        if _n_=1 then
            do  i1=1 to ntotal;
                  set have nobs=ntotal;
                  _x[i1]=x;
            end;
        do i1=1 to dim(_x)-2;
             do i2=i1+1 to dim(_x)-1;
                  do i3=i2+1 to dim(_x);
                       _x2[1]=_x[i1]; _x2[2]=_x[i2]; _x[3]=_x[i3];
                       output;
                  end;
             end;
        end;
run;
[/code:xyu6fc2j]

not tested yet
作者: shiyiming    时间: 2011-2-1 14:46
标题: Re: 请教:TRIPLES
to jingju11
奥利奥生成的数据集可以用来做为取数的索引。可以预先生成一系列的中间数据集,以后都用来做索引,多好啊。
作者: shiyiming    时间: 2011-2-2 00:09
标题: Re: 请教:TRIPLES
谢谢。
我用5个观测的数据去测试,发现你的输出数据集有20个观测。据我的理解应该有10个观测。也不知道其中的原因?
作者: shiyiming    时间: 2011-2-2 03:26
标题: Re: 请教:TRIPLES
to jingju11
sorry, pls add "STOP;" right before "RUN;" statement, like:
[code:26c0p1if]
data have;
     do i=1 to 5;
            x=ranuni(0);
                output; drop i;
         end;
run;
data triple;
        array _x{5} _temporary_  ;
        array _x2{3}  x1-x3;
        if _n_=1 then
            do  k=1 to ntotal;
                  set have nobs=ntotal;
                  _x[k]=x;
            end;        
        do i1=1 to dim(_x)-2;
             do i2=i1+1 to dim(_x)-1;
                  do i3=i2+1 to dim(_x);
                       _x2[1]=_x[i1]; _x2[2]=_x[i2]; _x2[3]=_x[i3];
                      drop k x;
                     output;
                  end;
             end;
        end;
       stop;
run;
[/code:26c0p1if]
作者: shiyiming    时间: 2011-2-4 00:27
标题: Re: 请教:TRIPLES
首先祝大家春节快乐。
谢谢oloolo。你的程序很好。如果data 是1000, 差不多两三分钟即可。只是如果观测数增加到5000, 运行一段时间之后,程序结束报告:资源不足。我自己的用set的random access也大致差不多的结局。我的困惑是,如果做有选择的output,有可能成功吗?也就是说,output的过程占用I/O, CPU , MEMORY?哪一个呢?如果只是占用cpu,考虑output与否显然是没有意义的。谢谢。
作者: shiyiming    时间: 2011-2-4 09:04
标题: Re: 请教:TRIPLES
to jingju11
估计跟内存,CPU 没啥关系,主要怕是你的磁盘空间不够了,如果在server上,会不会被admin给干预了?
因为你的3个id都是1--5000的小整形数,设定他们的长度为4,而不是默认的8;如果闲麻烦,直接compress=binary应该有效
另外只保留你要的数据

5000个的话你这个配下来可是200多亿条的记录数
作者: shiyiming    时间: 2011-2-4 23:15
标题: Re: 请教:TRIPLES
如果output所有的数据是不现实的,那么也许我应该在输出之前算出所需要的统计量了。
作者: shiyiming    时间: 2011-2-5 06:39
标题: Re: 请教:TRIPLES
to jingju11
I guess the total size of the output file would be:
N=(20820835000*(3*8+3*4))/1024/1024/1024~=698GB?
correct me if my calculation is wrong

you can try DATA _null_ first to obtain a ball park estimate on how long it will take.




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2