Thanks Gavin, Jari,

Trying to get the message across more clear, this are the commands I used to 
calculate the distance matrix for fso function. It seems there is a problem 
with 
the dissimilarity matrix attachment; maybe it is not in the right form...
Any suggestion appreciated.

Dragos George
http://webs.uvigo.es/zdragos/

library(fso)
#metals
> MET
      Al   Li       Ti     Mn    Cu    As    Pb
1  20895 76.0 37.50000 543.29 20.11 15.61 26.42
2  22148 84.0 33.33333 591.40 25.08 16.99 28.90
3  27574 93.0 38.11881 628.63 23.48 18.15 29.30
4  25135 87.0 24.77477 853.39 23.57 22.19 30.60
5  23015 83.0 23.50000 706.67 19.74 20.02 28.08
6  22965 91.0 24.24242 637.84 21.44 21.35 29.66
7  24895 87.5 27.00000 646.62 23.01 21.51 31.04
8  21784 87.0 25.00000 618.32 21.37 19.99 29.01
9  17827 80.0 27.40385 581.50 20.11 18.27 28.43
10 17889 83.0 34.34343 651.70 21.96 17.39 30.78
11 16005 72.0 42.66055 554.42 15.94 13.40 22.53
12 17694 80.0 42.85714 629.78 21.52 17.82 29.87
13 21342 78.0 42.57426 708.46 22.73 17.47 32.51
14 18380 76.0 34.00000 692.82 17.90 15.45 26.09
15 13439 62.0 14.95327 544.17 13.07 12.50 20.45
16 15240 64.5 17.50000 590.62 14.72 13.56 23.00
17 16562 72.0 19.02655 605.47 15.81 12.42 21.79
18 19750 86.5 20.50000 559.13 20.89 16.54 29.26
19 21710 88.0 23.00000 666.26 21.41 17.86 29.79
20 17904 78.0 17.50000 791.57 16.77 15.37 27.36
21 15000 72.0 23.52941 552.09 15.54 11.93 22.55
22 17000 75.0 19.04762 531.31 14.51 12.37 24.65
23 18657 85.0 13.72549 548.93 13.68 12.56 20.14
24 15765 86.5 17.50000 571.96 14.66 12.30 22.12
25 15517 72.0 15.21739 495.06 14.44 11.64 22.38
26 16625 72.5 16.50000 460.57 14.50 11.64 21.93
27 17228 72.0 18.81188 483.02 12.43 11.94 19.93
28 20380 77.0 21.63462 561.09 14.72 12.03 21.76
29 19204 74.0 21.84466 596.23 17.29 11.51 29.30
30 15717 64.0 16.66667 563.92 16.05 12.10 22.87
31 19014 71.0 11.21495 528.77 15.47 12.50 21.35
32 18826 83.0 11.60714 498.92 16.72 11.29 25.53
33 17580 64.5 13.00000 499.45 14.07 11.12 19.13

#environmental variables
> CC
   SpringFreezLevel PrecipitDays SnowDays
1          2124.354           95       18
2          2488.462          117       24
3          2391.031          108       17
4          2447.431           91       25
5          2408.462           89        9
6          2444.354           65       26
7          2326.415           77       23
8          2757.185           97       13
9          2326.415          111       17
10         2424.877           90       17
11         2406.415           97       18
12         2359.738           99       14
13         2333.585          103       16
14         2241.277           99       12
15         2416.154          104       15
16         2436.662          100       16
17         2318.723          107       15
18         2457.185          120       22
19         2267.431          119       40
20         2180.262          124       34
21         2087.954          133       29
22         2308.462          111       21
23         2313.585          132       31
24         2526.923          133       27
25         2108.462          134       38
26         2123.846          168       49
27         2159.738          144       46
28         2298.200          170       40
29         2328.969          136       28
30         2021.277          137       41
31         2098.200          120       35
32         2062.308          103       26
33         1944.354          134       38

#dissimilarity
> sim<-cor(MET,method="spearman")
> dis<-1-sim
> dis
          Al        Li        Ti        Mn         Cu        As         Pb
Al 0.0000000 0.2372233 0.5757272 0.4735963 0.26892862 0.3438074 0.37561628
Li 0.2372233 0.0000000 0.5760003 0.4638951 0.31543042 0.3197032 0.33668230
Ti 0.5757272 0.5760003 0.0000000 0.4222668 0.25263333 0.3481023 0.30435507
Mn 0.4735963 0.4638951 0.4222668 0.0000000 0.26073875 0.2570617 0.25378123
Cu 0.2689286 0.3154304 0.2526333 0.2607387 0.00000000 0.2178201 0.08399498
As 0.3438074 0.3197032 0.3481023 0.2570617 0.21782013 0.0000000 0.26803176
Pb 0.3756163 0.3366823 0.3043551 0.2537812 0.08399498 0.2680318 0.00000000

