Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Re: Plotting regression coefficients


From   Roger Newson <r.newson@imperial.ac.uk>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Re: Plotting regression coefficients
Date   Wed, 2 Jun 2010 13:01:33 +0100

Yes, there is. The -parmest- package has a -stars()- option, allowing the user to generate a string variable containing the stars for the P-value. And -eclplot- has an -addplot()- option, allowing the user to add the stars to the plot as a superimposed additional plot.

So, if we wanted 1 star for P-values at or below 0.05, 2 stars for P-values at or below 0.01, and 3 stars for P-values at or below 0.001, and we wanted the stars to be just above the upper confidence limits, then Martin's code might be revised to read:

*************
clear*
set obs 10000
//get Roger`s -parmest-
capt which parmest
if _rc ssc inst parmest
gen personid=_n
gen bmi0 = rnormal()
gen bmi4 = rnormal()
gen bmi6 = rnormal()
gen bmi8 = rnormal()
gen gluc = 1+.3*bmi0-.2*bmi4-.1*bmi6+.5*bmi8+rnormal(0,10)
la var gluc "2-h glucose concentration"
la var bmi0 "BMI at birth"
la var bmi4 "BMI at age 4"
la var bmi6 "BMI at age 6"
la var bmi8 "BMI at age 8"
reshape long bmi, i(personid) j(age)
qui parmby "regr gluc bmi",by(age) saving(myfile, replace ///
  stars(0.05 0.01 0.001)
u myfile, clear
keep if parm=="bmi"
l age estimate min95 max95 p, sepby(age) noo

eclplot estimate min95 max95 age, eplottype(scatter) ///
  rplottype(rcap) supby(parm ,) estopts( sort ) ciopts( ) ///
  addplot(scatter max95 age, msym(none) mlab(stars) mlabpos(12))

*************

I hope this helps.

Best wishes

Roger


Roger B Newson BSc MSc DPhil
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton Campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
UNITED KINGDOM
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Email: r.newson@imperial.ac.uk
Web page: http://www.imperial.ac.uk/nhli/r.newson/
Departmental Web page:
http://www1.imperial.ac.uk/medicine/about/divisions/nhli/respiration/popgenetics/reph/

Opinions expressed are those of the author, not of the institution.

On 02/06/2010 12:47, Miranda Kim wrote:
I wonder is there a way of plotting stars that represent the significance of the respective p-value above each regression coefficient (95%CI), in the eclplot generated by Martin's code below?
Many thanks,
Miranda
*************
clear*
set obs 10000
//get Roger`s -parmest-
capt which parmest
if _rc ssc inst parmest
gen personid=_n
gen bmi0 = rnormal()
gen bmi4 = rnormal()
gen bmi6 = rnormal()
gen bmi8 = rnormal()
gen gluc = 1+.3*bmi0-.2*bmi4-.1*bmi6+.5*bmi8+rnormal(0,10)
la var gluc "2-h glucose concentration"
la var bmi0 "BMI at birth"
la var bmi4 "BMI at age 4"
la var bmi6 "BMI at age 6"
la var bmi8 "BMI at age 8"
reshape long bmi, i(personid) j(age)
qui parmby "regr gluc bmi",by(age) saving(myfile, replace)
u myfile, clear
keep if parm=="bmi"
l age estimate min95 max95 p, sepby(age) noo

eclplot estimate min95 max95 age, /* */ eplottype(scatter) rplottype(rcap) /* */ supby(parm ,) estopts( sort ) ciopts( )
*************
Martin Weiss wrote:
<>  You are more than welcome!

For the y-line, just add
*************
yline(0, lpattern(dash_dot) style(default) )
*************
to the -eclplot- call. Change the pattern according to your taste (-help
linepatternstyle-)...

HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Miranda Kim
Gesendet: Mittwoch, 20. Januar 2010 10:56
An: statalist@hsphsun2.harvard.edu
Betreff: Re: AW: st: AW: Plotting regression coefficients
Thank you so much Martin, this looks fantastic!
I had never used either parmest or eclplot!
Do you know how I could add a horizontal dotted line at zero?
Best wishes,
Miranda
Martin Weiss wrote:
<>
Here is a solution employing -ssc d parmest- and -reshape-

*************
clear*
set obs 10000
//get Roger`s -parmest-
capt which parmest
if _rc ssc inst parmest
gen personid=_n
gen bmi0 = rnormal()
gen bmi4 = rnormal()
gen bmi6 = rnormal()
gen bmi8 = rnormal()
gen gluc = 1+.3*bmi0-.2*bmi4-.1*bmi6+.5*bmi8+rnormal(0,10)
la var gluc "2-h glucose concentration"
la var bmi0 "BMI at birth"
la var bmi4 "BMI at age 4"
la var bmi6 "BMI at age 6"
la var bmi8 "BMI at age 8"
reshape long bmi, i(personid) j(age)
qui parmby "regr gluc bmi",by(age) saving(myfile, replace)
u myfile, clear
keep if parm=="bmi"
l age estimate min95 max95 p, sepby(age) noo

eclplot estimate min95 max95 age, /* */ eplottype(scatter) rplottype(rcap) /* */ supby(parm ,) estopts( sort ) ciopts( )
*************

HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Martin Weiss
Gesendet: Mittwoch, 20. Januar 2010 10:35
An: statalist@hsphsun2.harvard.edu
Betreff: AW: st: AW: Plotting regression coefficients

<>
Sounds like a case for a -reshape long- to me, before you even
-regress-...

HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Miranda Kim
Gesendet: Mittwoch, 20. Januar 2010 10:26
An: statalist@hsphsun2.harvard.edu
Betreff: Re: st: AW: Plotting regression coefficients
Thank you Martin, Alan and Nick for your replies,
I'm sorry I didn't give enough description of my dataset. As it is currently structured I have each line (observation) corresponding to a distinct person. I have five variables for each individual (five columns in my dataset):
gluc = 2-h glucose concentration
bmi0 = BMI at birth
bmi4 = BMI at age 4
bmi6 = BMI at age 6
bmi8 = BMI at age 8
I could simply type
reg gluc bmi0
reg gluc bmi4
etc.
saving the regression coefficients (and CIs) along the way, and then plotting them.
But I didn't know if this was a long-winded way of going about it.
Many thanks
Miranda
Blood glucose vs. BMI at birth
Blood glucose vs. BMI at age 4
Blood glucose vs. BMI at age 6
Blood glucose vs. BMI at age 8

Martin Weiss wrote:
<>
Apart from -statsby-, -ssc d parmest- by Roger Newson may be useful for
you...

HTH
Martin

-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Miranda Kim
Gesendet: Dienstag, 19. Januar 2010 18:03
An: statalist@hsphsun2.harvard.edu
Betreff: st: Plotting regression coefficients
I am using Stata v11

I would like to run four regressions of the same outcome variable on a given predictor at four different timepoints. For example:
Blood glucose vs. BMI at birth
Blood glucose vs. BMI at age 4
Blood glucose vs. BMI at age 6
Blood glucose vs. BMI at age 8

Then I would like to plot the four regression coefficients and respective confidence intervals on the same graph, with time as the
x-axis.
I wonder what the most straightforward way of producing such a plot would be.
Any suggestions would be of great help.
Many thanks,
Miranda

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/ 		 	   		
_________________________________________________________________
http://clk.atdmt.com/UKM/go/195013117/direct/01/
We want to hear all your funny, exciting and crazy Hotmail stories. Tell us now
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index