BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Taliah
Obsidian | Level 7

We are running a linear regression model with 4 numerical independent variables predicting a numerical dependent variable. We now need to add two additional categorical independent varables.

The client wants a seperate prediction for each commbination of the two new categorical independent variables. 

Thinknig of proc GLM with the categorical variables in the class statement, but can't see how to get a separate prediction forf each commbination of the two new categorical independent variables. All help will be appreciated, Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
StatDave
SAS Super FREQ
You will get a predicted value for each observation in your data set. So, observations with different combinations of values of all of the variables in your model will have different predicted values. If what you want is a single predicted mean value for just the combinations of those two categorical variables, then you probably will want to add the LSMEANS statement. For example:
lsmeans a*b;

View solution in original post

8 REPLIES 8
StatDave
SAS Super FREQ
That is what the CLASS statement is for. Many modeling procedures (GLM, GENMOD, GLIMMIX, and so on) have a CLASS statement that allows you to specify the variables that are categorical. Then those variables can also be included in the MODEL statement along with the numerical, continuous variables. You will see examples in the documentation of the procedures. If you have been using PROC REG, you will need to change to PROC GLM or one of the others that have a CLASS statement.
Taliah
Obsidian | Level 7

Thank you! using proc GLM the way you suggest, how can I get a separate predition for each combinatin of teh two categorical variables?

Also we just realized we will need to do the same also for a model where we use autoreg due to autocorrelation in teh data. Id there a way to add teh two class variables to proc autoreg or another proocn that can handle data with autocorrelation (we can add the lag of the dependent variable to the GLM model' but that would not be the same as running proc autoreg). Thamnk you!

StatDave
SAS Super FREQ
Include the interaction of the two categorical variables. For example, for two categorical variables, a and b, their interaction is a*b:

class a b;
model y=x1 x2 a b a*b;
Taliah
Obsidian | Level 7

@StatDave wrote:
Include the interaction of the two categorical variables. For example, for two categorical variables, a and b, their interaction is a*b:

class a b;
model y=x1 x2 a b a*b;


Thank you! I use the "PREDICTED" value I get from the model output. Will the intercation you wrote result in getting a predicted value for each combination?

StatDave
SAS Super FREQ
You will get a predicted value for each observation in your data set. So, observations with different combinations of values of all of the variables in your model will have different predicted values. If what you want is a single predicted mean value for just the combinations of those two categorical variables, then you probably will want to add the LSMEANS statement. For example:
lsmeans a*b;
Taliah
Obsidian | Level 7

Thank you very much for all your help!

PaigeMiller
Diamond | Level 26

@Taliah wrote:

 

The client wants a seperate prediction for each commbination of the two new categorical independent variables. 


Although @StatDave has provide a complete and correct answer, I feel it would be helpful to point out that you do NOT get predictions for "each combination" of the independent variable. You get predictions for each observation. This has nothing to do with SAS, this is how the math works.

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 8 replies
  • 1004 views
  • 2 likes
  • 3 in conversation