> attach(CC)

        The following object(s) are masked from CC ( position 3 ) :

         PrecipitDays SnowDays SpringFreezLevel 


        The following object(s) are masked from CC ( position 8 ) :

         PrecipitDays SnowDays SpringFreezLevel 

#fuzzy set ordination
> z <- fso(~SpringFreezLevel+ PrecipitDays+SnowDays,dis,permute=1000)
Error in fso.formula(~SpringFreezLevel + PrecipitDays + SnowDays, dis,  : 
  You must supply a (dis)similarity matrix

________________________________
    

Message: 2
Date: Tue, 20 Jul 2010 20:42:54 +0100
From: Gavin Simpson <gavin.simp...@ucl.ac.uk>

Cc: r-sig-ecology@r-project.org
Subject: Re: [R-sig-eco] Distance matrix based on correlation
    coefficient
Message-ID: <1279654974.2355.49.ca...@desktop.localdomain>
Content-Type: text/plain; charset="UTF-8"

On Tue, 2010-07-20 at 12:12 -0700, Dragos Zaharescu wrote:
> I would much appreciate if someone would enlighten me on how to calculate a 
> distance matrix based on correlation coefficient (Spearman)? The simple 
> correlation matrix seems not to work.

In what sense did it not work? We aren't mind readers! Hence the posting
guide asking you to provide information that will help us to help you.

> I am trying to use it in FSO/MFSO to calculate the influence of 
> climate factors on heavy metals concentrations.

Does this help at all?

> dat <- data.frame(A = rnorm(10), B = rnorm(10), C = rnorm(10))
> cor(dat)
           A          B         C
A 1.00000000 0.08986947 0.1224007
B 0.08986947 1.00000000 0.2667838
C 0.12240068 0.26678381 1.0000000
> 1 - cor(dat) ## dissimilarity
          A         B         C
A 0.0000000 0.9101305 0.8775993
B 0.9101305 0.0000000 0.7332162
C 0.8775993 0.7332162 0.0000000
> as.dist(1 - cor(dat))
          A         B
B 0.9101305          
C 0.8775993 0.7332162

HTH

G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



------------------------------

Message: 3
Date: Tue, 20 Jul 2010 23:35:02 +0300
From: Jari Oksanen <jari.oksa...@oulu.fi>
To: Gavin Simpson <gavin.simp...@ucl.ac.uk>,    Dragos Zaharescu

Cc: r-sig-ecology@r-project.org
Subject: Re: [R-sig-eco] Distance matrix based on correlation
    coefficient
Message-ID: <c86be326.104bb%jari.oksa...@oulu.fi>
Content-Type: text/plain;    charset="US-ASCII"

On 20/07/10 22:42 PM, "Gavin Simpson" <gavin.simp...@ucl.ac.uk> wrote:

> On Tue, 2010-07-20 at 12:12 -0700, Dragos Zaharescu wrote:
>> I would much appreciate if someone would enlighten me on how to calculate a
>> distance matrix based on correlation coefficient (Spearman)? The simple
>> correlation matrix seems not to work.
> 

>> 1 - cor(dat) ## dissimilarity
>
Actually the canonical transformation to distance is sqrt(2-2*cor(dat)).

Cheers, Jari Oksanen



------------------------------

Message: 4
Date: Tue, 20 Jul 2010 21:38:23 +0100
From: Gavin Simpson <gavin.simp...@ucl.ac.uk>
To: Jari Oksanen <jari.oksa...@oulu.fi>

    r-sig-ecology@r-project.org
Subject: Re: [R-sig-eco] Distance matrix based on correlation
    coefficient
Message-ID: <1279658303.18174.2.ca...@localhost>
Content-Type: text/plain; charset="UTF-8"

On Tue, 2010-07-20 at 23:35 +0300, Jari Oksanen wrote:
> On 20/07/10 22:42 PM, "Gavin Simpson" <gavin.simp...@ucl.ac.uk> wrote:
> 
> > On Tue, 2010-07-20 at 12:12 -0700, Dragos Zaharescu wrote:
> >> I would much appreciate if someone would enlighten me on how to calculate a
> >> distance matrix based on correlation coefficient (Spearman)? The simple
> >> correlation matrix seems not to work.
> > 
> 
> >> 1 - cor(dat) ## dissimilarity
> >
> Actually the canonical transformation to distance is sqrt(2-2*cor(dat)).
> 
> Cheers, Jari Oksanen

Of course, thanks Jari. That 1 - bit was total rubbish, not even
acknowledging that cor could be negative. Not sure what came over me; I
blame the heat here in London ;-)

Hangs head in shame.

G

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%


      
        [[alternative HTML version deleted]]

_______________________________________________
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology

Reply via email to