[R] Using the mantel test in Ape Package

Sarah Goslee sarah.goslee at gmail.com
Thu Mar 15 16:47:35 CET 2012


Hi,

You didn't copy the main r-help list on this email, so I've added them back it.

Beyond that, I don't see anything grossly wrong. You don't provide
enough information to reproduce the problem: mantel.test() works with
the 7x7 parts you provided.

So you'll need to provide a small reproducible example, ideally using
dput(), and also the output of sessionInfo() for your system.

Sarah

On Thu, Mar 15, 2012 at 11:14 AM, Dorothea Hill
<dorothea.hill at zoo.ox.ac.uk> wrote:
> Hello,
>
> Sorry for not providing sufficient information! I am an R beginner! I wonder if it might be something to do with decimal points or if I have accidently altered a value in one of the cells?
>
> The results of str() and dim() are below:
>
>> str(Geo_matrix)
>  num [1:54, 1:54] 0 249 249 217 123 ...
>  - attr(*, "dimnames")=List of 2
>  ..$ : chr [1:54] "1" "2" "3" "4" ...
>  ..$ : chr [1:54] "V1" "V2" "V3" "V4" ...
>> str(Gen_matrix)
>  num [1:54, 1:54] 0 111 118 552 322 125 313 134 212 189 ...
>  - attr(*, "dimnames")=List of 2
>  ..$ : chr [1:54] "1" "2" "3" "4" ...
>  ..$ : chr [1:54] "V1" "V2" "V3" "V4" ...
>> dim(Gen_matrix)
> [1] 54 54
>> dim(Geo_matrix)
> [1] 54 54
>
> The geo_dist csv looks like this before import (this is only the first 7x7):
>
> 0       248.69  248.69  216.76  123.38  123.38  123.38
> 248.69  0       0       34.68   266.02  266.02  266.02
> 248.69  0       0       34.68   266.02  266.02  266.02
> 216.76  34.68   34.68   0       244.59  244.59  244.59
> 123.38  266.02  266.02  244.59  0       0       0
> 123.38  266.02  266.02  244.59  0       0       0
> 123.38  266.02  266.02  244.59  0       0       0
>
> And the gen_dist csv looks like this before import (again first 7x7)
> 0       111     118     552     322     125     313
> 111     0       89      533     288     134     293
> 118     89      0       532     293     131     284
> 552     533     532     0       733     571     730
> 322     288     293     733     0       311     455
> 125     134     131     571     311     0       322
> 313     293     284     730     455     322     0
>
> After import and converting to a matrix, geo_matrix looks like this:
>
>       V1     V2     V3     V4     V5     V6     V7     V8     V9    V10    V11    V12    V13    V14
> 1    0.00 248.69 248.69 216.76 123.38 123.38 123.38 123.38 123.38 123.38 123.38 123.38 123.38 123.38
> 2  248.69   0.00   0.00  34.68 266.02 266.02 266.02 266.02 266.02 266.02 266.02 266.02 266.02 266.02
> 3  248.69   0.00   0.00  34.68 266.02 266.02 266.02 266.02 266.02 266.02 266.02 266.02 266.02 266.02
> 4  216.76  34.68  34.68   0.00 244.59 244.59 244.59 244.59 244.59 244.59 244.59 244.59 244.59 244.59
>
> And gen_matrix looks like this:
>
>    V1  V2  V3   V4   V5  V6   V7  V8  V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21 V22 V23 V24
> 1    0 111 118  552  322 125  313 134 212 189 111  90 158  91 147 108  99 120  88 115 185  81  92 131
> 2  111   0  89  533  288 134  293 116 191 170  96  65 134  68 125 123 122 101  69  94 192  58  71 106
> 3  118  89   0  532  293 131  284 115 188 167  77  70 137  73 110 128 115  82  72  87 209  57  70 117
> 4  552 533 532    0  733 571  730 559 634 593 523 504 575 513 560 564 557 532 506 531 637 497 510 545
> 5  322 288 293  733    0 311  455 288 375 364 274 267 338 266 287 317 319 295 265 290 371 262 271 304
>
> Many thanks.
>
>
>
> -----Original Message-----
> From: Sarah Goslee [mailto:sarah.goslee at gmail.com]
> Sent: 14 March 2012 23:33
> To: Dorothea Hill
> Cc: r-help at r-project.org
> Subject: Re: [R] Using the mantel test in Ape Package
>
> Hi,
>
> On Wed, Mar 14, 2012 at 2:21 PM, Dorothea Hill <dorothea.hill at zoo.ox.ac.uk> wrote:
>> Hi,
>>
>> I am trying to use a mantel test on two distance matrices. The code I have entered for each is:
>>
>> Gen_dists <- read.csv(file.choose(),
>>                                                stringsAsFactors =
>> FALSE,
>>                                                na.strings = c(" "),
>>                                                fill = T,
>>                                                header = FALSE,
>>                  blank.lines.skip = FALSE)
>>
>> Gen_matrix <- as.matrix(Gen_dists)
>>
>> mantel.test(Geo_matrix, Gen_matrix, nperm = 999, graph = T,
>> alternative = "great")
>>
>> I am getting a result but with lots of warning messages :
>> "Warning: non-square matrix"
>>
>> However, my matrices are square!
>
> Not according to R. Somewhere in the import or modification steps they have become unsquare. Since you provide neither a reproducible example nor any description of your matrices -- str() and dim() seem particularly relevant -- we can't possibly tell you where.
>
> Sarah
>


-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list