Dear Statalist,
I am having trouble producing an interaction plot between a (restricted cubic) spline variable and a nominal variable. I am using Stata 14.2 for Mac.
My model is a poisson regression with robust standard errors producing relative risks. The dependent variable is non-receipt of surgery for breast cancer (no_surg). The independent variables are hormone receptor status (hr_status), which is a nominal variable with 3 levels and comorbidity severity score (c3), which is a restricted cubic spline with 3 knots. I ran a model with the main effects and interaction. I want to produce an interaction plot showing how the relationship between comorbidity severity and non-receipt of surgery varies by hormone receptor status. I would like to plot the range of C3 values from the 5th to the 95% centile, which is approximately 0 to 3 and includes non-integer values.
I have explored using margins however this is problematic as margins does not recognise that the two variables that make up the spline belong together.
I then trialled an approach suggested by Maarten Buis1 and mentioned in a previous Statalist post (https://www.statalist.org/forums/for...-cubic-splines). This uses margins to graph predictions for a continuous variable (fixed at various functions of the mean and standard deviation) against a linear spline. The issue I had with this was that C3 contains non-integer values.
I also tried looking at the interaction between hormone receptor status and age (also a restricted cubic spline with 3 knots) using the same approach thinking this would work given age has only integers. However this produced a graph opposite to what I am after, that is, with hormone receptor status on the x axis and predictions for every value of age. I figure this is because I am using a categorical variable rather than continuous as was used in the example.
Any advice on this problem would be greatly appreciated.
Reference
Buis, M. Additional examples for: Stata tip #: Exploring model consequences by plotting different predictions (Translated to Stata > 12). Cited [2018 Mar 25]. Available from http://maartenbuis.nl/wp/inter_quadr...quadr_new.html.
I am having trouble producing an interaction plot between a (restricted cubic) spline variable and a nominal variable. I am using Stata 14.2 for Mac.
My model is a poisson regression with robust standard errors producing relative risks. The dependent variable is non-receipt of surgery for breast cancer (no_surg). The independent variables are hormone receptor status (hr_status), which is a nominal variable with 3 levels and comorbidity severity score (c3), which is a restricted cubic spline with 3 knots. I ran a model with the main effects and interaction. I want to produce an interaction plot showing how the relationship between comorbidity severity and non-receipt of surgery varies by hormone receptor status. I would like to plot the range of C3 values from the 5th to the 95% centile, which is approximately 0 to 3 and includes non-integer values.
I have explored using margins however this is problematic as margins does not recognise that the two variables that make up the spline belong together.
Code:
// Create a restricted cubic spline for C3 mkspline c3spline = c3, knots(0 0.1 2.8) cubic // Estimate the regression model with main effects & interaction qui poisson no_surg c.c3spline*##hr_status, vce(robust) irr // Obtain predictions qui margins, at(c3=(0(0.1)3)) over(hr_status) expression(exp(xb())) // Error message c3 ambiguous abbreviation r(111);
Code:
// Obtain predictions qui margins, at(hr_status=1 hr_status=2 hr_status=3) over(c3) expression(exp(xb())) // Error message only integer values are allowed in by() variables r(198);
Code:
// Create a restricted cubic spline for age mkspline agespline = age, knots(38 57 83) cubic // Estimate the regression model with main effects & interaction qui poisson no_surg c.age*##hr_status, vce(robust) irr // Obtain predictions qui margins, at(hr_status=1 hr_status=2 hr_status=3) over(age) expression(exp(xb())) // Plot predictions marginsplot, noci
Reference
Buis, M. Additional examples for: Stata tip #: Exploring model consequences by plotting different predictions (Translated to Stata > 12). Cited [2018 Mar 25]. Available from http://maartenbuis.nl/wp/inter_quadr...quadr_new.html.
Comment