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

Hello there,

I'm trying to understand how to create a regression analysis code depending on if the intercept and/or slope varies based on some group variables. Below is a hypothetical dataset with 15 students nested in 3 schools. Their passing an exam is correlated with their family income and the school they attend to which is the nesting variable.

 

Student_IDPASSFAMILY_INCOMESCHOOL
11120000sch1
21170000sch1
3090000sch1
4091500sch1
5093000sch1
61180000sch1
71225000sch1
81150000sch1
9190000sch2
10192000sch2
11194000sch2
12078000sch2
131110000sch3
14050000sch3
151140000sch3

 

If I want to write a regression analysis with constant intercept and slope for each school:

 

1.png I would:

PROC LOGISTIC DATA = TEST;

MODEL PASS = FAMILY_INCOME;

RUN;

 

If I want to write a regression analysis with varying intercept but constant slope for each school:

 

2.png

where

 

3.png

I would:

PROC LOGISTIC DATA = TEST;

CLASS SCHOOL (ref="sch1");

MODEL PASS = FAMILY_INCOME SCHOOL;

RUN;

 

If I want to write a regression analysis with varying intercept and slope for each school:

 

4.png

where

5.png

6.png

 

Now, my questions are:

 

1. Did I get the varying intercept constant slope model in PROC LOGISTIC right?

2. How would I write the PROC LOGISTIC to accommodate varying intercept and slope for each hospital?

 

Thanks a lot in advance!

 

Recep


5.png
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
  1. yes
  2. MODEL PASS = FAMILY_INCOME|SCHOOL; (the vertical bar creates main effects and interactions, which can also be written as MODEL PASS=FAMILY SCHOOL FAMILY*INCOME;   )
--
Paige Miller

View solution in original post

10 REPLIES 10
Reeza
Super User

2 - BY statement.

 

proc logistic ...;

by school hospital;

model .....;

run;

PaigeMiller
Diamond | Level 26

@Reeza wrote:

2 - BY statement.

 

proc logistic ...;

by school hospital;

model .....;

run;


No, you wouldn't do this unless you had a very good reason. You want all terms in one model, which gives you better estimate of the overall variability than you get if you do it with a BY statement.

--
Paige Miller
PaigeMiller
Diamond | Level 26
  1. yes
  2. MODEL PASS = FAMILY_INCOME|SCHOOL; (the vertical bar creates main effects and interactions, which can also be written as MODEL PASS=FAMILY SCHOOL FAMILY*INCOME;   )
--
Paige Miller
Reeza
Super User

I think I may have misunderstood the question, I would definitely trust @PaigeMiller solution over mine!

Recep
Quartz | Level 8

Thanks a lot for your response Paige!

 

Did you mean:

 

MODEL PASS = FAMILY_INCOME SCHOOL FAMILY_INCOME*SCHOOL;

 

?

 

Cheers,

 

Recep

PaigeMiller
Diamond | Level 26

Yes, that's what I meant

--
Paige Miller
Ksharp
Super User

that wil lead you to Generalize Mixed Model. Try GLIMMIX.

 

PROC GLIMMIX DATA = TEST;

class school;

MODEL PASS = FAMILY_INCOME/dist=binomial;

random intercept FAMILY_INCOME /subject=school;

RUN;

PaigeMiller
Diamond | Level 26

@Ksharp wrote:

that wil lead you to Generalize Mixed Model. Try GLIMMIX.

 

PROC GLIMMIX DATA = TEST;

class school;

MODEL PASS = FAMILY_INCOME/dist=binomial;

random intercept FAMILY_INCOME /subject=school;

RUN;


I don't see this as answering the original question. My interpretation is that the original question was not asking for RANDOM effects to be included in the model. If you make something a RANDOM effect, then you won't get an estimate of the slopes, and you won't get estimates of the intercepts.

 

I would not have a problem with this as a solution to the problem:

 

proc glimmix data=test;
    class school;
    model pass=family_income|school/dist=binomial;
run;
--
Paige Miller
Recep
Quartz | Level 8

This discussion points to the root of my original problem: I think I'm having a bit of a hard time to understand the difference between having a "varying slope" vs. "random effects" for a particular variable (the school in my example). So, Paige, would you say the LOGISTIC regression you proposed would still be a fixed effects for "SCHOOL"?

 

@Ksharp, thanks for your response as well! Even though the code you provided did not work for my data (it may be just because my made up data was not big/versitile enough for the GLIMMIX) how would you differentiate a "varying slope" vs "random effects"?

 

Thanks a lot in advance to both of you...

 

Recep

 

 

PaigeMiller
Diamond | Level 26

In statistical terminology

 

If you are only interested in these specific schools, and you want to estimate a different slope and estimate a different intercept for each school, these are FIXED effects.

 

If you are interested in the entire population of schools and you have randomly selected these schools and you want to know the variability of the intercept across schools, or the variability of slopes across schools (in other words, a standard deviation of the intercepts or a standard deviation of the slopes), then you have a RANDOM effect.

 

The SAS procedure GLIMMIX will not estimate the slopes for you if you put SCHOOL in a RANDOM statement, it will give you a variance of the slopes.

 

As I understand your original question, and the models which you carefully wrote out, it seems to me the slopes and intercepts are FIXED effects, and thus a RANDOM statement is not needed here (in fact, in my opinion, a RANDOM statement incorrect in this situation).

--
Paige Miller

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 10 replies
  • 2230 views
  • 7 likes
  • 4 in conversation