I would like to plot on the same graph the interaction between my continuous predictor and my categorical moderator. I know how to do it when both are categorical (factor interaction), but don't really know how to do it when one is continuous and one is categorical.
2 Answers
If you're talking about an interaction in a general linear model (e.g., ANCOVA), and if your categorical moderator has a reasonably small number of levels, you can plot separate regression lines for each level of the moderator. If you want these on the same plot, superimpose them, code by color or line type, and provide a legend. One of your plot's axes will represent the continuous predictor (presumably the horizontal "$x$" axis), and the other will represent the dependent variable, which I'm assuming is continuous. If your categorical predictor (moderator) has more than four levels, that might get a little too busy for one plot, but I'm not aware of a better method for such circumstances that doesn't resort to separate plots for each level.
-
$\begingroup$ thanks for your reply! I am indeed referring to a GLM (univariate),which only lets me plot estimated marginal means for factor interactions. I am not sure how to superimpose as you say...I work with SPSS. could you please detail a bit more on that? $\endgroup$– AndreeaCommented Jan 14, 2014 at 13:30
-
1$\begingroup$ For SPSS just save the predicted values after estimating the model. Then in the graph plot the predicted values on the Y axis, and the continuous predictor on the X axis, then use the categorical variable to group the lines or points. $\endgroup$– Andy WCommented Jan 14, 2014 at 13:35
-
$\begingroup$ thanks! just to clarify, which graph plot exactly do I need to produce for this? Is it a scatter plot with regression line? If so, then I would need to produce 3 different graphs for the 3 different levels of my moderator...how do I put it on the same graph? Also just to clarify that the predicted values take into consideration the adjusted regression with covariates? $\endgroup$– AndreeaCommented Jan 14, 2014 at 13:50
-
1$\begingroup$ @Andreea, I have added an answer to address your comment. $\endgroup$ Commented Jan 14, 2014 at 14:31
-
$\begingroup$ @AndyW do you save the predicted values from the estimated model with or without the interaction term (or does it not matter)? $\endgroup$ Commented Oct 26, 2014 at 13:34
Just to address the following comment:
thanks! just to clarify, which graph plot exactly do I need to produce for this? Is it a scatter plot with regression line? If so, then I would need to produce 3 different graphs for the 3 different levels of my moderator...how do I put it on the same graph? Also just to clarify that the predicted values take into consideration the adjusted regression with covariates?
Here is how to do it in SPSS. I use the Employee.sav
data as example. Suppose we'd like to use salary as outcome, beginning salary as the continuous predictor and job category as the categorical predictor:
Go to Graph > Legacy > Scatter:
Choose just simple scatter plot is fine. Then, fill in the variables:
You'll then see the scatter plot. Double click on the scatter plot to open the chart editor. At the top, click the icon to "fit lines to subgroups." See pic below:
Done:
Now, whether you use the original salary variable as outcome or the predicted salary as outcome adjusted for the other third or more predictors is a matter of your purpose. The original salary will fit better as exploration, while the predicted salary will be more suitable as presenting your regression results.
-
$\begingroup$ thank you! This confirms what I did is ok, I have other covariates involved so I have to use predicted outcome (saved as unstandardised in the regression model). This is of much help! $\endgroup$– AndreeaCommented Jan 14, 2014 at 15:45
-
$\begingroup$ I have another question: I am unsure that I should stick with continuous predictors in my regression analysis, as the associations, while significant both before and after adjustment, they seem to be driven by big outliers. If I split my predictor into 3 categories (zero frequencies, below and above median), then I do not have any significant associations with the continuous outcome anymore. Any suggestions of what the best way to go would be? thank you $\endgroup$– AndreeaCommented Jan 14, 2014 at 20:25
-
$\begingroup$ How many "big outliers" are we talking about? Do you have any other unusual information about them that could justify their exclusion from your sample? If it's less a matter of outliers than of a non-normal distribution, you might consider fitting a robust/nonparametric GLM to reduce bias in your results. $\endgroup$ Commented Jan 14, 2014 at 20:43
-
$\begingroup$ thanks for the suggestion. My continuous outcomes don't appear to be normally distributed when I do a hystogram, but when I do a residuals plot (save standardised residuals in GLM), and I look for an approximately rectangular scatter, they seem to fit into this pattern, which suggests similar levels of variation across the range of predicted value, so that's ok I'd say. In terms of outliers, there seem to be between 1-3 outliers judging from the scatter plot (i can't seem to be able to copy-paste the plots here). I have never worked with nonparametric GLM so not sure where to find that in SPSS $\endgroup$– AndreeaCommented Jan 14, 2014 at 22:02