SAS期望频率的计算过程:
首先根据原始数据估算 mean 和 standard deviation。然后SAS根据估算的mean 和 standard deviation来计算期望频率。
详见以下程序的的第5步。
- *---------------------------------------------------------------------------;
- * Step 1: Read in data;
- *---------------------------------------------------------------------------;
- data trans;
- input temp;
- cards;
- 543
- 543
- 543
- 548
- ......
- ;
- run;
- *---------------------------------------------------------------------------;
- * Step 2: generate historgram bins and
- output histogram as well as add a normal curve on the histogram;
- *---------------------------------------------------------------------------;
- title 'Fit a normal curve on histogram';
- ods select ParameterEstimates GoodnessOfFit FitQuantiles Bins MyPlot;
- ods output bins=bins ParameterEstimates=est;
- proc univariate data=Trans;
- histogram Temp / normal(percents=20 40 60 80 midpercents)
- name='MyPlot'
- endpoints = 363 to 619 by 1;
- inset n mean std / pos = ne format = 6.3;
- run;
- *---------------------------------------------------------------------------;
- * Step 3: Output estimated parameters into macro variables;
- *---------------------------------------------------------------------------;
- proc sql;
- select estimate into :mu
- from est
- where Symbol="Mu";
- select estimate into :sigma
- from est
- where Symbol="Sigma";
- quit;
- %put μ σ
- *---------------------------------------------------------------------------;
- * Step 4: Scattered plots of observed and fitted percentages;
- *---------------------------------------------------------------------------;
- SYMBOL1 V=STAR C=RED;
- symbol2 color=blue interpol=spline value=dot height = .1;
- proc gplot data=bins;
- plot obsPercent*MinPoint estPercent*MinPoint /overlay haxis=350 to 650 by 50;
- run;
- quit;
- *---------------------------------------------------------------------------;
- * Step 5: How the fitted percentages are calculated? ;
- *---------------------------------------------------------------------------;
- data bin1;
- set bins;
- pdf=100*pdf('normal', MinPoint+.5, &mu, &sigma);
- /* &mu is the estimated mean, and &sigma is the estimated standard deviation*/
- format pdf 6.3;
- run;
- *---------------------------------------------------------------------------;
- * Step 6: Compare machine-reported and manual-calculated PDFs;
- *---------------------------------------------------------------------------;
- proc print data=bin1(obs = 100);
- var estPercent pdf;
- format estPercent 6.4 pdf 6.4;
- run;
- * Graph comparison;
- SYMBOL1 V=dot C=RED;
- symbol2 color=blue interpol=spline value=dot height = .1;
- title 'Compare machine-reported and manual-calculated PDFs';
- proc gplot data=bin1;
- plot pdf*MinPoint estPercent*MinPoint /overlay haxis=350 to 650 by 50;
- run;
- quit;



雷达卡






京公网安备 11010802022788号







