楼主: peijiamei
8159 4

[程序分享] 怎样计算变量的期望频率? [推广有奖]

已卖:299份资源

学科带头人

75%

还不是VIP/贵宾

-

威望
3
论坛币
26157 个
通用积分
12.7133
学术水平
217 点
热心指数
343 点
信用等级
210 点
经验
75401 点
帖子
1099
精华
1
在线时间
2016 小时
注册时间
2007-11-15
最后登录
2016-3-21

楼主
peijiamei 发表于 2010-7-8 17:28:35 |AI写论文
100论坛币
已经某个变量服从正太分布,如何计算该变量的每一个值所对应的期望?

最佳答案

BraveMadMan 查看完整内容

如果你的问题跟这个帖子相关的话:http://www.pinggu.org/bbs/thread-852915-1-1.html SAS期望频率的计算过程: 首先根据原始数据估算 mean 和 standard deviation。然后SAS根据估算的mean 和 standard deviation来计算期望频率。 详见以下程序的的第5步。
关键词:变量 期望 频率
我的微博:http://t.sina.com.cn/1087192374
欢迎互相加关注!

沙发
BraveMadMan 发表于 2010-7-8 17:28:36
如果你的问题跟这个帖子相关的话:http://www.pinggu.org/bbs/thread-852915-1-1.html


SAS期望频率的计算过程:

首先根据原始数据估算 mean 和 standard deviation。然后SAS根据估算的mean 和 standard deviation来计算期望频率。

详见以下程序的的第5步。
  1. *---------------------------------------------------------------------------;
  2. * Step 1: Read in data;
  3. *---------------------------------------------------------------------------;
  4. data trans;
  5.   input temp;
  6.   cards;
  7.   543
  8. 543
  9. 543
  10. 548
  11. ......
  12. ;
  13. run;

  14. *---------------------------------------------------------------------------;
  15. * Step 2: generate historgram bins and
  16.   output histogram as well as add a normal curve on the histogram;
  17. *---------------------------------------------------------------------------;

  18. title 'Fit a normal curve on histogram';
  19. ods select ParameterEstimates GoodnessOfFit FitQuantiles Bins MyPlot;
  20. ods output bins=bins ParameterEstimates=est;

  21. proc univariate data=Trans;
  22.    histogram Temp / normal(percents=20 40 60 80 midpercents)
  23.                      name='MyPlot'
  24.                      endpoints = 363 to 619 by 1;
  25.    inset n mean std / pos = ne format = 6.3;
  26. run;

  27. *---------------------------------------------------------------------------;
  28. * Step 3: Output estimated parameters into macro variables;
  29. *---------------------------------------------------------------------------;

  30. proc sql;
  31.   select estimate into :mu
  32.   from est
  33.   where Symbol="Mu";
  34.   select estimate into :sigma
  35.   from est
  36.   where Symbol="Sigma";
  37. quit;
  38. %put μ σ

  39. *---------------------------------------------------------------------------;
  40. * Step 4: Scattered plots of observed and fitted percentages;
  41. *---------------------------------------------------------------------------;

  42. SYMBOL1 V=STAR C=RED;      
  43. symbol2 color=blue interpol=spline value=dot height = .1;

  44. proc gplot data=bins;
  45.   plot obsPercent*MinPoint estPercent*MinPoint /overlay haxis=350 to 650 by 50;
  46.   run;
  47. quit;

  48. *---------------------------------------------------------------------------;
  49. * Step 5: How the fitted percentages are calculated? ;
  50. *---------------------------------------------------------------------------;

  51. data bin1;
  52.   set bins;
  53.   pdf=100*pdf('normal', MinPoint+.5, &mu, &sigma);
  54.   /* &mu is the estimated mean, and &sigma is the estimated standard deviation*/
  55.   format pdf 6.3;
  56. run;

  57. *---------------------------------------------------------------------------;
  58. * Step 6: Compare machine-reported and manual-calculated PDFs;
  59. *---------------------------------------------------------------------------;

  60. proc print data=bin1(obs = 100);
  61.   var estPercent pdf;
  62.   format estPercent 6.4 pdf    6.4;
  63. run;

  64. * Graph comparison;

  65. SYMBOL1 V=dot C=RED;      
  66. symbol2 color=blue interpol=spline value=dot height = .1;
  67. title 'Compare machine-reported and manual-calculated PDFs';
  68. proc gplot data=bin1;
  69.   plot pdf*MinPoint estPercent*MinPoint /overlay haxis=350 to 650 by 50;
  70.   run;
  71. quit;
复制代码
Don't get lost in technical details. What is the big picture?

藤椅
viterbi 发表于 2010-7-8 18:21:19
用pdf函数可以吧如均均值为0,方差为10的正态分布,以下是计算变量i的期望频率,结果是x的值。不知道我理解题意否,哈。


data cc;
do i=-50 to 50 ;

x=pdf('normal',i,0,10);output;
end;
format x percent8.2;
run;

