Programming the statistical procedures from SAS

Varying intercept and slope in regression analyses

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

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_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

Attachment

Accepted Solutions
Solution
a week ago
Trusted Advisor
Posts: 1,415

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;   )

View solution in original post


All Replies
Grand Advisor
Posts: 16,858

Re: Varying intercept and slope in regression analyses

2 - BY statement.

 

proc logistic ...;

by school hospital;

model .....;

run;

Trusted Advisor
Posts: 1,415

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.

Solution
a week ago
Trusted Advisor
Posts: 1,415

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;   )
Grand Advisor
Posts: 16,858

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: 23

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

Trusted Advisor
Posts: 1,415

Re: Varying intercept and slope in regression analyses

Yes, that's what I meant

Grand Advisor
Posts: 9,447

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;

Trusted Advisor
Posts: 1,415

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;
Contributor
Posts: 23

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

 

 

Trusted Advisor
Posts: 1,415

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).

☑ This topic is SOLVED.

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

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