Announcement

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

  • Plot for a multiple linear regression analysis

    Hey
    I would like to make a scatter plot with p-value and r^2 included for a multiple linear regression. I have a continous dependent variable, a continous independent variable and a categorial independent variable (gender).
    Earlier Benjamin Chartock, Nick Cox and Roman Mostazir helped me with a similar scatterplot for a simple linear regression (see under this section), and I imagine a scatterplot in the same style, but with a line for men and women separately in the same graph.

    reg y-variable x-variable
    test _b[x-variable]=0

    mat b = e(b)
    local constant : display %4.3f = b[1,2]
    display `constant'
    local x : display %4.3f = b[1,1]
    local r2 : display %5.4f = e(r2)

    local hats : display _skip(1) "̂" _skip(26) "̂"
    local heads_a "y="
    local heads_b "x"

    local p_value : display %5.4f = r(p)


    twoway (scatter y-variable x-variable) || ///
    (lfit y-variable x-variable, ///
    caption("{subscript:`hats'}" ///
    "{superscript:`heads_a' `constant'+}{superscript:`x'`heads_b'}" ///
    "{superscript:R-squared=`r2'}" ///
    "{superscript:P-value : `p_value'}", justification(left) position(3)) legend(off))



    I hope some of you can help.
    Thank you, Kristine

  • #2
    The code isn't related to the question and we can't run it any way as you give no data example.

    The technique here may help. Decoration with summary statistics depends on technique you already know about.

    Code:
    sysuse auto, clear
    gen gpm = 1000/mpg
    regress gpm weight foreign
    
    predict predicted
    separate predicted, by(foreign) 
    separate gpm, by(foreign) veryshortlabel
    
    scatter gpm? weight, ms(Oh +) mcolor(blue orange) ///
    || line predicted? weight, lcolor(blue orange)    ///
    ytitle(Gallons per 1000 miles) sort               ///
    legend(order(2 1) pos(10) ring(0) col(1))
    Click image for larger version

Name:	twoscatter.png
Views:	1
Size:	11.0 KB
ID:	1341738

    Comment


    • #3
      Here is a similar solution:

      Code:
      sysuse auto, clear
      gen gpm = 1000/mpg
      regress gpm weight i.foreign
      
      margins foreign, at(weight=(1760(40)4840))
      
      #delimit ;
      marginsplot, noci recast(line) plotopts(lw(thick))
         addplot((scatter gpm weight if foreign==0, mc(navy))
                 (scatter gpm weight if foreign==1, mc(maroon)))
         legend(off);
      #delimit cr
      Click image for larger version

Name:	Graph.png
Views:	0
Size:	0
ID:	1341760

      Comment


      • #4
        Alan: That's a very helpful example.

        I'm often guilty of tending to use my own programs or re-creating graphs from first principles and I do tend to neglect marginsplot. The graph is clearly similar in broad terms to mine.

        I find the automated (not Alan-produced) graph title "Adjusted predictions of foreign" disconcerting when foreign is a predictor.

        Comment

        Working...
        X