Announcement

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

  • Horizontal mean and standard deviation line on Bland Altman Plot

    Hi all,

    I used the code

    Code:
    twoway (scatter difference averagesys), by (Group)
    What do you I need to add to the code to include a horizontal line for the mean and the standard deviation

    Any help will be much appreaciated


  • #2
    Mean and standard deviation of what? And do you mean the overall mean and sd, or does each Group get its own? Also, the standard deviation may well be completely off what would otherwise be the scale of the graph. Did you mean the mean + 1 sd, or something like that?

    Also, when asking for help with code, it is best to give example data to work with. Use the -dataex- command to do that. If you are running version 17, 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


    • #3
      Thank you very much for your reply. Each group gets its own mean and +1.96SD

      I will look into how to use data to be more clear when asking for help next time

      Comment


      • #4
        Since you don't show example data, I'll illustrate the approach with the auto.dta dataset. In this code, rep78 is the group variable, and mpg and price correspond to difference and averagesys, respectively.

        Code:
        sysuse auto, clear
        
        local graphs
        levelsof rep78, local(reps)
        foreach r of local reps {
            summ mpg if rep78 == `r'
            local mean`r' = r(mean)
            local upper`r' = r(mean) + 1.96*`r(sd)'
            graph twoway scatter mpg price if rep78 == `r', yline(`mean`r'' `upper`r'') ///
                name(rep`r', replace) title("rep78 = `r'")
            local graphs `graphs' rep`r'
        }
        
        graph combine `graphs'

        Comment


        • #5
          Thank you very much this worked!

          Comment

          Working...
          X