%let libpath=Q:\vyuka\DM1\2012\cviceni;
libname st192 "&libpath";


/*ukol 1 */

ods graphics on;
ods listing close;
ods pdf file='D:\dukumenty\prace\MU\vyuka\SAS\ST192_ATK\data.pdf'
         style=journal;

proc corr data=st192.fitness rank
          plots(only)=scatter(nvar=all ellipse=none);
    var RunTime Age Weight Run_Pulse
        Rest_Pulse Maximum_Pulse Performance;
    with Oxygen_Consumption;
    title "Correlations and Scatter Plots with Oxygen_Consumption";
run;
ods pdf close;
ods listing;

/*ukol 2 */
ods graphics / imagemap=on;
ods listing close;
ods html gpath="D:\dukumenty\prace\MU\vyuka\SAS\ST192_ATK\data"
          path="D:\dukumenty\prace\MU\vyuka\SAS\ST192_ATK\data"
          file='corr.html'
         style=statistical;

proc corr data=st192.fitness nosimple 
          plots=matrix(nvar=all histogram);
    var RunTime Age Weight Run_Pulse
         Rest_Pulse Maximum_Pulse Performance;
    title "Correlations and Scatter Plot Matrix of Fitness Predictors";
run;

ods html close;
ods listing;


/*ukol 3a */
ods graphics on;
proc reg data=st192.fitness;
    model Oxygen_Consumption = RunTime;
        title 'Predicting Oxygen_Consumption from RunTime';
run;
quit;

/*ukol 3b 

CLI 
 computes 100(1-alfa)% confidence limits for an individual predicted value 
 
CLM 
 computes 100(1-alfa)% confidence limits for the expected value of the dependent variable 
 
*/
ods graphics on;
proc reg data=st192.fitness;
    model Oxygen_Consumption = RunTime / clm cli;
    title 'Predicting Oxygen_Consumption from RunTime';
run;
quit;


/*ukol 4a*/ 

data Need_Predictions;
    input RunTime @@;
    datalines;
9 10 11 12 13
;
run;

data PredOxy;
    set Need_Predictions 
        st192.fitness;
run;

ods graphics off;

proc reg data=PredOxy;
    model Oxygen_Consumption=RunTime / p;
    id RunTime;
    title 'Oxygen_Consumption=RunTime with Predicted Values';   
run;
quit;

/*ukol 4b*/
proc reg data=st192.fitness noprint outest=Betas;
    model Oxygen_Consumption=RunTime;
run;
quit;

proc print data=Betas;
    title "OUTEST= Data Set from PROC REG";
run;

proc score data=Need_Predictions score=Betas
           out=Scored type=parms;
    var RunTime;
run;

proc print data=Scored;
    title "Scored New Observations";
run;


/*ukol 5*/
ods graphics / imagemap=on;
ods listing close;
ods pdf file='D:\dukumenty\prace\MU\vyuka\SAS\ST192_ATK\data\reg_cp.pdf'
         style=statistical;

proc reg data=st192.fitness plots(only)=(rsquare adjrsq cp);
    ALL_REG: model oxygen_consumption 
                    = Performance RunTime Age Weight
                      Run_Pulse Rest_Pulse Maximum_Pulse
            / selection=rsquare adjrsq cp;
    title 'Best Models Using All-Regression Option';
run;
quit;

ods pdf close;
ods listing;


/*ukol 6*/
ods graphics;
ods listing gpath="D:\dukumenty\prace\MU\vyuka\SAS\ST192_ATK\data";
ods select selectionsummary adjrsqplot;

proc reg data=st192.fitness plots(only)=adjrsq;
   FORWARD:  model oxygen_consumption 
                    = Performance RunTime Age Weight
                      Run_Pulse Rest_Pulse Maximum_Pulse
            / selection=forward;
   BACKWARD: model oxygen_consumption 
                    = Performance RunTime Age Weight
                      Run_Pulse Rest_Pulse Maximum_Pulse
            / selection=backward;
   STEPWISE: model oxygen_consumption 
                    = Performance RunTime Age Weight
                      Run_Pulse Rest_Pulse Maximum_Pulse
            / selection=stepwise;
   title 'Best Models Using Stepwise Selection';
run;
quit;

/*neco navic*/
/*ukol 7*/
ods graphics off;
ods pdf file='D:\dukumenty\prace\MU\vyuka\SAS\ST192_ATK\data\regrese20.pdf' style=sasweb;
proc reg data=st192.fitness;
model oxygen_consumption=RunTime;
plot predicted.*RunTime;
run;
quit;
ods pdf close;
