Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Sorry, I am not enough educated to catch up your goals about checking the correlation efficient between two covariance matrices, but I tried to apprehend your code per se.</p> <p>If I am right, you are making up 10.000 different matrices from the same matrix (<code>mat2</code>) by reordering the cells all round, and recomputing the correlation between the covariance matrix of <code>mat1</code> and the covariance matrix of the resampled array. Those are stored in the <code>statSim</code> variable.</p> <p>You said the original correaltion efficient was high (<code>statObs</code>), but the maximum of <code>statSim</code> was low, which is strange. I think the problem is with your result list:</p> <pre><code>list( obs = statObs , sumFit = sum(statSim &gt; statObs)/numR) </code></pre> <p>Where you return the original correaltion coefficient (<code>obs</code>), but not the written maximum with <code>sumFit</code>. There you might use eg. <code>max(statSim)</code>. I see the point in returning <code>sumFit</code> for checking if the resampling did any improvement to the correlation efficient, but based on your code, I see no problem about the theory.</p> <p>Updated function with <code>max</code> of simulated correlation coefficients:</p> <pre><code>resamplerSimAlt &lt;- function(mat1, mat2, numR, graph = FALSE) { statSim &lt;- numeric(numR) mat1vcv &lt;- cov(mat1) mat2vcvT &lt;- cov(mat2) ltM1 &lt;- mat1vcv[col(mat1vcv) &lt;= row(mat1vcv)] ltM2T &lt;- mat2vcvT[col(mat2vcvT) &lt;= row(mat2vcvT)] statObs &lt;- cor(ltM1, ltM2T) indice &lt;- c(1:length(mat2)) resamplesIndices &lt;- lapply(1:numR, function(i) sample(indice, replace = F)) for (i in 1:numR) { ss &lt;- mat2[sample(resamplesIndices[[i]])] ss &lt;- matrix(ss, nrow = dim(mat2)[[1]], ncol = dim(mat2)[[2]]) mat2ss &lt;- cov(ss) ltM2ss &lt;- mat2ss[col(mat2ss) &lt;= row(mat2ss)] statSim[i] &lt;- cor(ltM1, ltM2ss) } if (graph == TRUE) { plot(1, main = "resampled data density distribution", xlim = c(0, statObs+0.1), ylim = c(0,14)) points(density(statSim), type="l", lwd=2) abline(v = statObs) text(10, 10, "observed corelation = ") } list( obs = statObs , sumFit = sum(statSim &gt; statObs)/numR, max=max(statSim)) } </code></pre> <p>What I had run:</p> <pre><code>&gt; mat1 &lt;- matrix(runif(25),5,5) &gt; mat2 &lt;- mat1+0.2 &gt; resamplerSimAlt(mat1, mat2, 10000) $obs [1] 1 $sumFit [1] 0 $max [1] 0.94463 </code></pre> <p>And with random <code>mat2</code>:</p> <pre><code>&gt; mat2 &lt;- matrix(runif(25),5,5) &gt; resamplerSimAlt(mat1, mat2, 10000) $obs [1] 0.31144 $sumFit [1] 0.9124 $max [1] 0.9231 </code></pre> <p>My answer might not be a real answer. If that would be the case, please give more details about the problem :)</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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