Logistic Regression in SAS

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

Logistic Regression in SAS

I have the data below

Untitled.png

and here is my code to conduct logisic regression analysis. For some reason my code doesnt work. Any idea why?

data beetle_data;

   input dose total dead;

   y = dead/total;

   datalines;

1.6907  59 6

1.7242  60 13

1.7552  62 18

1.7842  56 28

1.8113  63 52

1.8369  59 53

1.8610  62 61

1.8839  60 60

;

proc logistic data=beetle_data;

model

y =dose/link=logit dist=binomial;

run;


Accepted Solutions
Solution
‎11-20-2014 02:21 PM
Respected Advisor
Posts: 4,930

Re: Logistic Regression in SAS

In my view, variable Y is not needed. I would start with:

data beetle_data;

   input dose total dead;

   label dose="Log(dose)";

   datalines;

1.6907  59 6

1.7242  60 13

1.7552  62 18

1.7842  56 28

1.8113  63 52

1.8369  59 53

1.8610  62 61

1.8839  60 60

;

proc logistic data=beetle_data  plots(only)=effect;

model dead/total = dose;

run;

EffectPlot2.png

PG

View solution in original post


All Replies
N/A
Posts: 1

Re: Logistic Regression in SAS

In proc logistic the default link is logit and dist is not in the option list.  Try removing "/link=logit dist=binomial". Reference link: SAS/STAT(R) 9.2 User's Guide, Second Edition.

Trusted Advisor
Posts: 1,228

Re: Logistic Regression in SAS

Dependent variable Y is not a dichotomous dependent variable.

Super User
Posts: 11,343

Re: Logistic Regression in SAS

Looks more like a PROC REG or similar procedure problem.

Super User
Posts: 19,855

Re: Logistic Regression in SAS

I'd change the data structure to match what SAS was expecting, unless you're looking for an infection rate model, if so see here:

SAS/STAT(R) 9.22 User's Guide

Otherwise something like the following might work:

data beetle_data;

   input dose total dead;

   y = dead/total;

   datalines;

1.6907  59 6

1.7242  60 13

1.7552  62 18

1.7842  56 28

1.8113  63 52

1.8369  59 53

1.8610  62 61

1.8839  60 60

;

data have;

set beetle_data;

do record=1 to total;

if record <= dead then y_new=1;

else y_new=0;

output;

end;

run;

proc logistic data=have;

model y_new = dose / expb;

run;

Occasional Contributor
Posts: 6

Re: Logistic Regression in SAS

Reeza, thanks for your work. Much appreciated. I am asking this because I am very new to SAS - is there no way to conduct the analysis in my way in SAS? Considering the fact that this could be done in R as shown below, I thought SAS too is able to do that.

dose <- c(1.6907, 1.7242, 1.7552, 1.7842,
  
1.8113, 1.8369, 1.8610,1.8839)
total
<- c(59,60,62,56,63,59,62,60)
dead
<- c(6,13,18,28,52,53,61,60)
y
<- dead/total

lineer.model
<- glm(y ~ dose,family=binomial(link=logit), weights=total)


which gives exactly the same coefficients as yours.

Solution
‎11-20-2014 02:21 PM
Respected Advisor
Posts: 4,930

Re: Logistic Regression in SAS

In my view, variable Y is not needed. I would start with:

data beetle_data;

   input dose total dead;

   label dose="Log(dose)";

   datalines;

1.6907  59 6

1.7242  60 13

1.7552  62 18

1.7842  56 28

1.8113  63 52

1.8369  59 53

1.8610  62 61

1.8839  60 60

;

proc logistic data=beetle_data  plots(only)=effect;

model dead/total = dose;

run;

EffectPlot2.png

PG
Occasional Contributor
Posts: 6

Re: Logistic Regression in SAS

PGStats thanks a million. That is exactly what I was after. I need one last favour. Do you mind sharing the code required for the lovely plot?

Respected Advisor
Posts: 2,655

Re: Logistic Regression in SAS

It comes as part of the deal--the plots(only)=effect option to the PROC LOGISTIC statement.

Steve Denham

Occasional Contributor
Posts: 6

Re: Logistic Regression in SAS

Posted in reply to SteveDenham

Steve, that is what I thought, but the plot does not appear in my output page. Could that have something to do with the version of SAS I am using (btw mine is Enterprise Guide 4.3)? Or does it appear somewhere else?

Respected Advisor
Posts: 2,655

Re: Logistic Regression in SAS

Yeah, it is version dependent.  Certainly available in 9.3 (SAS/STAT12.1) or later.  Earlier versions require an ODS GRAPHICS ON; statement, but for SAS/STAT13.1 on, it is a default.  And since my EG version is 6.1, I'm not sure how far back it goes.

Steve Denham

SAS Super FREQ
Posts: 3,755

Re: Logistic Regression in SAS

EG 4.3 shipped with SAS 9.9m2, so make sure you have an explicity

ODS GRAPHICS ON;

statement before you call PROC LOGISITC.

Respected Advisor
Posts: 4,930

Re: Logistic Regression in SAS

If it makes any sense in your context, you might also want to fit a natural mortality rate as part of your model. Proc Probit offers that feature:

data beetle_data;

input logDose total dead;

dose = 10 ** logDose;

label logDose="Log(dose)";

datalines;

1.6907  59 6

1.7242  60 13

1.7552  62 18

1.7842  56 28

1.8113  63 52

1.8369  59 53

1.8610  62 61

1.8839  60 60

;

ods graphics on;

proc probit data=beetle_data log10 optc plots=predpplot;

model dead/total = dose / dist=logistic lackfit;

run;

PredPPlot8.png

I find the fit slightly better this way.

PG

PG
Occasional Contributor
Posts: 6

Re: Logistic Regression in SAS

PGStats, since I am using Enterprise Guide 4.3, plots=predpplot does not produce the plot above. Is there some other way to do so?

Respected Advisor
Posts: 4,930

Re: Logistic Regression in SAS

I'm sorry, I don't use EG. If the plots= option doesn't log an error it could be that the plot is generated somewhere but not shown to you... Just a guess.

PG
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 16 replies
  • 549 views
  • 6 likes
  • 9 in conversation