Solved
Contributor
Posts: 31

# Varying intercept and slope in regression analyses

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_ID PASS FAMILY_INCOME SCHOOL 1 1 120000 sch1 2 1 170000 sch1 3 0 90000 sch1 4 0 91500 sch1 5 0 93000 sch1 6 1 180000 sch1 7 1 225000 sch1 8 1 150000 sch1 9 1 90000 sch2 10 1 92000 sch2 11 1 94000 sch2 12 0 78000 sch2 13 1 110000 sch3 14 0 50000 sch3 15 1 140000 sch3

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

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:

where

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:

where

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?

Recep

Accepted Solutions
Solution
‎06-14-2017 01:06 PM
Posts: 2,055

## Re: Varying intercept and slope in regression analyses

[ Edited ]
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

All Replies
Super User
Posts: 20,735

## Re: Varying intercept and slope in regression analyses

2 - BY statement.

proc logistic ...;

by school hospital;

model .....;

run;

Posts: 2,055

## Re: Varying intercept and slope in regression analyses

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
Solution
‎06-14-2017 01:06 PM
Posts: 2,055

## Re: Varying intercept and slope in regression analyses

[ Edited ]
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
Super User
Posts: 20,735

## Re: Varying intercept and slope in regression analyses

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

Contributor
Posts: 31

## Re: Varying intercept and slope in regression analyses

Thanks a lot for your response Paige!

Did you mean:

MODEL PASS = FAMILY_INCOME SCHOOL FAMILY_INCOME*SCHOOL;

?

Cheers,

Recep

Posts: 2,055

## Re: Varying intercept and slope in regression analyses

Yes, that's what I meant

--
Paige Miller
Super User
Posts: 10,213

## Re: Varying intercept and slope in regression analyses

[ Edited ]

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;

Posts: 2,055

## Re: Varying intercept and slope in regression analyses

[ Edited ]

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
Contributor
Posts: 31

## Re: Varying intercept and slope in regression analyses

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

Posts: 2,055

## Re: Varying intercept and slope in regression analyses

[ Edited ]

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
☑ This topic is solved.