Home > Mobile >  Using formulas for calculation in R
Using formulas for calculation in R

Time:03-06

I would like some help to solve a calculus issue involving the R software. I did one part, but I didn't understand the other part very well, so I would like your help.

I used three multicriteria methods (MCDM), which I will call M1, M2 and M3, to generate ranks, which is the result database. That was the first step.

 result<-structure(list(n = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 
         12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 
         28, 29), M1 = c(29L, 1L, 28L, 27L, 25L, 26L, 24L, 20L, 21L, 
         22L, 23L, 15L, 12L, 17L, 18L, 19L, 16L, 13L, 14L, 5L, 6L, 7L, 
         8L, 9L, 10L, 11L, 4L, 2L, 3L), M2 = c(1, 29, 28, 27, 26, 25, 
        24, 23, 22, 21, 20, 15, 12, 19, 18, 17, 16, 14, 13, 11, 10, 9, 
       8, 7, 6, 5, 4, 3, 2), M3 = c(1L, 29L, 28L, 27L, 25L, 26L, 24L, 
       20L, 21L, 22L, 23L, 15L, 12L, 17L, 18L, 19L, 16L, 13L, 14L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 4L, 
       2L, 3L)), class = "data.frame", row.names = c(NA,-29L))

> result
    n M1 M2 M3
1   1 29  1  1
2   2  1 29 29
3   3 28 28 28
4   4 27 27 27
5   5 25 26 25
6   6 26 25 26
7   7 24 24 24
8   8 20 23 20
9   9 21 22 21
10 10 22 21 22
11 11 23 20 23
12 12 15 15 15
13 13 12 12 12
14 14 17 19 17
15 15 18 18 18
16 16 19 17 19
17 17 16 16 16
18 18 13 14 13
19 19 14 13 14
20 20  5 11  5
21 21  6 10  6
22 22  7  9  7
23 23  8  8  8
24 24  9  7  9
25 25 10  6 10
26 26 11  5 11
27 27  4  4  4
28 28  2  3  2
29 29  3  2  3

The second step utilizes Spearman’s rank correlation coefficient to find the weights for each MCDM method. Spearman’s rank correlation coefficient between the kth and ith MCDM methods is calculated by the following equation:

enter image description here

where n is the number of alternatives and di is the difference between the ranks of two MCDM methods.

So I did like this:

pki<-cor(result[,2:4], method = "spearman")

> pki
          M1        M2        M3
M1 1.0000000 0.5778325 0.6137931
M2 0.5778325 1.0000000 0.9640394
M3 0.6137931 0.9640394 1.0000000

The third step is as follows: Based on the value of pki, the average similarities between the kth MCDM method and other MCDM methods can be calculated as:

enter image description here

where q is the number of MCDM methods.

This third step I didn't quite understand, so I don't know how to do it, can you help me???

CodePudding user response:

Perhaps:

rho2 <-rho # “pki” -> rho[k,i]
diag(rho2) <- 0
rowSums(rho2)/2 # 1/(3-1) == 2

Do note the the term “formula” does not apply here when discussing R. That mathematical equation is really describing a set of mathematical operations. R formulas have several uses with the most applicable here being to describe model structures. The closest term to search on might be expression or function if you were trying to encapsulate this into a single object.

  •  Tags:  
  • r
  • Related