Discussion:
Is there a way to get a "margins" graph or table in SPSS as one can do in Stata, in case of an interaction involving continuous variables?
(too old to reply)
federico tedeschi
2023-02-24 13:48:58 UTC
Permalink
The "margins" command in Stata allows one to plot the estimated effect of a variable X1 on an outcome Y for several values of a variable X2, in a model including a X1∗X2 interaction. Not only: it also permits the creation of a table with the estimated effects of X1 for multiple values of X2. This holds even when both variables are continuous:

https://stats.oarc.ucla.edu/stata/faq/how-can-i-understand-a-continuous-by-continuous-interaction-in-logistic-regression-stata-12/

Can anything like that be done with SPSS? The great majority of the online sources I found about SPSS relate to interactions between categorical variables. I found some examples involving one continuous variable, through the "emmeans" options. In particular, by writing: /EMMEANS=TABLES(X1
) WITH(X2=K), where k is a specific value, one can see the estimated effect of X1 for that value of X2

(see, for example, the penultimate row and last command line here: https://www.theanalysisfactor.com/why-report-estimated-marginal-means-in-spss-glm/

/EMMEANS=TABLES(X) WITH(V=50)) . Does one have to write one command line for each value of X2 for which one wants to estimated effect of X1 on Y? Also, is there any way to graph this? The great majority of the online sources I found about SPSS relate to interaction between categorical variables.
Bruce Weaver
2023-02-24 16:11:49 UTC
Permalink
Hi Federico. AFAIK, there is no way in SPSS that is nearly as easy as -margins- and -marginsplot- in Stata. However, using NOMREG with a bunch of TEST sub-commands, I can duplicate the contrasts you get from -margins-, but with one caveat. Bear in mind that when you use -margins- after -logit-, the default is to display predicted probabilities. If you want log-odds, you need to add the option predict(xb). I.e., try this:

margins, dydx(r) at(m=(30(5)70)) vsquish predict(xb)

Now the "slopes" that you see are on the log-odds scale, and look like this:

--------------------------------------
| Delta-method
| dy/dx std. err.
-------------+------------------------
r |
_at |
1 | .2405485 .0965139
2 | .2071807 .0807686
3 | .173813 .0653655
4 | .1404453 .0506178
5 | .1070776 .0373113
6 | .0737099 .0276142
7 | .0403421 .02595
8 | .0069744 .0335367
9 | -.0263933 .046005
--------------------------------------

I can reproduce those contrasts in SPSS using the NOMREG command to estimate the model with a a TEST sub-command, as follows. I used NOMREG because LOGISTIC REGRESSION and GENLIN, other commands you could use to estimate the model, do not have a TEST sub-command. But when you compare the table of coefficients to the table from Stata, you'll see that it estimates the same model.

NOMREG y (BASE=LAST ORDER=DESCENDING) WITH r m
/MODEL r m r*m
/INTERCEPT=INCLUDE
/PRINT=PARAMETER SUMMARY LRT CPS STEP MFI
/TEST "Intercept"
ALL 1 0 0 0
/TEST "B for simple effect of r"
ALL 0 1 0 0
/TEST "B for simple effect of m"
ALL 0 0 1 0
/TEST "B for r*m"
ALL 0 0 0 1
/TEST "r-slopes for m=30(5)70"
ALL 0 1 0 30;
ALL 0 1 0 35;
ALL 0 1 0 40;
ALL 0 1 0 45;
ALL 0 1 0 50;
ALL 0 1 0 55;
ALL 0 1 0 60;
ALL 0 1 0 65;
ALL 0 1 0 70
.

I included the 4 TEST sub-commands to demonstrate that I could reproduce the coefficients and SEs shown in the table of coefficients. The final TEST sub-command duplicates the 9 contrasts from Stata shown above. Here are is the relevant SPSS output:

Est SE Wald df Sig. Exp(B) Lower Upper
C1 .241 .097 6.212 1 .013 1.272 1.053 1.537
C2 .207 .081 6.580 1 .010 1.230 1.050 1.441
C3 .174 .065 7.071 1 .008 1.190 1.047 1.352
C4 .140 .051 7.699 1 .006 1.151 1.042 1.271
C5 .107 .037 8.236 1 .004 1.113 1.035 1.197
C6 .074 .028 7.125 1 .008 1.076 1.020 1.136
C7 .040 .026 2.417 1 .120 1.041 .990 1.095
C8 .007 .034 .043 1 .835 1.007 .943 1.075
C9 -.026 .046 .329 1 .566 .974 .890 1.066

To make those results accessible for graphing, you could use OMS to write the relevant tables to a new dataset, etc. But as you can already see, that is a fairly cumbersome process compared to using -margins- and -marginsplot- in Stata. Others may be able to suggest less cumbersome approaches, but I will be surprised if any of them are as straightforward as -margins- and -marginsplot- in Stata.

HTH.
Post by federico tedeschi
https://stats.oarc.ucla.edu/stata/faq/how-can-i-understand-a-continuous-by-continuous-interaction-in-logistic-regression-stata-12/
Can anything like that be done with SPSS? The great majority of the online sources I found about SPSS relate to interactions between categorical variables. I found some examples involving one continuous variable, through the "emmeans" options. In particular, by writing: /EMMEANS=TABLES(X1
) WITH(X2=K), where k is a specific value, one can see the estimated effect of X1 for that value of X2
(see, for example, the penultimate row and last command line here: https://www.theanalysisfactor.com/why-report-estimated-marginal-means-in-spss-glm/
/EMMEANS=TABLES(X) WITH(V=50)) . Does one have to write one command line for each value of X2 for which one wants to estimated effect of X1 on Y? Also, is there any way to graph this? The great majority of the online sources I found about SPSS relate to interaction between categorical variables.
federico tedeschi
2023-02-25 16:47:13 UTC
Permalink
Thank you very much, Bruce.

