在知乎上看到这个问题,觉得挺有意思~用SAS玩了一下。
1 options symbolgen mprint mlogic; 2 %let a=1; 3 %let b=12; 4 %GLOBAL flag; 5 %macro girl(n,m); 6 %if ^%symexist(flag) %then %let flag=0; 7 %do yt= 1 %to &m; 8 data girl&yt.; 9 /* call streaminit(0+&yt);*/10 do i = 1 to &n;11 x=rand("Uniform");12 y=round(&a*(1-x)+&b*x);13 output;14 end;15 run;16 proc sql noprint;17 select count(distinct y) into: boyfriend&yt18 from girl&yt19 ;20 quit;21 %if &&boyfriend&yt =&b. %then %do;22 %let flag=%eval(&flag+1);23 %end;24 %end;25 %mend;26 27 %macro test(g,h,w);28 %do o=12 %to &g;29 dm log "clear";30 %do t= 1 %to &w;31 %girl(&o,&h);32 %let flag&t= &flag;33 data test&o;34 %if %eval(&t)>1 %then %do;35 set test&o;36 %end;37 sum_flag++&&flag&t.;38 %if &t=&w %then %do ;39 average_flag=sum_flag/&t.;40 percent_flag=average_flag/&h.;41 boyfriend_n=&o.;42 %end;43 run;44 %let flag=0;45 %end;46 %end;47 48 data want; set test:; run;49 50 proc options option=RLANG;run;51 proc iml;52 run ExportDatasetToR("want","want");53 submit/R;54 library(ggplot2)55 plot=ggplot(data=want,aes(x=boyfriend_n,56 y=percent_flag,color=percent_flag))+57 geom_point(alpha=0.8)+58 geom_smooth(method=lm,formula=y~I(poly(x,2)),59 se=FALSE,fullrange=TRUE)+60 annotate("text",y=0.5,x=38,label="average")+61 labs(title="Percent per Number of BoyFriend",62 x="BoyFriend N",y="Percent")+63 scale_x_continuous(limits=c(12,100),64 breaks=seq(10,100,5))65 plot66 endsubmit;67 *quit;68 %mend;69 70 %test(100,10,20);
得出结论~平均交往38个男朋友,可以收集满12星座~如果男朋友的数量超过85个...
但是,其实每个星座的分布并不是均匀的,而且女生对男生的星座也是有偏好的~所以有bias~
by yant07