[R] How to get multiple Correlation Coefficients

John Fox jfox at mcmaster.ca
Thu Oct 19 15:20:00 CEST 2006


Dear David and Kum-Hoe Hwang,

David has pointed out to me that polychor() will incorrectly return a
polychoric correlation when its arguments are length-one character vectors:

> polychor("a", "b")
[1] 0.1055909

Actually, the problem is more general, since polychor() will erroneously
compute a polychoric correlation in any event when the contingency table for
the data contains only one cell:

> polychor(1, 2)
[1] 0.1055909
> polychor(rep("a", 100), rep("b", 100))
[1] 0.1055909

I've fixed this bug so that polychor() and polyserial() report an error when
a categorical variable has just one level. I'll upload the new version of
the package to CRAN shortly.

Regards,
 John

--------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario
Canada L8S 4M4
905-525-9140x23604
http://socserv.mcmaster.ca/jfox 
-------------------------------- 

> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch 
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of David Barron
> Sent: Thursday, October 19, 2006 5:54 AM
> To: Kum-Hoe Hwang; r-help
> Subject: Re: [R] How to get multiple Correlation Coefficients
> 
> The problem is that in the expression  polychor(vars[i], 
> vars[j]), vars[i] and vars[j] refer to the names of the 
> variables, not the variables themselves.  So, use sdi[,i] and 
> sdi[,j] instead.
> 
> On 19/10/06, Kum-Hoe Hwang <phdhwang at gmail.com> wrote:
> > Hi
> >
> > I have used a polycor package for categorical correlation 
> coefficients.
> > I run the following script. But there were no results.
> >
> > Could you tell me how to correct the script?
> >
> > Thanks in advance,
> >
> > vars <- names(sdi)
> > for (i in 1:length(vars)) {
> > for (j in 1:length(vars)) {
> >   paste(vars[i]," and ", vars[j])
> >   polychor(vars[i], vars[j])
> >   # corr
> > }
> > }
> >
> >
> >
> > --
> > Kum-Hoe Hwang, Ph.D.Phone : 82-31-250-3516Email : phdhwang at gmail.com
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide 
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
> 
> 
> --
> =================================
> David Barron
> Said Business School
> University of Oxford
> Park End Street
> Oxford OX1 1HP
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list