Are things easier in case the outcome is continuous?

Federico
Post by Bruce Weaver
margins, dydx(r) at(m=(30(5)70)) vsquish predict(xb)
--------------------------------------
| Delta-method
| dy/dx std. err.
-------------+------------------------
r |
_at |
1 | .2405485 .0965139
2 | .2071807 .0807686
3 | .173813 .0653655
4 | .1404453 .0506178
5 | .1070776 .0373113
6 | .0737099 .0276142
7 | .0403421 .02595
8 | .0069744 .0335367
9 | -.0263933 .046005
--------------------------------------
I can reproduce those contrasts in SPSS using the NOMREG command to estimate the model with a a TEST sub-command, as follows. I used NOMREG because LOGISTIC REGRESSION and GENLIN, other commands you could use to estimate the model, do not have a TEST sub-command. But when you compare the table of coefficients to the table from Stata, you'll see that it estimates the same model.
NOMREG y (BASE=LAST ORDER=DESCENDING) WITH r m
/MODEL r m r*m
/INTERCEPT=INCLUDE
/PRINT=PARAMETER SUMMARY LRT CPS STEP MFI
/TEST "Intercept"
ALL 1 0 0 0
/TEST "B for simple effect of r"
ALL 0 1 0 0
/TEST "B for simple effect of m"
ALL 0 0 1 0
/TEST "B for r*m"
ALL 0 0 0 1
/TEST "r-slopes for m=30(5)70"
ALL 0 1 0 30;
ALL 0 1 0 35;
ALL 0 1 0 40;
ALL 0 1 0 45;
ALL 0 1 0 50;
ALL 0 1 0 55;
ALL 0 1 0 60;
ALL 0 1 0 65;
ALL 0 1 0 70
.
Est SE Wald df Sig. Exp(B) Lower Upper
C1 .241 .097 6.212 1 .013 1.272 1.053 1.537
C2 .207 .081 6.580 1 .010 1.230 1.050 1.441
C3 .174 .065 7.071 1 .008 1.190 1.047 1.352
C4 .140 .051 7.699 1 .006 1.151 1.042 1.271
C5 .107 .037 8.236 1 .004 1.113 1.035 1.197
C6 .074 .028 7.125 1 .008 1.076 1.020 1.136
C7 .040 .026 2.417 1 .120 1.041 .990 1.095
C8 .007 .034 .043 1 .835 1.007 .943 1.075
C9 -.026 .046 .329 1 .566 .974 .890 1.066
To make those results accessible for graphing, you could use OMS to write the relevant tables to a new dataset, etc. But as you can already see, that is a fairly cumbersome process compared to using -margins- and -marginsplot- in Stata. Others may be able to suggest less cumbersome approaches, but I will be surprised if any of them are as straightforward as -margins- and -marginsplot- in Stata.
HTH.
Post by federico tedeschi
https://stats.oarc.ucla.edu/stata/faq/how-can-i-understand-a-continuous-by-continuous-interaction-in-logistic-regression-stata-12/
Can anything like that be done with SPSS? The great majority of the online sources I found about SPSS relate to interactions between categorical variables. I found some examples involving one continuous variable, through the "emmeans" options. In particular, by writing: /EMMEANS=TABLES(X1
) WITH(X2=K), where k is a specific value, one can see the estimated effect of X1 for that value of X2
(see, for example, the penultimate row and last command line here: https://www.theanalysisfactor.com/why-report-estimated-marginal-means-in-spss-glm/
/EMMEANS=TABLES(X) WITH(V=50)) . Does one have to write one command line for each value of X2 for which one wants to estimated effect of X1 on Y? Also, is there any way to graph this? The great majority of the online sources I found about SPSS relate to interaction between categorical variables.
Thank
Bruce Weaver
2023-03-03 15:03:00 UTC
Permalink
I don't think so, Federico. In that case, you might use UNIANOVA (or GLM) with LMATRIX sub-commands, but it would require the same basic approach. Given a choice, I would use -margins- and -marginsplot- in Stata rather than SPSS for this task. ;-)
Post by federico tedeschi
Thank you very much, Bruce.
Are things easier in case the outcome is continuous?
Federico
Andrea B
2023-12-07 00:50:28 UTC
Permalink
Sorry for stepping in.
I am facing a similar problem. I normally use STATA's margins and marginsplot, but this time I have to use SPSS because of the specific model I am estimating. It is a multilevel multinomial logistic regression with a very large sample and STATA's gsem takes literally days to give me an output. Using SPSS's generalized lineral mixed models, I successfully estimated the multilevel logit model. Now I am facing the problem of how to plot predicted probabilities for each outcome category at different values of a predictor in one single graph. This is what I would normally do with STATA's margins command, but SPSS doesn't have that option. I thought that one way could be to re-estimate the same model but as three separate binary logistic regressions, one for each of the three outcomes. Using the model estimates, I can derive predicted probabilities doing some calculations in Excel and plot them. This problem arises from the fact that in a multinomial model one of the three categories is treated as the baseline and in my case I need to show all three S-shaped curves in the graph, not just two of them relative to the baseline. Any suggestions would be greatly appreciated! Thank you in advance!!!!
Loading...