Announcement

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

  • plotting scales (with marginsplot)

    Hi all,

    I am using marginsplot to draw graphs with confidence intervals using the following syntax:

    Code:
    regress Y x1 c1 c2 c3 
    margins, at(x1 =(1 3 5 7 9 11 13 15 17))
    marginsplot, scheme(s1manual) title("") ytitle("Y variable") xtitle("x1 variable") plotopts(msize(vtiny)) yscale(range(1 5)) ylabel (#1)
    then i repeat it for x2 x3 x4 independent variables.

    as I want to present all these plots in a comparable manner (visually), i used yscale option. however, when plot confidence intervals go outside the range specified in yscale the range on the plot is automatically adjusted accordingly.

    e.g. if the Y variable values range between 2 and 4 (well within 1-5 range defined by yscale), but its confidence interval goes from 0 to 5, the Y variable scale on the plot is automaticaly adjusted to be 0 to 5, instead 1 to as I defined by yscale option

    I do understand that this is probably a feature, but how i can get around it and plot all graphs on the same Y scale?


    Increasing the range for all graphs is not an options, as the CI as sometimes extremely wide and some graphs will look like a straight line - e.g. if Y values are between 4 and 5 and CI values are between 0 and 10

    Hope that I managed to describe the problem...


    thank you in advance,

    C.












  • #2
    Well, I think we can all agree that it is not possible to plot a zero value on a scale that only runs from 1 to 5. So either you have to accept the rescaling that Stata is giving you, or you have to omit the confidence intervals (which seem to be the only values that go outside your preferred range) from the plot. -marginsplot- has a -noci- option which suppresses plotting of the confidence intervals.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      Well, I think we can all agree that it is not possible to plot a zero value on a scale that only runs from 1 to 5. So either you have to accept the rescaling that Stata is giving you, or you have to omit the confidence intervals (which seem to be the only values that go outside your preferred range) from the plot. -marginsplot- has a -noci- option which suppresses plotting of the confidence intervals.
      i hoped for some way to plot it, but maybe to cut off the CI lines that go out of range at the border...

      Comment


      • #4
        I hope not to be taken amiss, but, if some of the CIs are 'extremely wide", contrasting with the CIs from other variables, as you remarked, the graphs under Stata can just present the phenomenon. I believe we agree that getting rid of the CIs may surely present a "cleaner" graph under this scenario, but this is "getting around" just in terms of omiting the information.
        Best regards,

        Marcos

        Comment


        • #5
          Implicit in Clyde's and Marco's answers - but worth stating in response to post #3 = is that Stata's "philosophy" of its graphics, at least as I have experienced it, is that Stata will make whatever adjustments it must to the options you specify in order to be able to present all the data you specify to be plotted and Stata leaves it to the user to select the data appropriately. This makes sense for something like scatter plots - you do not want to inadvertently hide unnoticed or unexpected outliers from the user - it does not work so well for situations like the one you are encountering, especially when the plotting data is created and selected by a program only indirectly under your control.

          Comment


          • #6
            thank you, all

            Comment


            • #7
              Strictly speaking, what you want can be done by saving the margins predictions and confidence intervals and using twoway to graph. However, I cannot emphasize Clyde's, Marco's and William's point that it would be better to present the graph "as is" or just to drop the confidence intervals altogether because any modified intervals would be misleading. For illustration, I show that you can achieve what you want using the user written command -marginscontplot-. Margins also allows you to save the predicted margins

              Code:
              clear
              sysuse auto
              qui regress mpg i.rep78 weight
              margins, at(rep78=(1 2 3 4 5))
              marginsplot


              Assume we want to restrict the upper bound of the ci to 24

              Code:
              *\\ To install, type -findit marginscontplot- and follow instructions to install
              quietly marginscontplot rep78, ci saving(graph, replace)
              
              *\\ Confidence interval saved in external dataset
              use graph
              
              *\\ Upper bound ci saved as _ci_ub. Restrict upper bound to 24
              gen _ci_ub1= cond( _ci_ub< 24, _ci_ub, 24 )
              
              *\\ Plot with twoway
              twoway (rcap _ci_lb _ci_ub1 rep78, sort pstyle(ci))(line _margin rep78, sort lstyle(refline))
              Click image for larger version

Name:	margins.png
Views:	1
Size:	36.6 KB
ID:	1382844

              Comment


              • #8
                Originally posted by Andrew Musau View Post
                Strictly speaking, what you want can be done by saving the margins predictions and confidence intervals and using twoway to graph. However, I cannot emphasize Clyde's, Marco's and William's point that it would be better to present the graph "as is" or just to drop the confidence intervals altogether because any modified intervals would be misleading. For illustration, I show that you can achieve what you want using the user written command -marginscontplot-. Margins also allows you to save the predicted margins

                Code:
                clear
                sysuse auto
                qui regress mpg i.rep78 weight
                margins, at(rep78=(1 2 3 4 5))
                marginsplot


                Assume we want to restrict the upper bound of the ci to 24

                Code:
                *\\ To install, type -findit marginscontplot- and follow instructions to install
                quietly marginscontplot rep78, ci saving(graph, replace)
                
                *\\ Confidence interval saved in external dataset
                use graph
                
                *\\ Upper bound ci saved as _ci_ub. Restrict upper bound to 24
                gen _ci_ub1= cond( _ci_ub< 24, _ci_ub, 24 )
                
                *\\ Plot with twoway
                twoway (rcap _ci_lb _ci_ub1 rep78, sort pstyle(ci))(line _margin rep78, sort lstyle(refline))
                [ATTACH=CONFIG]n1382844[/ATTACH]
                Thank you Andrew, that is exactly what i was looking for!

                Comment


                • #9
                  This is what may be called "vexata quaestio". Hopefully other points of view will be shared here.

                  I agree it is possible to use a "range cap" - rcap - graph so as to display CIs. I also agree that, depending on the command, it is possible to "bar" the presentation of the CIs correctly under a rcap graph. In #7, Andrew gave a clever demonstration about how to produce such a graphic.

                  That said, a few issues come to my mind:

                  First, as far as I'm concerned (and I may be wrong), this strategy is not provided under "regular" marginsplot command in Stata, and I believe for due reason: it won't be the CI, truly, anymore.

                  Second, the SJ marginscontplot - also, mcp - , written by Patrick Royston, was designed to provide reliable "marginsplot" for continuous variables, hence the lack of any indication in the article about "getting around" extremely large CIs.

                  Third, I fear that "getting around" large-range CIs, as wanted in #1, will lead to a "well-behaved" graph. Just that. But not "the" CIs, for that matter. I wonder whether this aspect shouldn't be underlined in the footnote of the graph sent to a journal. Moreover, I wonder whether it should be accepted for publication.

                  Before ending, I wish to repeat the closing remark in #4: I believe we agree that getting rid of the CIs may surely present a "cleaner" graph under this scenario, but this is "getting around" just in terms of omiting the information.
                  Last edited by Marcos Almeida; 09 Apr 2017, 18:40.
                  Best regards,

                  Marcos

                  Comment


                  • #10
                    HI Marcos,

                    I agree with your points, however, this all depends on what is the final goal. My goal is to present the the plots in comparable manner. I am not trying to hide CIs, i do want to present them and their range (wide/narrow) is part of the story. I think the way presented by Andrew still allows to understand what are the true CIs, as only one side of them is capped and only one or two extremes will be capped. Also, I can always put the uncapped full scape plots in the appendix.

                    Comment


                    • #11
                      Yes, I very much agree with Marcos. The graph in question no longer contains confidence intervals: it contains intervals that have been trimmed in such a way that their coverage probabilities are no longer the stated probabilities. As such, unless there is a prominent and clear annotation on the graph to indicate that this has happened, I would regard such a graph as misleading. I think the annotation needs to be plainly visible because, by habit, people seeing the rcaps instinctively assume that they represent either standard errors or 95% confidence intervals. When such a strongly ingrained convention is being violated, it is incumbent on the author of the graph to unambiguously warn the reader.

                      Added: Crossed with #10.

                      Comment

                      Working...
                      X