Note that there are some explanatory texts on larger screens.

plurals
  1. POSpearman correlation loop in R
    primarykey
    data
    text
    <p>A previous post explained how to do a Chi-squared loop in R on all your data-pairs: <a href="https://stackoverflow.com/questions/7382039/chi-square-analysis-using-for-loop-in-r">Chi Square Analysis using for loop in R</a>. I wanted to use this code to do the same thing for a Spearman correlation.</p> <p>I've already tried altering a few of the variables and I was able to calculate the pearson correlation variables using this code:</p> <pre><code>library(plyr) combos &lt;- combn(ncol(fullngodata),2) adply(combos, 2, function(x) { test &lt;- cor.test(fullngodata[, x[1]], fullngodata[, x[2]]) out &lt;- data.frame("Row" = colnames(fullngodata)[x[1]] , "Column" = colnames(fullngodata[x[2]]) , "cor" = round(test$statistic,3) , "df"= test$parameter , "p.value" = round(test$p.value, 3) ) return(out) }) </code></pre> <p>But since I work with data on an ordinal scale, I need to use the Spearman correlation.</p> <p>I thought I could get this data by just adding the method="spearman" command but this does not seem to work. If I use the code:</p> <pre><code>library(plyr) combos &lt;- combn(ncol(fullngodata),2) adply(combos, 2, function(x) { test &lt;- cor.test(fullngodata[, x[1]], fullngodata[, x[2]], method="spearman") out &lt;- data.frame("Row" = colnames(fullngodata)[x[1]] , "Column" = colnames(fullngodata[x[2]]) , "Chi.Square" = round(test$statistic,3) , "df"= test$parameter , "p.value" = round(test$p.value, 3) ) return(out) }) </code></pre> <p>I get the response:</p> <pre><code>Error in data.frame(Row = colnames(fullngodata)[x[1]], Column = colnames(fullngodata[x[2]]), : arguments imply differing number of rows: 1, 0 In addition: Warning message: In cor.test.default(fullngodata[, x[1]], fullngodata[, x[2]], method = "spearman") : Cannot compute exact p-values with ties </code></pre> <p>what am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload