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!
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
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!
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?
What I get:
What I would like to get:
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 😕
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.
Ready to level-up your skills? Choose your own adventure.