SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 1175|回复: 9
打印 上一主题 下一主题

求救! 哪位高人能写出这个题的SAS code!!!!!!!

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2009-9-11 08:07:10 | 只看该作者

求救! 哪位高人能写出这个题的SAS code!!!!!!!

In one of the Louis Vuitton Cup challenger series, there were 9 competing syndicates. Let‟s call then Boats 1 to 9. Suppose that we rank the boats with a score from 1 to 9, so that Boat 1 (the slowest) has value 1, Boat 2 (the second slowest) has values 2, up to Boat 9 (the fastest) having value 9. Then suppose when Boats i and j compete, that Boat i will win with probability i/(i + j), and Boat j will win with probability j/(i + j), and there are no draws.
There are two rounds. In Round 1, suppose a win means 1 point and a loss means no points. In Round 2, suppose a win means 2 points and a loss no points. Then whatever boat having the highest cumulative points by the end of Round 2 will be the challenger for the America‟s cup, i.e., sail against the defender (Team New Zealand). In Round 1, every possible combination of pairwise boat race will be staged. Similarly, for Round 2. Thus, there will be 72 boat races in total; each boat will race 16 times.
We want to estimate the probability that Boat 9 outrightly wins, and also the probability that Boat 9 draws, the Louis Vuitton Cup. With these, we want an associated 95% confidence interval.
Write a SAS program to simulate the above description. Run your simulation 10000 times. Please make sure you heed the following instructions.
(i) Print the output from 10000 simulations. If your log file is „big‟, then only print the log file coming from 3 simulations.
(ii) You should clearly stat the values of your two estimates. Your print out should be well labelled and reasonably understandable. You can calculate your confidence intervals by hand.
(iii) By an “outright” win, after 72 races, it might be that two or more boats each have the same number of points (i.e., the boats are first equal). Then this is a draw, and not an outright win. An outright win will occur when the number of points of one of the boats is strictly greater than all the other boats.
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2009-9-11 13:04:47 | 只看该作者

Re: 求救! 哪位高人能写出这个题的SAS code!!!!!!!

[code:2nj2hx70]
data ran(where=(i^=j));
        do k=1 to 10000;
                do i=1 to 9;
                        do j=1 to 9;
                                if j=i then do;
                                        s1=0;
                                        s2=0;
                          end;
                          else do;
                                  s1=(ranuni(0)<=(i/(i+j))) ;
                                  s2=2*(ranuni(0)<=(i/(i+j))) ;
                          end;
                          s=s1+s2;
                     output;
                        end;
                end;
        end;
run;
proc sql;
        create table ran_ as
                select k, ifn(sum(ss2)=10,1,ifn(sum(ss2)>0,2,3)) as ss3, 2-(calculated ss3=1) as win,   2-(calculated ss3=2) as draw  
                        from (select k,i,ss, (ss-max(ss)=0) as ss1, ifn(calculated ss1=0, 0, ifn(i=9,10,-1) ) as ss2
                                                        from (select k,i ,sum(s)  as ss
                                                                                        from ran
                                                                                        group by k,i)
                                                        group by k)
                  group by k;
quit;

proc format;
value winFmt 1='win' 2='not win';
value drawFmt 1='draw' 2='not draw';
proc freq data=ran_;
format win winFmt. draw drawFmt.;
tables win draw;
exact binomial;
run;[/code:2nj2hx70]

不知道理解的对不对?
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
板凳
 楼主| 发表于 2009-9-13 16:40:42 | 只看该作者

Re: 求救! 哪位高人能写出这个题的SAS code!!!!!!!

proc sql;
        create table ran_ as
                select k, ifn(sum(ss2)=10,1,ifn(sum(ss2)>0,2,3)) as ss3, 2-(calculated ss3=1) as win,   2-(calculated ss3=2) as draw  
                        from (select k,i,ss, (ss-max(ss)=0) as ss1, ifn(calculated ss1=0, 0, ifn(i=9,10,-1) ) as ss2
                                                        from (select k,i ,sum(s)  as ss
                                                                                        from ran
                                                                                        group by k,i)
                                                        group by k)
                  group by k;
quit;

