Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: Re: st: least products regression


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: Re: st: least products regression
Date   Wed, 23 Aug 2006 14:07:55 +0100

The keywords for -concord- at present are 

statistics concordance correlations coefficients lin graphs graphics
limits agreement measurements comparisons

I am not sure about adding "reduced major axis", partly 
because there are so many other synonyms (witness "least 
products") and partly because someone will then complain 
that it does not support the same wholeheartedly. 

More positively, I already did what Joseph asks, but I failed 
to make the program public.

. sysuse auto, clear  

. sdline mpg weight

Slope:        -0.007
Intercept:    43.774

<know that a graph appeared> 

. ret li

scalars:
             r(slope) =  -.0074440955951873
               r(xsd) =  777.1935671373662
             r(xmean) =  3019.45945945946
               r(ysd) =  5.785503209735141
             r(ymean) =  21.2972972972973
                 r(N) =  74

Here's the code. I'll ask Kit Baum to put this up on SSC 
in due course. 

*! 2.1.0 NJC 22 Aug 2006
* 2.0.0 NJC 3 Aug 2004
* 1.0.0 NJC 26 Nov 1996
program sdline, rclass
	version 8   
	syntax varlist(numeric min=2 max=2) [if] [in] ///
	[, GENerate(str) SORT NOGRAPH PLOT(str asis) ADDPLOT(str asis) * ]

	quietly { 
		marksample touse 
		count if `touse' 
		if r(N) == 0 error 2000 
		if r(N) == 1 error 2001 
		local N = r(N) 

		tokenize `varlist' 
		args y x 
		tempvar ysdl
		tempname meany meanx sdy sdx slope 

		corr `y' `x' if `touse'
		local sign = sign(r(rho))
		
		su `y' if `touse'
		scalar `meany' = r(mean)
		scalar `sdy' = r(sd)
		su `x' if `touse' 
		scalar `meanx' = r(mean)
		scalar `sdx' = r(sd)
		scalar `slope' = `sign' * (`sdy' / `sdx')
		gen `ysdl' = `meany' +  `slope' * (`x' - `meanx') if `touse' 

		local yttl `"`: variable label `y''"'
		if `"`yttl'"' == "" local yttl "`y'" 

		label var `ysdl' "SD line" 
	} 	

	di 
	di as txt "Slope:     " as res %9.3f `slope'  
	di as txt "Intercept: " as res %9.3f `meany' - `meanx' * `slope' 

	if "`nograph'" == "" {
		twoway scatter `y' `ysdl' `x' `if' `in', ///
		ms(oh none) connect(none l) sort yti(`"`yttl'"') `options' ///
		|| `plot'   ///
		|| `addplot' 
	}

	if "`generate'" != "" {
		confirm new variable `generate'
		gen `generate' = `ysdl' `if' `in'
	}

	return scalar N     = `N'
	return scalar ymean =  `meany'
	return scalar ysd   = `sdy'
	return scalar xmean = `meanx'
	return scalar xsd   = `sdx'
	return scalar slope = `slope'
end

That said, the best graphical aid in my view for Richard's problem 
remains the plot of differences 
vs means. It is rather odd that this is called a Bland-Altman 
plot, except that it seems that this confers instant recognition
among (at least some) medical statisticians. Bland and Altman, 
both long-time Stata users, deserve all the esteem they have
received for their persistent work and lucid expositions on this
problem, but they hardly invented this plot. 

Yet another discussion is in 

2006. Assessing agreement of measurements and predictions in 
geomorphology. Geomorphology 76, 332-346. 

in which the examples should not prove too esoteric.

Nick 
n.j.cox@durham.ac.uk 

Joseph Coveney
 
> Nick Cox wrote:
> 
> The command -concord- by Thomas Steichen and myself
> includes a fitting of this line, which is known by
> many, many different names. We do use the term
> "reduced major axis", but that is evidently not
> among the keywords used to code the command.
> 
> So far, the publication history of this program
> in the STB and SJ includes 8 episodes: some of them are
> just small fixes or flourishes, but others are more substantial.
> 
> [snip]
> 
> My rather predictable bias, here and elsewhere, is
> that you learn more from graphics than by treating
> the problem as inferential. See also
> 
> Graphing agreement and disagreement.  Stata Journal 4:
> 329--349 (2004)
> 
> --------------------------------------------------------------
> ------------------
> 
> So much for my powers of recall.
> 
> Nick's point about graphing and inference is well taken:  run 
> the do-file
> attached to my post and examine confidence intervals & 
> P-values for the
> reduced major axis slope from both -jackknife- and 
> -bootstrap-; hold that
> thought and now run -concord- on the dataset and take a look at the
> scatterplot and reduced major axis line.
> 
> It might be worth an st0015_4 episode to add the ability of -concord-
> to -return- the reduced major axis regression coefficients in 
> scalars or a
> matrix, and to add some keywords so that it's more visible to the
> memory-impaired.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index