[R] How to get multiple Correlation Coefficients
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 : [EMAIL PROTECTED] __ R-help@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.
Re: [R] How to get multiple Correlation Coefficients
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 [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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 : [EMAIL PROTECTED] __ R-help@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 -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP __ R-help@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.
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 [EMAIL PROTECTED] 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 : [EMAIL PROTECTED] __ R-help@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@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.
Re: [R] How to get multiple Correlation Coefficients
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: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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 : [EMAIL PROTECTED] __ R-help@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@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. __ R-help@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.