proc gplot data=cc;
plot x*i;
run;quit;
gplot10.png

已有 1 人评分论坛币 热心指数 收起 理由
peijiamei + 60 + 2 好的意见建议

总评分: 论坛币 + 60  热心指数 + 2   查看全部评分

板凳
BraveMadMan 发表于 2010-7-9 01:53:54
对前100个Obs的比较 表明以上表述是正确的:

                                 Fit a normal curve on histogram                                63
                                                                     23:14 Wednesday, July 7, 2010

                                              Est
                                     Obs    Percent       pdf

                                       1    0.1405     0.1405
                                       2    0.1465     0.1465
                                       3    0.1526     0.1526
                                       4    0.1589     0.1589
                                       5    0.1654     0.1654
                                       6    0.1721     0.1721
                                       7    0.1790     0.1790
                                       8    0.1861     0.1860
                                       9    0.1933     0.1933
                                      10    0.2007     0.2007
                                      11    0.2083     0.2083
                                      12    0.2161     0.2161
                                      13    0.2241     0.2241
                                      14    0.2323     0.2323
                                      15    0.2407     0.2407
                                      16    0.2492     0.2492
                                      17    0.2579     0.2579
                                      18    0.2668     0.2668
                                      19    0.2759     0.2759
                                      20    0.2851     0.2851
                                      21    0.2945     0.2945
                                      22    0.3041     0.3041
                                      23    0.3138     0.3138
                                      24    0.3237     0.3237
                                      25    0.3338     0.3338
                                      26    0.3440     0.3439
                                      27    0.3543     0.3543
                                      28    0.3648     0.3647
                                      29    0.3754     0.3753
                                      30    0.3861     0.3861
                                      31    0.3969     0.3969
                                      32    0.4079     0.4078
                                      33    0.4189     0.4189
                                      34    0.4300     0.4300
                                      35    0.4413     0.4413
                                      36    0.4526     0.4526
                                      37    0.4639     0.4639
                                      38    0.4754     0.4754
                                      39    0.4868     0.4868
                                      40    0.4984     0.4984
                                      41    0.5099     0.5099
                                      42    0.5215     0.5215
                                      43    0.5330     0.5330
                                      44    0.5446     0.5446
                                      45    0.5562     0.5562
                                      46    0.5677     0.5677
                                      47    0.5792     0.5792
                                      48    0.5906     0.5906
                                      49    0.6020     0.6020

                                 Fit a normal curve on histogram                                64
                                                                     23:14 Wednesday, July 7, 2010

                                              Est
                                     Obs    Percent       pdf

                                      50    0.6133     0.6133
                                      51    0.6245     0.6245
                                      52    0.6356     0.6356
                                      53    0.6466     0.6466
                                      54    0.6575     0.6575
                                      55    0.6682     0.6682
                                      56    0.6788     0.6788
                                      57    0.6893     0.6893
                                      58    0.6995     0.6995
                                      59    0.7096     0.7096
                                      60    0.7195     0.7195
                                      61    0.7291     0.7291
                                      62    0.7385     0.7386
                                      63    0.7477     0.7478
                                      64    0.7567     0.7567
                                      65    0.7654     0.7654
                                      66    0.7738     0.7738
                                      67    0.7820     0.7820
                                      68    0.7898     0.7898
                                      69    0.7974     0.7974
                                      70    0.8046     0.8046
                                      71    0.8115     0.8115
                                      72    0.8181     0.8181
                                      73    0.8243     0.8243
                                      74    0.8302     0.8302
                                      75    0.8358     0.8358
                                      76    0.8409     0.8409
                                      77    0.8457     0.8457
                                      78    0.8501     0.8502
                                      79    0.8542     0.8542
                                      80    0.8578     0.8578
                                      81    0.8611     0.8611
                                      82    0.8639     0.8639
                                      83    0.8663     0.8663
                                      84    0.8684     0.8684
                                      85    0.8700     0.8700
                                      86    0.8712     0.8712
                                      87    0.8720     0.8720
                                      88    0.8723     0.8724
                                      89    0.8723     0.8723
                                      90    0.8718     0.8719
                                      91    0.8710     0.8710
                                      92    0.8697     0.8697
                                      93    0.8680     0.8680
                                      94    0.8658     0.8659
                                      95    0.8633     0.8633
                                      96    0.8604     0.8604
                                      97    0.8571     0.8571
                                      98    0.8533     0.8533

                                 Fit a normal curve on histogram                                65
                                                                     23:14 Wednesday, July 7, 2010

                                              Est
                                     Obs    Percent       pdf

                                      99    0.8492     0.8492
                                     100    0.8447     0.8447
Don't get lost in technical details. What is the big picture?

报纸
BraveMadMan 发表于 2010-7-9 02:06:35
画图皮较:

fig.png (14.71 KB)

fig.png

Don't get lost in technical details. What is the big picture?

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-3 03:18