这一步可以用简单的方式写吗? 我还没有学到 proc sql 看不懂 <!-- s:( --><img src="{SMILIES_PATH}/icon_sad.gif" alt=":(" title="Sad" /><!-- s:( -->
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
地板
 楼主| 发表于 2009-9-15 07:37:11 | 只看该作者

Re: 求救! 哪位高人能写出这个题的SAS code!!!!!!!

怎样才能看到 boat 9 win  draw 和loss 的次数呢 boat 1 和boat2比  boat 2和 boat 1比 不就重复了吗
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
5#
 楼主| 发表于 2009-9-15 08:32:14 | 只看该作者

Re: 求救! 哪位高人能写出这个题的SAS code!!!!!!!

sorry。我没有看到这一点。其实我的程序是比赛了72×2=144场。显然错了。
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
6#
 楼主| 发表于 2009-9-15 08:35:35 | 只看该作者

Re: 求救! 哪位高人能写出这个题的SAS code!!!!!!!

那应该怎么改呢 想要把第九只穿的输赢单列出来
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
7#
 楼主| 发表于 2009-9-15 09:28:18 | 只看该作者

Re: 求救! 哪位高人能写出这个题的SAS code!!!!!!!

[code:3ga4nqcp]
*these are the scores for the boats but without counting scores for matched boats;
data BoatScore;
        do sample=1 to 10000;*sampling 10,000 times;
                do boat=1 to 8;
                        do MatchedBoat=boat+1 to 9;
                                  stage1=    (ranuni(0)&lt;=(boat/(boat+MatchedBoat))) ; *score at stage1 match;
                                  stage2=2*(ranuni(0)&lt;=(boat/(boat+MatchedBoat))) ; *score at stage2 match;
                                  int=matchedBoat;
                             totScore=stage1+stage2; *total scores for a boat after two-stage match;
                               output;
                        end;
                end;
        end;
        drop int;
run;
*these are the scores for matched boats;
data MatchedBoatScore;
        set BoatScore;
        int=Boat;
        Boat=MatchedBoat;
        MatchedBoat=int;
        stage1=1-stage1;
        stage2=2-stage2;
        totScore=stage1+stage2; *total scores for a boat after two-stage match;
        drop int;
run;
*all scores;
data Score;
        set BoatScore MatchedBoatScore;
run;
proc sort; by sample boat matchedboat; run;
[/code:3ga4nqcp]
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
8#
 楼主| 发表于 2009-9-15 11:04:05 | 只看该作者

Re: 求救! 哪位高人能写出这个题的SAS code!!!!!!!

算出来的结果还是不对的 9号船的最高分可以使24  这里只有3分
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
9#
 楼主| 发表于 2009-9-15 12:06:54 | 只看该作者

Re: 求救! 哪位高人能写出这个题的SAS code!!!!!!!

其实任何一条船在两回合16场比赛的最高得分都可能是8×1+2×8=24,只不过几率不同而已。我们来看一条观测值

[quote:3gc269x4]
sample boat MatchedBoat stage1 stage2 totScore
10---------9------3--------------------0----------2----------2
[/quote:3gc269x4]

在第10个sample里,船9 和船3 比赛,第一回合船9 输,不得分;第二回合船9赢,得两分;船9总共得2分。那么对于船3来说,它的得分是1+0=1;这就是我matchedScore 数据做的;
依次类推,船9 还要和船1 2 4 5 6 7 8 进行两回合的比赛。所以船9 的总得分应该是它们之和。然后对各船在一个sample里的总得分做个排序(主要是船9 的次序)。这也是那个sql过程要做的。
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
10#
 楼主| 发表于 2009-9-15 12:50:07 | 只看该作者

Re: 求救! 哪位高人能写出这个题的SAS code!!!!!!!

data BoatScore;

    array points{9} points1-points9;

    keep win9 draw9 points1-points9;

   

   do sample=1 to 10000;*sampling 10,000 times;

        do i=1 to 9;

            points(i) = 0;

        end;

      do boat=1 to 2;

        if boat = 1 then winpoint = 1; else winpoint = 2;

         do MatchedBoat=1 to 8;

                do nextmatchedboat = matchedboat+1 to 9;

              if ranuni(0)&lt;(boat/(boat+MatchedBoat))  then points(matchedboat) = points(matchedboat) + winpoint;

              else points(nextmatchedboat) = points(nextmatchedboat) + winpoint; *score at stage1 match;

              *if ranuni(0)&lt;=(boat/(boat+MatchedBoat)) ; *score at stage2 match;

           

              *totScore=stage1+stage2; *total scores for a boat after two-stage match;

                *output;

            end;

        end;

      end;

        output;

      end;

run;



  proc print;

  run;

用这个做出来的数据就不一样

但是怎么用max 把每一次最大值提出来呢
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2026-2-5 23:15 , Processed in 0.385422 second(s), 21 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表