Announcement

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

  • Add a p value on a boxplot

    Hi everyone, im trying to graph over 20 different boxplots in wich i would like to put the p value of a Wilcoxon´s test as the image below. But i have no clue how to do that, here is my code:

    graph box tfg_b, over(breslow) by(type) ytitle(TFG Beta) nooutsides note("") box(1,bcolor(dkorange)) graphregion(color(white))
    graph export tfg_b_breslow.png, replace



    Any suggestion? thank you!
    just a p value, no the arrows i get this, i need the pvalue whitin and between groups
    Last edited by Sebastian Epinoza; 29 Oct 2015, 15:17.

  • #2
    Well, there are several different tests that people refer to as Wilcoxon's, so I'm not sure which command you used to run the test. But in any case, check out what the command returns in r() [if it isn't listed in the help file, check the manual]. Some of these commands return a p-value directly, often as r(p). Some return a z-statistic or something else from which you can then calculate a p-value. In any event, here's pseudocode followed by a modification of your -graph box- command:

    Code:
    wilcoxon_test_command [whatever variables, options]
    local pvalue: display %05.3f =r(p) // IF THERE IS AN r(p)
    
    //  OR local pvalue = formula to calculate p from statistics in r()
    // local pvalue: display %05.3f `pvalue'
    
    graph box tfg_b, over(breslow) by(type) ytitle(TFG Beta) nooutsides note("p = `pvalue'") ///
        box(1,bcolor(dkorange)) graphregion(color(white))
    graph export tfg_b_breslow.png, replace
    Note: This will place "p = 0.xxx", with appropriate x numbers in the note on your graph. If you want more or fewer decimal places, or don't care for the leading zero, feel free to change %05.3f to your preferred display format.




    Comment


    • #3
      First, thank you for your prompt answer. The test that i used was the ranksum test, as i see on the help file i got to use the r(z) result. So, i got the pvalue with the formula 2*normprob(-abs(r(z)))
      finally it works perfectly, thank you!!

      Comment


      • #4
        Hi Clyde, i tried the commands that you suggested above. However, i am only getting 'p= '. No value is appearing. Would you please suggest how i may fix this?. Thank you

        Comment


        • #5
          The code I show in #2 is really just a scheme for writing code: it leaves things to be filled in. So perhaps you have not done that part correctly. Without seeing your actual code and some example data to run it on (use -dataex- for that), I can't troubleshoot it.

          If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

          Comment

          Working...
          X