标题: 求救! 哪位高人能写出这个题的SAS code!!!!!!! [打印本页] 作者: shiyiming 时间: 2009-9-11 08:07 标题: 求救! 哪位高人能写出这个题的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.作者: shiyiming 时间: 2009-9-11 13:04 标题: 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]
不知道理解的对不对?作者: shiyiming 时间: 2009-9-13 16:40 标题: 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:( -->作者: shiyiming 时间: 2009-9-15 07:37 标题: Re: 求救! 哪位高人能写出这个题的SAS code!!!!!!! 怎样才能看到 boat 9 win draw 和loss 的次数呢 boat 1 和boat2比 boat 2和 boat 1比 不就重复了吗作者: shiyiming 时间: 2009-9-15 08:32 标题: Re: 求救! 哪位高人能写出这个题的SAS code!!!!!!! sorry。我没有看到这一点。其实我的程序是比赛了72×2=144场。显然错了。作者: shiyiming 时间: 2009-9-15 08:35 标题: Re: 求救! 哪位高人能写出这个题的SAS code!!!!!!! 那应该怎么改呢 想要把第九只穿的输赢单列出来作者: shiyiming 时间: 2009-9-15 09:28 标题: 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)<=(boat/(boat+MatchedBoat))) ; *score at stage1 match;
stage2=2*(ranuni(0)<=(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]作者: shiyiming 时间: 2009-9-15 11:04 标题: Re: 求救! 哪位高人能写出这个题的SAS code!!!!!!! 算出来的结果还是不对的 9号船的最高分可以使24 这里只有3分作者: shiyiming 时间: 2009-9-15 12:06 标题: Re: 求救! 哪位高人能写出这个题的SAS code!!!!!!! 其实任何一条船在两回合16场比赛的最高得分都可能是8×1+2×8=24,只不过几率不同而已。我们来看一条观测值