Statalist The Stata Listserver


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

RE: st: Joint -pwcorr- and -spearman-


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Joint -pwcorr- and -spearman-
Date   Wed, 23 Aug 2006 13:59:25 +0100

You asked the same question in previous postings, 
I believe, which is why I did not spell out the 
details. Or at least I figured that your previous 
interest in -makematrix- showed that you were 
aware of that. 

By the way, I assume your interest in -pwcorr- 
rather than -correlate- shows an interest in 
getting correlations based on the largest possible
number of values for each pair of variables. 
That is _not_ what you get from the procedure 
below if values are missing for some variables 
but not others. 

Regardless, -makematrix- from SSC can calculate 
either matrix. You just need to use the -listwise- 
option if and only if that is what you want. 

An alternative for Spearman is to rank all
the variables first, and then feed the ranked 
variables to the procedure you outline. But 
again that is not the thing to use if you want 
correlations based on the largest possible
number of values for each pair of variables
_and_ values are missing for some variables 
but not others. 

By the way, there is no way to get P-values 
into the same matrix. A matrix is a two-dimensional 
array in which each entry is a single number. 
Therefore, what you can get is a _separate_
matrix of P-values. 

I find it difficult to understand why people 
want to see a matrix of P-values when they 
have a correlation matrix too. If the argument 
is that you need to know whether the correlation 
is significant (significantly different from
zero) at conventional levels, well, almost any 
correlation satisfies that unless the sample size
is very small. If the argument is that the P-value
provides a measure of the strength of the relationship, 
well, that is what the correlation does, and a
lot better too. What is more, the correlation 
tends to be well-behaved by virtue 
of Cauchy-Schwarz, but the P-value is hypersensitive 
to deviations from bivariate normality. You 
still need to check for outliers etc. but that 
is standard. 

Nick 
[email protected] 

Herve STOLOWY
 
> Dear Nick:
> 
> Thank you for your help. I tried what you suggest but I face 
> difficulties at the first two steps (given my insufficient 
> knowledge of matrices). 
> 
> Before contacting you, I tried to solve the issue with the 
> Stata manual.
> 
> 1. Get pairwise correlation matrix, say -pearson-.
> 
> I did the following:
> 
> matrix accum R =  var1 var2,nocons dev
> matrix R = corr(R)
> matrix list R
> 
> I checked that I get the correct coefficients (comparing with 
> -pwcorr-).
> 
> Is this method correct? 
> With -pwcorr-, I can get the p-value. Is there a way to also 
> include the p-value in the matrix?
> 
> 2. Get pairwise Spearman correlation matrix, say -spearman-.
> 
> I did not find a solution. I guess there must be something 
> equivalent to corr(R) for Spearman. 
 
[email protected] 

> Despite your question, doing this synchronously
> does not seem especially important to what you
> want here. I suppose you could get two
> Statas working more or less in unison, but they
> would still need to talk to each other.
> 
> A recipe for the hybrid matrix is
> 
> 1. Get pairwise correlation matrix, say -pearson-.
> 
> 2. Get pairwise Spearman correlation matrix, say -spearman-.
> 
> 3. Loop over rows and columns one side of the principal
> diagonal:
> 
> matrix both = pearson
> local I = rowsof(pearson)
> forval i = 1/`I' {
> 	local j1 = `i' + 1
> 	forval j = `j1'/`I' {
> 		matrix both[`i',`j'] = spearman[`i',`j']
> 	}
> }
> 
> 4.
> 
> matrix list both
> 
> As each matrix is square, either the number of rows or
> the number of columns suffices to indicate the matrix size.
> 
> There are no doubt cuter ways to do it, especially in Mata, 
> but this works.
> 
> I guess you want this as a compact display, not for further analysis.
 
> Herve STOLOWY
> 
> Do you know if there is a possibility to run -pwcorr- and -spearman- 
> jointly (i.e., on the same variables at the same time) in 
> order to get 
> the results in only one matrix: with the -pwcorr- results in 
> the lower 
> left triangle and the -spearman- results in the upper right 
> triangle (or 
> the reverse presentation)?

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index