Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 925763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:34:15+00:00 2026-05-15T19:34:15+00:00

I have a feeling this will be a quick fix, given that I started

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:34:15+00:00Added an answer on May 15, 2026 at 7:34 pm

    Try robjects.r['mantel.rtest']:

    In [1]: %cpaste
    Pasting code; enter '--' alone on the line to stop.
    :from rpy2 import robjects
    import rpy2.robjects as robjects
    robjects.r('library(ade4)')
    ::::::--
    
    In [3]: robjects.r['mantel.rtest']
    Out[5]: <RFunction - Python:0xa2aac0c / R:0xac9ec04>
    

    This also works:

    In [8]: robjects.r('mantel.rtest')
    Out[8]: <RFunction - Python:0xaf7042c / R:0xac9ec04>
    

    Edit (for the New Issue):
    Since you say mantel.rtest requires data in dist format, I suppose M1 and M2 should be in dist format. But M1 and M2 appear to be numpy arrays. On the other hand, MOne and MTwo look like they might be in dist format.

    So perhaps try

    result = rmantel(MOne, MTwo, nrepet = 9999)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a really strong feeling that this question will either be closed or
I have a feeling that this query is pretty easy to construct, I just
I somehow have the feeling that modern systems, including runtime libraries, this exception handler
I have a feeling that this probably is not possible using strictly CSS, but,
I have a feeling this will be too wordy, but I'll do my best.
I have a feeling this XML is not valid, can someone please explain why?
I have a feeling this is a stupid question but I can't find the
I'm maintaining a CMS where I have this feeling it was made in the
I have a feeling I'm going about this all wrong. But anyway. I have
I have the feeling the answer to this question is no but I figured

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.