Announcement

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

  • Graphical Vizualization of Simulation Results

    Hey!

    I want to present the results of my statistical simulation with a different graph. So far I have greated only a boxplot, see attached:

    #delimit ;
    graph box t1 t3, title("Graph 2: Simulated probabilities of post-conflict relapse") ///
    scheme(s1mono) legend(off) ///
    note("Source: Created by the author based on statistical simulation technique (introduced by King et al. 2000)") ///
    ylabel(0 "0%" 0.2 "20%" 0.4 "40%" 0.6 "60%" 0.8 "80%") ///
    ytitle("Expected likelihood of conflict resurgence")
    name(graph2, replace);
    #delimit cr

    However, the problem is that the boxplot does not show the confidence intervals.Something like the second uploaded picture would be cool. How can I display my variable t1 and t3 just as lines indicating the confidence intervals and a dot in the middle for the mean (or median)?

    I'm very grateful for advice!
    Attached Files

  • #2
    Christoph Steinert a box plot wouldn't display any confidence intervals. Without knowing what happened prior to the graph it is a bit difficult to suggest things, but this type of graph can be created fairly easily with the marginsplot command. If you have the data in a different format/structure, another potential alternative would be to use a twoway rarea to graph the confidence intervals as an area and overlay the points of interest as a line or points on top of it.

    Comment


    • #3
      Thanks a lot for the response. I try to explain a bit better what I did. In a first step, I estimated a logistic regression model. With clarify I simulated the coefficients and I saved the simulated coefficients with their confidence intervals in a new variable. My goal is to display those simulated coefficients with their confidence intervals. Here my full procedure:

      set seed 1234
      estsimp logit prelapse pgma duration battledeath_log peacekeep polityt gdpcap_log ethnic victory milexp deminter if pperid != "174_1990", cluster(location)

      setx pgma 1 duration mean battledeath_log mean peacekeep mean polityt mean gdpcap_log mean ethnic mean victory mean milexp mean deminter mean
      setx
      simqi, genpr(t0 t1) level(95)
      sum t0 t1
      _pctile t1, p(2.5,97.5)
      scalar lo100 = r(r1)
      scalar up100 = r(r2)

      setx pgma 0 duration mean battledeath_log mean peacekeep mean polityt mean gdpcap_log mean ethnic mean victory mean milexp mean deminter mean
      setx
      simqi, genpr(t2 t3) level(95)
      sum t2 t3
      simqi
      _pctile t3, p(2.5,97.5)
      scalar lo101 = r(r1)
      scalar up101 = r(r2)

      Now I would like to display t1 and t3 in the described manner. I just tried "marginsplot t1 t3" but it says "varlist not allowed". t1 and t3 are simple continous variables which I want to display with their confidence intervals to compare the effects...

      Comment


      • #4
        You'll have to spend some time reading the manual entry on margins and marginsplot. If you have the point estimates and confidence intervals in a dataset (either from your simulations or from a call to margins, saving(filename)), then the following code will get you started on creating a graph:

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input int x float(high low mean)
        1   20.28003  -23.94995  -1.834961
        2   47.76001 -25.380005   11.18994
        3   50.23999  29.140015   39.68994
        4   34.77002  -5.050049  14.859985
        5 -1.6500244  -23.70996 -12.680054
        end
        
        twoway rcap high low x  || scatter mean x, mcolor(black) msize(small) yline(0, lpattern(dash) lcolor(gray)) legend(off)
        Stata/MP 14.1 (64-bit x86-64)
        Revision 19 May 2016
        Win 8.1

        Comment


        • #5
          Hmm, when I type this in then I get the error command "variable t1 already defined". Isn't there in easier way to plot the two variables with their confidence intervals?

          Comment


          • #6
            When you type what? Please tell use exactly what you typed and exactly what Stata responded with. Please use [CODE][/CODE] delimiters around any code and/or Stata output.
            Stata/MP 14.1 (64-bit x86-64)
            Revision 19 May 2016
            Win 8.1

            Comment


            • #7
              Sorry, for my unspecific answer! I typed the following:

              Code:
              [input int t1 float(high low mean)]

              Statas Response:
              [variable t1 already defined]
              r(110);


              Comment


              • #8
                To input the example data, or to type in new data containing your CIs, you must type clear first (which will eliminate your dataset) or open a new instance of Stata.

                Put [CODE] before your first word (input in this case) and [/CODE] after your last word (r(110); in this case).
                Stata/MP 14.1 (64-bit x86-64)
                Revision 19 May 2016
                Win 8.1

                Comment


                • #9
                  Great, thank you so much! Now it works! I have now only some minor issues. I attach my Graph as a PDF. 1.) How can I get rid of the xlabels (0.5 1 1.5 2 2.5) and nevertheless keep this range of the xaxis? 2.) Is there a way to bring the two lines closer together? 3.) How can I label them with meaningful names?

                  Code:
                  clear
                  input int x float(high low mean)
                  1 0.62744436 0.38474058 0.505633
                  2 0.07221445 0.45795712 0.2208324
                  end
                  
                  #delimit ;
                  twoway rcap high low x  || scatter mean x, mcolor(black) msize(small) legend(off) ///
                  xlabel(0.5 1 1.5 2 2.5, grid) ylabel(0 "0%" 0.2 "20%" 0.4 "40%" 0.6 "60%" 0.8 "80%") ///
                  scheme(s1mono) ///
                  note("Source: Created by the author based on statistical simulation technique (introduced by King et al. 2000)") ///
                  title("Graph 2: Simulated probabilities of post-conflict relapse") ///
                  ytitle("Expected likelihood of conflict resurgence") ///
                  name(graphx, replace);
                  #delimit cr
                  Attached Files

                  Comment


                  • #10
                    You would do well to read about twoway graph options (help twoway_options). First, you've told the graph to include those x labels with the xlabel option. You should change that to something meaningful. To bring the lines closer together, change the scale of the graph by increasing the range of the x-axis.

                    Code:
                    #delimit ;
                    twoway rcap high low x  ||
                    scatter mean x, mcolor(black) msize(small) legend(off) 
                    xlabel(1 "something" 2 "meaningful", grid) 
                    xscale(range(0 3)) 
                    ylabel(0 "0%" 0.2 "20%" 0.4 "40%" 0.6 "60%" 0.8 "80%") 
                    scheme(s1mono) 
                    note("Source: Created by the author based on statistical simulation technique (introduced by King et al. 2000)") 
                    title("Graph 2: Simulated probabilities of post-conflict relapse") 
                    ytitle("Expected likelihood of conflict resurgence") 
                    name(graphx, replace);
                    #delimit cr
                    Note that the advantage of using #delimit ; is that the line does not end until it reaches the semicolon. Therefore there is no need to use /// to break up lines of code

                    Stata/MP 14.1 (64-bit x86-64)
                    Revision 19 May 2016
                    Win 8.1

                    Comment


                    • #11
                      Christoph: If I understand your needs correctly, Roger Newson's eclplot may be helpful to you (see also parmest), both on SSC. Also Ben Jann's coefplot (SJ)

                      Comment


                      • #12
                        Great, thank you so much!

                        Comment


                        • #13
                          Previous has been flagged as spam. One such report should be enough!

                          Comment

                          Working...
                          X