I have a feeling this will be a quick fix, given that I started coding two weeks ago. I am try to run a statistical test - a Mantel, looking for a correlation between two distance matrices - in Python, by using a function(?) that has already been written in R, via Rpy2. The R module is "ade4" and it contains "mantel.rtest"
from rpy2 import robjects
import rpy2.robjects as robjects
robjects.r('library(ade4)')
**EDIT** rmantel = robjects.r("mantel.rtest")
for i in windownA:
M1 = asmatrix(identityA[i]).reshape(14,14)
for j in windownB:
M2 = asmatrix(identityB[j]).reshape(14,14)
**EDIT** result = rmantel (M1, M2, nrepet = 9999)
print result
print ' '
EDIT: this now works! "This returns the error: "AttributeError: 'R' object has no attribute 'mantel'" which leads me to believe that the object being called here is truncated at the "." (i.e. "mantel" versus the full "mantel.rtest"). I tried reassigning the "mantel.rtest" as an object without a "." ex) rmantel = "mantel.rtest" and substituting that result = robjects.r.rmantel (M1, M2, nrepet = 9999) only to receive the error: "AttributeError: 'R' object has no attribute 'rmantel'" - so that did not work. Any thoughts as to how I can get around this issue?"
New Issue: The Mantel test require data in "dist" format, so when I run the edited code, I get the following error "RRuntimeError: Error in function (m1, m2, nrepet = 99) : Object of class 'dist' expected"
So I tried to convert the file to that format and when I print the results, it's the bottom half of a matrix of the correct size, but all fields are filled with "NA"
robjects.r('library(ade4)')
rmantel = robjects.r("mantel.rtest")
distify = robjects.r("dist")
for i in windownA:
M1 = asmatrix(identityA[i]).reshape(14,14)
print distify(M1)
MOne = distify(M1, 14)
for j in windownB:
M2 = asmatrix(identityB[j]).reshape(14,14)
print distify(M2)
MTwo = distify(M2, 14)
result = rmantel(M1, M2, nrepet = 9999)
print result
print ' '
i get"
1 2 3 4 5 6 7 8 9 10 11 12 13
2 NA
3 NA NA
4 NA NA NA
5 NA NA NA NA
6 NA NA NA NA NA
7 NA NA NA NA NA NA
8 NA NA NA NA NA NA NA
9 NA NA NA NA NA NA NA NA
10 NA NA NA NA NA NA NA NA NA
11 NA NA NA NA NA NA NA NA NA NA
12 NA NA NA NA NA NA NA NA NA NA NA
13 NA NA NA NA NA NA NA NA NA NA NA NA
14 NA NA NA NA NA NA NA NA NA NA NA NA NA