I am looking to create a pdf with 4 nice graphs for different analysis. My question is, how do I output only the ROC curve for my logistic regression?
I use the following code
TITLE2 JUSTIFY=CENTER "Rank ordering characteristic curve (ROC)";
ODS GRAPHICS ON;
PROC LOGISTIC
DATA = input
plots(only)=(roc(id=obs))
;
MODEL y
(Event = '1')= x
/
SELECTION=NONE
LINK=LOGIT;
RUN;
QUIT;
ODS GRAPHICS OFF;
and a dummy dataset can be imagined using this
DATA HAVE;
DO I = 1 TO 100;
Y = RAND('integer',0,1);
x = ranuni(i);
output;
end;
run;
Thanks
EDIT: just to be explicit, I'm looking to output just a plot of the ROC curve and nothing else, i.e. the tables containing the somers' D etc.
ODS SELECT ROCCURVE;
ODS SELECT allows you to control the output and include only the tables/output you want.
You can wrap your code in ODS TRACE ON, ODS TRACE OFF to find out what the table name, or check the documentation.
Related
i am able to output all sorts of statistics and values, however, am missing the ability to output p-values of parameter estimator significance.
I do get them in the Output window but not in my outputted tables. Here is my code
ods output PhilOul = philipps FitSummary = Stats;
proc autoreg data=ppnr_1.train outest=regression_13;
model mnos = ir_irs10y_yoyd ur_ap_yoy sav_yoyd_l1
/ stationarity=(PHILLIPS)
;
where date ge "&dev_start." and date le "&dev_end." ;
proc print data = regression_13;
run;
quit;
As you can see, I get DW-statistics (in "Stats" table), PhilipsOulier ("Philipps" table) and parameter estimates ("Regression_13") but not the significance of these parameters...
Best regards, Niels
EDIT: I used to figure out how to output p-values in PROC REG statement. Specify the TABLEOUT option. However, this option is not valid in PROC AUTOREG :-(
The p-values are in ODS output table ParameterEstimates. Change your code to be:
ods output
PhilOul = philipps
FitSummary = Stats
ParameterEstimates = Estimates
;
You can observe the ODS output tables that a procedure creates by using ODS TRACE. You only need to trace once, or if you forget :).
ODS TRACE ON;
PROC ...;
ODS TRACE OFF;
I am using proc transreg to test different transformations in the sashelp.baseball dataset. I request all plots and sometimes I can see a curve fit graph and sometimes I can't. Is there something I am missing if I want to output the regression fit with the code below?
DATA BASEBALL;
SET SASHELP.BASEBALL;
RUN;
ODS GRAPHICS ON;
ODS OUTPUT
NObs = num_obs
FitStatistics = fitstat
Coef = params
;
PROC TRANSREG
DATA=BASEBALL
PLOTS=ALL
SOLVE
SS2
PREDICTED;
;
MODEL_1:
MODEL POWER(logsalary/parameter=1) = log(nruns);
OUTPUT OUT = fitted_model;
RUN;
For clarity, the regression fit plot is a scatter plot with the estimated regression line fitted through
The fit plot is generated when the dependent variable does not have a transformation. You can create the transformation ahead of time to get this graph then.
From documentation:
ODS Graph Name: FitPlot
Plot Description: Simple Regression and Separate Group Regressions
Statement and Option: MODEL, a dependent variable that is not
transformed, one non-CLASS independent variable, and at most one CLASS
variable
This code works for me:
PROC TRANSREG
DATA=sashelp.BASEBALL
PLOTS=ALL
SOLVE
SS2
PREDICTED;
;
MODEL_1:
MODEL identity(logsalary) = log(nruns);
OUTPUT OUT = fitted_model;
RUN;
And generates the desired graph.
I´ve been using the UNIVARIATE proccedure in order to get the p-value from a series of distributions (lognormal, exponential, gamma) and have reached the following problem:
I am using the following code to get the p-values of the goodness of fit tests for each of the distributions:
ods select all/*ParameterEstimates GoodnessOfFit*/;
proc univariate data=results.Parametros_Prueba_1;
var Monto_1.;
histogram /
lognormal (l=1 color=red SHAPE=&ParamLOGN2_1 SCALE=&ParamLOGN1_1)
gamma (l=1 color=red SHAPE=&ParamGAM1_1 SCALE=&ParamGAM2_1)
exponential (l=2 SCALE=&ParamEXP1_1);
ods output GoodnessOfFit=results.Goodness_1;
run;
proc print data=results.Goodness_1;
After running the previous code I get the "Results" which gives me the histogram graphic and other descriptive information about the tests. I am looking for a way to get this "Results" print to show only the last part corresponding to the "proc print" added on the last line.
Thanks in advance!
If you want no output to the screen (results window) from PROC UNIVARIATE, then the simplest answer is:
ods select none;
proc univariate ... ;
run;
ods select all;
proc print ... ;
run;
ods select none; tells ODS to not make any ODS output whatsoever. You'll still get your ODS OUTPUT though as that comes in afterwards.
ods select none;
proc univariate data=sashelp.class;
var height;
histogram name='univhist' /
lognormal (l=1 color=red )
gamma (l=1 color=red )
exponential (l=2 );
ods output GoodnessOfFit=Goodness_1;
run;
ods select all;
proc print data=Goodness_1;
run;
Now, you'll note you don't get your histogram; that one is harder. It unfortunately changes its name every time you run it, and even if you use the NAME= option, that'll only work the first time it's run. You need to use PROC GREPLAY to delete it.
proc greplay nofs igout=work.gseg;
delete 'univhist';
run; quit;
(Assuming UNIVHIST is the name you assign it.)
I wrote the following code in sas, but I did not get result!
The result histogram in grey and the range of data is not as I specified! what is the problem?
I got the following warning too: WARNING: The MIDPOINTS= list was extended to accommodate the data
what about color?
axis1 order=(0 to 100000 by 50000);
axis2 order=(0 to 100 by 5);
run;
proc capability data=HW2 noprint;
histogram Mvisits/midpoints=0 to 98000 by 10000
haxis=axis1
cfill=blue;
run;
.......................................
I have the same problem with boxplot, for example I got the following plot and I want to change the distances, then I could see the plot better, but I could not.
The below is for proc univariate rather than proc capability, I do not have access to SAS/QC to test, but the user guide shows very similar syntax for the histogram statements. Hopefully, you'll be able to translate it back.
It looks like you are having problems with the colour due to your output system. Your graphs are probably delivered via ODS, in which case the cfill option does not apply (see here and not the Traditional Graphics tag).
To change the colour of the histogram bars in ODS output you can use proc template:
proc template;
define style styles.testStyle;
parent = styles.htmlblue;
style GraphDataDefault /
color = green;
end;
run;
ods listing style = styles.testStyle;
proc univariate data = sashelp.cars;
histogram mpg_city;
run;
An example explaining this can be found here.
Alternatively you can use proc sgplot to create a histogram with more control of the colour as follows:
proc sgplot data = sashelp.cars;
histogram mpg_city / fillattrs = (color = red);
run;
As to your question of truncating the histogram. It doesn't really make a great deal of sense to ignore the extreme values as it will give you an erroneous image of the distribution, which somewhat defeats the purpose of the histogram. That said, you can achieve what you are asking for with bit of a hack:
data tempData;
set sashelp.cars;
tempClass = 1;
run;
proc univariate data = tempData noprint;
class tempClass;
histogram mpg_city / maxnbin = 5 endpoints = 0 to 25 by 5;
run;
In the above a dummy class tempClass is created and then comparative histograms are requested using the class statement. maxnbins will limit the number of bins displayed only in a comparative histogram.
Your other option is to exclude (or cap) your extreme points before creating the histogram, but this will lead to slightly erroneous frequency counts/percentages/bar heights.
data tempData;
set sashelp.cars;
mpg_city = min(mpg_city, 20);
run;
proc univariate data = tempData noprint;
histogram mpg_city / endpoints = 0 to 25 by 5;
run;
This is a possible approach to original question (untested as no SAS/QC or data):
proc capability data = HW2 noprint;
histogram Mvisits /
midpoints = 0 to 300000 by 10000
noplot
outhistogram = histData;
run;
proc sgplot data = histData;
vbar _MIDPT_ /
response = _OBSPCT_
fillattrs = (color = blue);
where _MIDPT_ <= 100000;
run;
I am trying to carry out a logistic regression with SAS. I have few settings for the model, and try to compare the difference.
What I want to archieve is to output the estimated coefficients to a file. I think ODS maybe a promising way, but don't know how to use it.
Can anyone write me a simple example?
Thank you very much.
To add a bit of additional color; ODS OUTPUT <NAME>=DATASET ... ; will save the output into the specified dataset.
Use ODS TRACE get the names of output tables. Information on the tables will be written to the log.
ods trace on;
ods output ParameterEstimates=estimates;
proc logistic data=test;
model y = i;
run;
ods trace off;
For Logistic:
proc logistic data = in descending outest = out;
class rank / param=ref ;
model admit = gre gpa rank;
run;
For proc reg:
proc reg data=a;
model y z=x1 x2;
output out=b
run;
for proc glm:
ods output Solution=parameters FitStatistics=fit;
proc glm data=hers;
model glucose = exercise ;
quit;
run;
for proc reg this doesn't work for me
Use proc reg OUTEST=b
proc reg data=a outest=b;
model y=x1;
run;
other reg can get other parameters added to OUTEST.