BookmarkSubscribeRSS Feed
rerere
Calcite | Level 5

 

Dear community,

Unfortunately, we don't work with SAS very often at the university. Therefore, I have been attempting to code a multilevel logistic regression using proc glimmix over the past few days. I successfully defined the model, but I am now facing challenges in visualizing the plot.

The model is as follows:

/*Random Intercept, fixed slope model*/
proc glimmix data=muslim method=LAPLACE empirical;
class country_1 sex (ref="0") believe_god (ref="0");
model anti_muslim(ref="0") = age sex edu rlscale2 believe_god attend_rel  
   /link = logit distribution=binary solution alpha=0.05; 
random intercept / subject = country_1 type = un;
output out = predict pred = logitpred;
run;

I am grouping the data by countries (N=34), and my outcome variable is dichotomous (responding to the question: "Would you like to have a Muslim as your neighbor?" where 0=no). Additionally, I have a few Level 1 predictors (age, sex, etc.). My goal is to create a spaghetti plot with the predicted outcome on the y-axis and the predictor on the x-axis. I believe that by doing this, I should obtain a graph with 34 lines representing each country's development over the predictor.

 

My attempted approach is as follows:

proc sort data = muslim;
by age sex edu rlscale2 believe_god attend_rel;
run;

data predict;
set predict;
pred = logistic(logitpred);
run;

title "Plot";
proc sgplot;
series y = pred x = age / group = country_1;
run;

 

Unfortunately, the resulting visualized plot is quite confusing. My suspicion is that SAS created a line for every individual (Level 1 unit).

 

I am unsure of what might be causing this issue and would greatly appreciate any assistance.

One more piece of information: There are missing values in the predictors. As a result, when I save the predicted values as shown above, there are numerous missing values in that variable.

 

Thank you in advance for any help you can provide and if you need any information please ask!

 

4 REPLIES 4
sbxkoenk
SAS Super FREQ

Create spaghetti plots in SAS
By Rick Wicklin on The DO Loop June 2, 2016
https://blogs.sas.com/content/iml/2016/06/02/create-spaghetti-plots-in-sas.html

 

Lasagna plots in SAS: When spaghetti plots don't suffice
By Rick Wicklin on The DO Loop June 8, 2016
https://blogs.sas.com/content/iml/2016/06/08/lasagna-plot-in-sas.html

 

Koen

rerere
Calcite | Level 5

Hey Koen,

Thanks for your reply! I've read the text, and it provided me with some useful insights. I believe I now understand why my code isn't working, but I have no idea how to fix it. It seems I need to take the other predictors into account in my plot!

GraphGuy
Meteorite | Level 14

Could you post a picture of what your graph looks like?

And could you perhaps sketch out by hand an example of what you would like your graph to look like?

 

rerere
Calcite | Level 5

What I get:

Screenshot 2023-09-01 115858.jpg

 

What I would like to get:

right.jpg

 

I think my problem is that I didn't consider the other predictors in this plot, but I have no clue how to take them into account 😕

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 764 views
  • 1 like
  • 3 in conversation