楼主: shenroong
4446 7

macro bootstrap confidence interval [推广有奖]

  • 1关注
  • 0粉丝

高中生

22%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
150 点
帖子
17
精华
0
在线时间
16 小时
注册时间
2010-12-21
最后登录
2013-2-23

楼主
shenroong 发表于 2012-10-19 04:45:56 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
求教各位高手,我现在用bootstrap找confidence interval,
我的code如下
data spatial;
      input a b @@;
   cards;
   48 42 36 33 20 16 29 39 42 38 42 36 20 15 42 33 22 20 41 43 45 34
   14 22  6  7  0 15 33 34 28 29 34 41  4 13 32 38 24 25 47 27 41 41
   24 28 26 14 30 28 41 40
   ;
  
/*To use the %JACK or %BOOT macros, you must write a macro called %ANALYZE to do the data analysis
   that you want to bootstrap. The %ANALYZE macro must have two arguments:

   DATA=   the name of the input data set to analyze
   OUT=    the name of the output data set containing the statistics
           for which you want to compute bootstrap distributions.
*/
   %macro analyze(data=,out=);
      proc means noprint data=&data vardef=n;
         output out=&out(drop=_freq_ _type_) var=var_a var_b;
         var a b;
         *%bystmt;
      run;
   %mend;

/* %analyze(data=spatial,out=temp); proc print data=temp;run;*/

   title2 'Normal ("Standard") Confidence Interval with Bias Correction';
   %boot(data=spatial,alpha=.10,samples=100,random=123);

   title2 'Normal ("Standard") Confidence Interval without Bias Correction';
   %bootse(alpha=.10,biascorr=0);

   title2 'Efron''s Percentile Confidence Interval';
   %bootci(percentile,alpha=.10);

   title2 'BC Confidence Interval';
   %bootci(bc,alpha=.10);

   title2 'BCa Confidence Interval';
   %bootci(bca,alpha=.10);


   title2 'Resampling with Computation of Studentizing Statistics';
   %macro analyze(data=,out=);
      proc means noprint data=&data vardef=n;
         output out=&out(drop=_freq_ _type_)
            var=var_a var_b kurtosis=kurt_a kurt_b;
         var a b;
         %bystmt;
      run;
      data &out;
         set &out;
         stud_a=var_a*sqrt(kurt_a+2);
         stud_b=var_b*sqrt(kurt_b+2);
         drop kurt_a kurt_b;
      run;
   %mend;

   %boot(data=spatial,stat=var_a var_b,samples=100,random=123);

   title2 'T Confidence Interval';
   %bootci(t,stat=var_a var_b,student=stud_a stud_b,alpha=.10)

我最后得到的var b 90%的 bootstrap confidence interval是70到150,我dataset里面的var b竟然全不在90% confidence interval,所以求问是什么情况。我即使用t-distribution算90%  confidence interval  117 到228。
所以我不是很明白,为什么我dataset里面的data 全不在我的confidence interval

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:confidence Bootstrap Bootstra Interval Macro called write

沙发
zkymath 在职认证  发表于 2012-10-19 14:41:07
帮顶!还没到这个水平

藤椅
jingju11 发表于 2012-10-20 01:35:24
what you are bootstrapping is about variance, not mean. I don't think you can easily see variance from data value itself. Jingju

板凳
shenroong 发表于 2012-10-21 05:41:10
jingju11 发表于 2012-10-20 01:35
what you are bootstrapping is about variance, not mean. I don't think you can easily see variance fr ...
谢谢你,
我后来也发现这个问题,后来我自己把code 改成mean_a 和mean_b了,算出来的就是mean的confidence interval。但是后来又有了个新问题,就是我想算exponential的lambda的confidence interval,lambda是个常数,这个时候code应该怎么写。我原来算的confidence interval都是变量。这个是我的算confidence interval的code,怎么进行变化可以让他算lambda的confidence interval。
谢谢。
%let lambda = 2;
data exp;
do i=1 to 20;
E=ranexp(2345)/λ
output;
end;
run;
Proc print; run;
%include 'C:\Users\shengrong\Documents\Wash U\2012 Fall\math 475\Note and Sample\jackboot.sas';
  %macro analyze(data=,out=);
      proc means noprint data=&data vardef=n;
         output out=&out(drop=_freq_ _type_) var=mean_i mean_E;
         var i E;
      
      run;
   %mend;

