title: Quadratic Assignment Procedure(QAP) in R is producing different results
body: <p>I would like to say thank you in advance for anyone who looks at my question and shares their thoughts and experiences. I am trying to run a quadratic assignment procedure (QAP) on correlations of behaviors between a community of five individuals. I have ten matrices that represent frequencies of behavior between individuals, and I calculated correlations (pearson's r) between pairs of matrices. For example, I found the correlation between matrix 1 and matrix 2, matrix 2 and matrix 3, matrix 3 and matrix 4... and so on. I then wanted to assess the significance of these correlations using the qaptest function from the R package sna. As per the R documentation on qaptest, I placed all of my matrices into an array. I then calculated the QAP p-value between pairs of matrices (matrix 1 and matrix 2, matrix 2 and matrix 3... etc.). However, I noticed that if I changed the number of matrices in the array (for example, if I only placed the first five into the array), the QAP p-values for the first set of matrices changed dramatically. Based on my understanding of arrays and QAP, this should not happen because the removed matrices have nothing to do with running a QAP test on matrix 1 and matrix 2. Has anyone else ran into this problem before? I included my matrices and my script below. </p>
  
  <p>Here are my matrices in a list format (in the code below, this is the step where I made filelist1. The second half of the code only uses matrices 1-5):</p>
  
  <pre><code>[[1]]
    1 2 3 4 5
  1 1 0 0 0 0
  2 5 0 3 5 0
  3 0 0 0 0 0
  4 0 0 0 0 0
  5 2 0 1 0 0
  
  [[2]]
    1 2  3 4 5
  1 0 0  1 0 0
  2 3 6 10 1 2
  3 0 0  0 0 0
  4 0 5  0 0 0
  5 0 0  5 0 0
  
  [[3]]
    1 2 3 4 5
  1 0 1 0 0 0
  2 2 0 5 7 0
  3 0 0 0 0 3
  4 1 0 0 0 0
  5 1 2 2 3 0
  
  [[4]]
    1 2 3 4 5
  1 0 6 0 0 2
  2 2 0 8 5 0
  3 0 5 0 0 0
  4 1 0 0 0 0
  5 0 0 1 3 2
  
  [[5]]
    1 2 3 4 5
  1 0 0 0 0 0
  2 1 0 2 5 1
  3 0 0 0 0 0
  4 1 2 3 0 1
  5 0 3 3 1 0
  
  [[6]]
    1 2 3 4 5
  1 0 0 0 0 0
  2 2 0 3 0 3
  3 0 0 0 0 0
  4 1 0 4 0 0
  5 1 5 7 0 0
  
  [[7]]
    1 2 3 4 5
  1 0 0 0 0 0
  2 2 0 6 0 3
  3 0 0 0 0 0
  4 6 0 4 0 0
  5 1 0 2 0 0
  
  [[8]]
    1 2 3 4 5
  1 0 0 0 1 0
  2 2 0 1 6 0
  3 0 0 0 0 0
  4 0 0 0 0 0
  5 6 0 2 2 0
  
  [[9]]
    1 2 3 4 5
  1 0 0 0 0 0
  2 0 0 2 3 2
  3 0 0 0 0 0
  4 0 0 0 0 0
  5 1 0 2 0 0
  
  [[10]]
    1 2 3 4 5
  1 0 0 0 0 0
  2 1 0 1 1 0
  3 0 0 0 0 0
  4 0 0 0 0 0
  5 6 0 1 2 0
  </code></pre>
  
  <p>This is my R script:</p>
  
  <pre><code># read in all ten of the matrices
  a&lt;-read.csv("test1.csv")
  b&lt;-read.csv("test2.csv")
  c&lt;-read.csv("test3.csv")
  d&lt;-read.csv("test4.csv")
  e&lt;-read.csv("test5.csv")
  f&lt;-read.csv("test6.csv")
  g&lt;-read.csv("test7.csv")
  h&lt;-read.csv("test8.csv")
  i&lt;-read.csv("test9.csv")
  j&lt;-read.csv("test10.csv")
  
  filelist&lt;-list(a,b,c,d,e,f,g,h,i,j) #place files in a list
  filelist1&lt;-lapply(filelist,function(x){
    x&lt;-x[1:5, 2:6] #choose only columns in the matrix
    colnames(x)&lt;-1:5 #rename columns according to identity
    x&lt;-as.matrix(x) #make a matrix
    return(x)
  })
  
  ee&lt;-array(dim=c(5,5,10)) #create an empty array
  
  array&lt;-function(files) {
    names(files) &lt;- c("c1","c2","c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10") #name the matrices
    invisible(lapply(names(files), function(x) assign(x,files[[x]],envir=.GlobalEnv))) #place the matrices in a global environment
    ee[,,1]&lt;-c(c1) #place each matrix in order into the array
    ee[,,2]&lt;-c(c2)
    ee[,,3]&lt;-c(c3)
    ee[,,4]&lt;-c(c4)
    ee[,,5]&lt;-c(c5)
    ee[,,6]&lt;-c(c6)
    ee[,,7]&lt;-c(c7)
    ee[,,8]&lt;-c(c8)
    ee[,,9]&lt;-c(c9)
    ee[,,10]&lt;-c(c10)
    return(ee) #return the completely filled in array
  }
  
  a.array&lt;-array(filelist1) # apply the function to the list of matrices
  
  q1.2&lt;-qaptest(a.array,gcor,g1=1,g2=2) #run the qaptest funtion
  #a.array is the array with the matrices,gcor tells the function that we want a correlation
  #g1=1 and g2=2 indicates that the qap analysis should be run between the first and second matrices in the array.
    summary.qaptest(q1.2) #provides a summary of the qap results
  #in this case, the p-value is roughly: p(f(perm) &gt;= f(d)): 0.176 
  
  ############ If I take out the last five matrices, the q1.2 p-value changes dramatically
  #first clear the memory or R will not create another blank array
  rm(list = ls())
  
  a&lt;-read.csv("test1.csv") #read in all five files
  b&lt;-read.csv("test2.csv")
  c&lt;-read.csv("test3.csv")
  d&lt;-read.csv("test4.csv")
  e&lt;-read.csv("test5.csv")
  
  filelist&lt;-list(a,b,c,d,e) #create a list of the files
  filelist1&lt;-lapply(filelist,function(x){
    x&lt;-x[1:5, 2:6] #include only the matrix
    colnames(x)&lt;-1:5 #rename the columns
    x&lt;-as.matrix(x) #make it a matrix
    return(x)
  })
  
  ee&lt;-array(dim=c(5,5,5)) #this time the array only has five slots
  
  array&lt;-function(files) {
    names(files) &lt;- c("c1","c2","c3", "c4", "c5")
    invisible(lapply(names(files), function(x) assign(x,files[[x]],envir=.GlobalEnv)))
    ee[,,1]&lt;-c(c1)
    ee[,,2]&lt;-c(c2)
    ee[,,3]&lt;-c(c3)
    ee[,,4]&lt;-c(c4)
    ee[,,5]&lt;-c(c5)
    return(ee)
  }
  
  a.array&lt;-array(filelist1)
  
  q1.2&lt;-qaptest(a.array,gcor,g1=1,g2=2) 
  #in this case, the p-value is roughly: p(f(perm) &gt;= f(d)): 0.804 
    summary.qaptest(q1.2)
  </code></pre>
  
  <p>I cannot think of a reason why the p-values would be so different when I am analyzing the exact same pair of matrices. The only difference is the number of additional matrices placed in the array. Has anyone else experienced this issue?</p>
  
  <p>Thank you!</p>