[R] How to get multiple Correlation Coefficients

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[R] How to get multiple Correlation Coefficients

Kum-Hoe Hwang
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 : [hidden email]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: [R] How to get multiple Correlation Coefficients

David Barron-2
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 <[hidden email]> 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 : [hidden email]
>
> ______________________________________________
> [hidden email] 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: [R] How to get multiple Correlation Coefficients

David Barron-2
Oh, and of course you need to use an explicit print inside a for loop.
 So, the line would be:

>  print( polychor(sdi[,i], sdi[,j]))

On 19/10/06, David Barron <[hidden email]> wrote:

> 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 <[hidden email]> 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 : [hidden email]
> >
> > ______________________________________________
> > [hidden email] 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
>


--
=================================
David Barron
Said Business School
University of Oxford
Park End Street
Oxford OX1 1HP

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: [R] How to get multiple Correlation Coefficients

Fox, John
In reply to this post by David Barron-2
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: [hidden email]
> [mailto:[hidden email]] 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 <[hidden email]> 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 : [hidden email]
> >
> > ______________________________________________
> > [hidden email] 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
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.