%analyze(data=exp,out=temp); proc print data=temp;run;
title "Bootstrap Confidence Interval";
   %boot(data=exp,stat=mean_i mean_E,samples=200,random=123,alpha=0.10);

报纸
jingju11 发表于 2012-10-21 06:04:55
first of all, I suggest you read sas doc about proc means.
to estimate mean, you should write mean =mean_i mean_e, or so. because mean= option tells sas to compute the mean.

you are generating a distribution of exponential with mean of 1/lambda, right?
now you are going to estimate lambda, that is 1/mean. as my understanding, in %analyze adding a code like:
data &out; set &out; lambda =1/mean_e; keep mean_i lambda;
run;
really, you are bootstrapping a function of statistics and keep in mind the property of that function.
jingju

地板
shenroong 发表于 2012-10-21 06:28:29
jingju11 发表于 2012-10-21 06:04
first of all, I suggest you read sas doc about proc means.
to estimate mean, you should write mean ...
十分感谢,我刚才还在您的博客上给你发纸条也问同样的问题了,真是很抱歉打扰您了,这个问题困扰了我好几天,网上查了各种方法,也挺着急的。
谢谢您。  我再去自己琢磨琢磨去。

7
shenroong 发表于 2012-10-21 12:10:36
jingju11 发表于 2012-10-21 06:04
first of all, I suggest you read sas doc about proc means.
to estimate mean, you should write mean ...
按照您教的方法,把bootstrap confidence interval给解决了,我又花了一晚上想t confidence interval的code,我也看了各种jackboot.sas对于bootci这个macro的解释和各种的sample。我对其中一个sample一个code不是很理解,所以我在仿照这个code写的时候 总是出不来结果。
sample code是
   title2 'Resampling with Computation of Studentizing Statistics';
   %macro analyze(data=,out=);
      proc means noprint data=&data vardef=n;
         output out=&out(drop=_freq_ _type_)
            var=var_a var_b kurtosis=kurt_a kurt_b;
         var a b;
         %bystmt;
      run;
      data &out;
         set &out;
         stud_a=var_a*sqrt(kurt_a+2);
         stud_b=var_b*sqrt(kurt_b+2);
         drop kurt_a kurt_b;
      run;
   %mend;

   %boot(data=spatial,stat=var_a var_b,samples=2000,random=123);

   title2 'T Confidence Interval';
   %bootci(t,stat=var_a var_b,student=stud_a stud_b,alpha=.10)
我在尝试写kurtosis的总是想不出来解决办法,
我现在的code是
%macro analyze(data=,out=);
      proc means noprint data=&data vardef=n;
         output out=&out(drop=_freq_ _type_)
            mean= mean_E kurtosis=kurt_E;
         var E;
         %bystmt;
      run;
          data &out;
set &out;lambda1=1/mean_E
studl= lambda1*(kurt_E+2)
run;
%mend
title2 'T Confidence Interval';
   %bootci(t,stat=lambda1,student=studl,alpha=.10)
我自己写的这个是我知道是不对的,但是我自己也不知道应该哪里改。我总感觉kurtosis=kurt_E这个应该是kurtosis=kurt_lambda1,但是在analyze这步的时候 lambda1还不存在,所以我试过kurtosis=kurt_1/
mean_E,但是还不对,不管我怎么修改log都是出现ERROR: Variable STUDL not found.
希望您能指导一下我这个新手,刚接触macro不到一个星期,一到自己写个code的时候就乱了。
谢谢

8
jingju11 发表于 2012-10-21 23:50:13
you want to get student-t confidence interval for lambda. i am not sure if you have the formula for that. if you have, i may have a look. the kurtosis is 4th moment of mean, i dont think it is relevant to what you are estimating.
according to your question, you may need to read about bootstrapping in t CI.
jingju

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 01:51