BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
star68
Calcite | Level 5

Could anyone tell me how to specific an option in the proc fmm procedure to output the pdf and cdf percentages?  I was able to run the proc fmm procedure to generate pdf fit statistics and pdf and cdf graphs, but I could not find an option to output the fitted pdf and cdf percentages.  Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
acordes
Rhodochrosite | Level 12

the example is from rick wicklin's do loop blog.

https://blogs.sas.com/content/iml/2011/09/23/modeling-finite-mixtures-with-the-fmm-procedure.html 

 

proc format;
   value PlayerName 1 = "Mom" 2 = "Rick";
run;
data scrabble;
input Game Player @@;
label Cumul = "Cumulative Score"
      Score = "Score for Turn";
Cumul = 0;
do Turn = 1 to 20;
   input Score @@;
   Cumul + Score;
   if Score^=. then output;
end;
format Player PlayerName.;
datalines;
1 1 20 15 12 24 11  9  9 18 14 16 14 20 23 14 11 10  8 10  8 -10
1 2 12 11  9  5  7 27 12  5 14 26 18 12 17  8 11 13 36  4  3 -1
2 1 14 30  8 13 16 11 12  8 26 12  8 27 27 12  5 15  9  7  2 -5
2 2 22 18  3 11 34 21  5  3 11 18 13 12 25 18 14 15 22 12  5 -2
3 1 18 16 20 26 17 16 20 12 15 12 33 17 26  6  5 -4  .  .  .  .
3 2 20 12 20 15 42 10  6 18 14 15  6 15 10  8 19  6  .  .  .  .
4 1 18  6 14 14 10  7 30 27 14 18 18 12 12  8 18  8  .  .  .  .
4 2 18 10 15 24 37 12  8 16 24 14 14 17 17 10 13 -3  .  .  .  . 
;
run;

proc means data=Scrabble;
class Player;
var Score;
run;

proc sgpanel data=Scrabble noautolegend;
panelby Game;
scatter x=Turn y=Cumul / group=Player transparency=0.75;
series x=Turn y=Cumul / group=Player curvelabel;
rowaxis integer grid;
colaxis grid;
run;

proc sgpanel data=Scrabble noautolegend;
panelby Player;
histogram Score;
density Score /type=kernel;
run;

From here ongoing I adapt Rick's code to your context by adding the ods output tables statement prior to the proc fmm. 

Then I create a data set that gets "scored" by the mixture of the distributions that proc fmm solved for. 

 

ods output ParameterEstimates=parms MixingProbs=mixi;
proc fmm data=scrabble(where=(Player=2)); /* Rick's scores */
model Score = / k=2;
output out=oks / allstats;
run;

proc sql;
select min(score), max(score) into :miny, :maxy from
scrabble where player=2;
quit;


/* go to output data sets and copy estimates and mixture probabilities, here normal distribution  */
data to_score;
format cdf_mixture percent9.2;
do score=%eval(&miny-3) to %eval(&maxy+3) by 1;
cdf_mixture=0.9460*cdf('normal', Score,  12.7127, sqrt(44.6022)) + (1-0.9460)* cdf('normal', Score,  37.3136, sqrt(8.7956)) ;
output;
end;
run;

 

View solution in original post

2 REPLIES 2
acordes
Rhodochrosite | Level 12

the example is from rick wicklin's do loop blog.

https://blogs.sas.com/content/iml/2011/09/23/modeling-finite-mixtures-with-the-fmm-procedure.html 

 

proc format;
   value PlayerName 1 = "Mom" 2 = "Rick";
run;
data scrabble;
input Game Player @@;
label Cumul = "Cumulative Score"
      Score = "Score for Turn";
Cumul = 0;
do Turn = 1 to 20;
   input Score @@;
   Cumul + Score;
   if Score^=. then output;
end;
format Player PlayerName.;
datalines;
1 1 20 15 12 24 11  9  9 18 14 16 14 20 23 14 11 10  8 10  8 -10
1 2 12 11  9  5  7 27 12  5 14 26 18 12 17  8 11 13 36  4  3 -1
2 1 14 30  8 13 16 11 12  8 26 12  8 27 27 12  5 15  9  7  2 -5
2 2 22 18  3 11 34 21  5  3 11 18 13 12 25 18 14 15 22 12  5 -2
3 1 18 16 20 26 17 16 20 12 15 12 33 17 26  6  5 -4  .  .  .  .
3 2 20 12 20 15 42 10  6 18 14 15  6 15 10  8 19  6  .  .  .  .
4 1 18  6 14 14 10  7 30 27 14 18 18 12 12  8 18  8  .  .  .  .
4 2 18 10 15 24 37 12  8 16 24 14 14 17 17 10 13 -3  .  .  .  . 
;
run;

proc means data=Scrabble;
class Player;
var Score;
run;

proc sgpanel data=Scrabble noautolegend;
panelby Game;
scatter x=Turn y=Cumul / group=Player transparency=0.75;
series x=Turn y=Cumul / group=Player curvelabel;
rowaxis integer grid;
colaxis grid;
run;

proc sgpanel data=Scrabble noautolegend;
panelby Player;
histogram Score;
density Score /type=kernel;
run;

From here ongoing I adapt Rick's code to your context by adding the ods output tables statement prior to the proc fmm. 

Then I create a data set that gets "scored" by the mixture of the distributions that proc fmm solved for. 

 

ods output ParameterEstimates=parms MixingProbs=mixi;
proc fmm data=scrabble(where=(Player=2)); /* Rick's scores */
model Score = / k=2;
output out=oks / allstats;
run;

proc sql;
select min(score), max(score) into :miny, :maxy from
scrabble where player=2;
quit;


/* go to output data sets and copy estimates and mixture probabilities, here normal distribution  */
data to_score;
format cdf_mixture percent9.2;
do score=%eval(&miny-3) to %eval(&maxy+3) by 1;
cdf_mixture=0.9460*cdf('normal', Score,  12.7127, sqrt(44.6022)) + (1-0.9460)* cdf('normal', Score,  37.3136, sqrt(8.7956)) ;
output;
end;
run;

 

star68
Calcite | Level 5
Thank you very much. I read your codes and understand how to get the cdf percentages.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 921 views
  • 0 likes
  • 2 in conversation