Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Visualizing two regression in one graph

    Dear Statalist respected users,

    I ran two regression models and I want to visualize the impact of 2 different interactions (one from each model) on an outcome variable, which is the same on the two models.
    For example,
    the first model: y = B0 + B1X1 + B2X2 + B3X2*X3 + e

    The second model: y= B0 + S1X1 + S2X2 + S3X2*X3 + e

    I want to visualize the impact of B3 and S3 on y in one graph.

    Thanks a lot in advance.

    Kind regards,
    Mohammed Kasbar

  • #2
    Tell us more about X1 X2 X3.

    What do you imagine would be on the y and x axes of such a graph?

    You can plot in a two-dimensional space

    (1) observed vs fitted, always

    (2) residual vs fitted, always

    (3) data and fit for response versus one predictor, if the other predictors are just shifting a fit in that space.

    These are evident possibilities, not a complete list.

    Comment


    • #3
      Nick Cox

      thanks a lot for your reply.
      Actually, I am not sure which option of the three which you gave me best fits my case.

      I estimated 2 models and I found that the interaction between X2 and X3 in the first model was positive while it was negative in the second model. Please note that X2 is different in the 2 models while X3 is exactly the same. The outcome variable is also the same in the 2 models.

      So, I want to show how the change in X2 can change the relationship between X3 and Y.


      I am not sure which option of the 3 options you gave me best fit my case.

      I wish i well well explained your question.

      Thanks a a lot in advance.

      Kind regards,
      mohammed Kasbar

      Comment


      • #4
        Thanks for the detail, but we're still short of knowing whether at least two of X1 X2 X3 are indicators [(0, 1) variables] which I think is necessary and sufficient for (c) in #2 to apply.

        Superimposing two sets of results is probably going to produce a mess any way. I would put either (a) or (b) side-by-side for the two regressions, and also consider added variable plots.

        Comment


        • #5
          Nick Cox

          thanks a lot for your reply. Yes, you are right; both X2 and X3 are dichotomous variables.
          So, I appreciate if you provide me with more details about the C option you provided in #2.

          thanks a lot in advance.

          Kind regards,
          Mohammed Kasbar

          Comment


          • #6
            You can plot Y versus X1 and superimpose the predicted values from the regression. That won't be (can't be) a complete rendering of the data.
            Last edited by Nick Cox; 21 Mar 2018, 13:13.

            Comment


            • #7
              Thanks a lot.
              This is much appreciated

              Comment


              • #8
                What I said in #6 was a little too pessimistic as the four distinct values of two indicators can be shown by four distinct markers. This shows some flavour for a regression simpler than yours -- and I would not want to do more than put the graph for another regression alongside.

                The veryshortlabel optionof separate is documented at

                SJ-5-4 gr0023 . . . . Stata tip 27: Classifying data points on scatter plots
                . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
                Q4/05 SJ 5(4):604--606 (no commands)
                tips for using separate, gray-scale gradation, and text
                characters as class symbols to classify data points on
                a scatter plot

                namely http://www.stata-journal.com/sjpdf.h...iclenum=gr0023


                Code:
                sysuse auto, clear
                set scheme s1color 
                
                gen recmpg = 1000/mpg 
                
                su length, meanonly 
                gen hilength = length > r(mean) 
                
                regress recmpg weight i.foreign i.hilength 
                predict predicted 
                
                egen group = group(foreign hilength), label 
                
                separate recmpg,  by(group) veryshortlabel 
                local response "`r(varlist)'" 
                
                separate predicted, by(group) veryshortlabel 
                local predictions "`r(varlist)'" 
                
                scatter `response' weight , ms(Oh + Sh X) mc(orange blue black magenta) ///
                || line `predictions' weight, sort lc(orange blue black magenta) ///
                legend(order(1 2 3 4) col(1) pos(3)) ytitle(Gallons per 1000 miles)
                Click image for larger version

Name:	interaction.png
Views:	1
Size:	35.6 KB
ID:	1435561

                Comment


                • #9
                  Nick Cox

                  Dear Nick,

                  Thanks a lot for your informative reply. I do apologize for replying late but I did not check my page for 2 days as I was busy teaching.
                  Thanks a lot again for your priceless efforts.

                  Kind regards,
                  Mohammed Kasbar

                  Comment

                  Working...
                  X