This vignette shows how to use the AHPweights() function to evaluate the weights of the lowest level subcriteria and, if available, that of the alternatives, from a hierarchical AHP structure read from a user-specified Excel file.
An example file is bundled with the package.
We assume the AHP structure is in the “ahp” sheet.
AHPstruc <- read_excel(file, sheet = "ahp")
print(AHPstruc, n=Inf)
#> # A tibble: 15 × 3
#> Node Parent Children_Ordered
#> <chr> <chr> <chr>
#> 1 G <NA> C1,C2,C3
#> 2 C1 G C1.1,C1.2
#> 3 C2 G C2.1,C2.2,C2.3
#> 4 C3 G C3.1,C3.2
#> 5 C2.1 C2 C2.1.1,C2.1.2
#> 6 C2.3 C2 C2.3.1,C2.3.2
#> 7 C1.1 C1 A1,A2,A3,A4
#> 8 C1.2 C1 A1,A2,A3,A4
#> 9 C2.2 C2 A1,A2,A3,A4
#> 10 C3.1 C3 A1,A2,A3,A4
#> 11 C3.2 C3 A1,A2,A3,A4
#> 12 C2.1.1 C2.1 A1,A2,A3,A4
#> 13 C2.1.2 C2.1 A1,A2,A3,A4
#> 14 C2.3.1 C2.3 A1,A2,A3,A4
#> 15 C2.3.2 C2.3 A1,A2,A3,A4
Note that the PCMs for all the nodes in the sheet named ahp are to be represented in the Excel sheet named “pcm”. Further, we there can be more than one respondent whose perceptions captured in PCMs are represented in separate rows of this sheet.
As we can see, there are five 15 nodes, G, C1, C2, C3, C2.1, C2.3, C1.1, C1.2, C2.2, C3.1, C3.2, C2.1.1, C2.1.2, C2.3.1 and C2.3.2. For the node G there is a 3 by 3 PCM comparing the ordered children, C1, C2 and C3 from the Children_Ordered column. The PCM is represented by the three \(\binom{3}{2}\) upper triangular elements of the matrix, and the corresponding columns take their names from the parent for these child nodes, G.1, G.2 an G.3
Similarly, for the node C1, we have a 2 by 2 PCM comparing its child nodes C1.1 and C1.2 represented by \(\binom{2}{2}\) = 1 entry named C1.1
For the node C2, there are 3 columns which need to be named which represent the upper triangular matrix for comparing C2.1, C2.2 and C2.3
Note that it is just coincidental that there is a match between some of the node names and the names of the upper triangular matrix entries in the pcm sheet.
The first row, shows the PCMs of the first respondent. There are three respondents whose responses can be seen below.
pcm <- read_excel(file, sheet = "pcm")
as.data.frame(pcm)
#> G.1 G.2 G.3 C1.1 C2.1 C2.2 C2.3 C3.1 C2.1.1 C2.3.1
#> 1 0.3333333 2 4 2 2 0.5000000 0.3333333 0.3333333 3 0.5000000
#> 2 0.5000000 1 3 3 1 0.3333333 0.2500000 0.5000000 2 1.0000000
#> 3 0.2500000 3 5 1 3 1.0000000 0.5000000 0.2500000 4 0.3333333
#> C1.1.1 C1.1.2 C1.1.3 C1.1.4 C1.1.5 C1.1.6 C1.2.1 C1.2.2 C1.2.3 C1.2.4
#> 1 0.3333333 2 4 4 6 3 2 1.0 4 0.5000000
#> 2 0.2500000 1 3 3 4 2 3 2.0 3 0.3333333
#> 3 0.5000000 3 5 5 5 4 1 0.5 5 1.0000000
#> C1.2.5 C1.2.6 C2.2.1 C2.2.2 C2.2.3 C2.2.4 C2.2.5 C2.2.6 C3.1.1
#> 1 2 3 2 1.0 0.5000000 0.5000000 0.3333333 2 0.5000000
#> 2 3 2 3 2.0 1.0000000 1.0000000 0.2500000 3 1.0000000
#> 3 1 4 1 0.5 0.3333333 0.3333333 0.5000000 1 0.3333333
#> C3.1.2 C3.1.3 C3.1.4 C3.1.5 C3.1.6 C3.2.1 C3.2.2 C3.2.3 C3.2.4 C3.2.5 C3.2.6
#> 1 2 4 3 5 2 2 2 4 1 2 3
#> 2 2 5 4 4 2 2 3 3 2 1 1
#> 3 1 3 2 3 1 1 1 2 2 2 2
#> C2.1.1.1 C2.1.1.2 C2.1.1.3 C2.1.1.4 C2.1.1.5 C2.1.1.6 C2.1.2.1 C2.1.2.2
#> 1 0.2500000 0.5 6 3 2 1 0.3333333 0.5
#> 2 0.3333333 1.0 4 2 3 2 0.5000000 1.0
#> 3 0.5000000 1.0 3 2 2 1 1.0000000 2.0
#> C2.1.2.3 C2.1.2.4 C2.1.2.5 C2.1.2.6 C2.3.1.1 C2.3.1.2 C2.3.1.3 C2.3.1.4
#> 1 0.3333333 2 2 2 0.2500000 0.5 0.3333333 2
#> 2 0.5000000 3 1 2 0.3333333 1.0 0.2500000 1
#> 3 0.2500000 1 3 2 0.2000000 1.0 0.5000000 3
#> C2.3.1.5 C2.3.1.6 C2.3.2.1 C2.3.2.2 C2.3.2.3 C2.3.2.4 C2.3.2.5 C2.3.2.6
#> 1 3 2 0.2000000 0.5 0.1666667 3 2 0.5
#> 2 2 1 0.2500000 0.5 0.2500000 3 3 1.0
#> 3 4 3 0.3333333 1.0 0.3333333 4 2 0.5
This process is optional, and not mandatorily required for the process of AHP weight calculations.
print(tree, "level", limit = NULL)
#> levelName level
#> 1 G 1
#> 2 ¦--C1 2
#> 3 ¦ ¦--C1.1 3
#> 4 ¦ ¦ ¦--A1 4
#> 5 ¦ ¦ ¦--A2 4
#> 6 ¦ ¦ ¦--A3 4
#> 7 ¦ ¦ °--A4 4
#> 8 ¦ °--C1.2 3
#> 9 ¦ ¦--A1 4
#> 10 ¦ ¦--A2 4
#> 11 ¦ ¦--A3 4
#> 12 ¦ °--A4 4
#> 13 ¦--C2 2
#> 14 ¦ ¦--C2.1 3
#> 15 ¦ ¦ ¦--C2.1.1 4
#> 16 ¦ ¦ ¦ ¦--A1 5
#> 17 ¦ ¦ ¦ ¦--A2 5
#> 18 ¦ ¦ ¦ ¦--A3 5
#> 19 ¦ ¦ ¦ °--A4 5
#> 20 ¦ ¦ °--C2.1.2 4
#> 21 ¦ ¦ ¦--A1 5
#> 22 ¦ ¦ ¦--A2 5
#> 23 ¦ ¦ ¦--A3 5
#> 24 ¦ ¦ °--A4 5
#> 25 ¦ ¦--C2.2 3
#> 26 ¦ ¦ ¦--A1 4
#> 27 ¦ ¦ ¦--A2 4
#> 28 ¦ ¦ ¦--A3 4
#> 29 ¦ ¦ °--A4 4
#> 30 ¦ °--C2.3 3
#> 31 ¦ ¦--C2.3.1 4
#> 32 ¦ ¦ ¦--A1 5
#> 33 ¦ ¦ ¦--A2 5
#> 34 ¦ ¦ ¦--A3 5
#> 35 ¦ ¦ °--A4 5
#> 36 ¦ °--C2.3.2 4
#> 37 ¦ ¦--A1 5
#> 38 ¦ ¦--A2 5
#> 39 ¦ ¦--A3 5
#> 40 ¦ °--A4 5
#> 41 °--C3 2
#> 42 ¦--C3.1 3
#> 43 ¦ ¦--A1 4
#> 44 ¦ ¦--A2 4
#> 45 ¦ ¦--A3 4
#> 46 ¦ °--A4 4
#> 47 °--C3.2 3
#> 48 ¦--A1 4
#> 49 ¦--A2 4
#> 50 ¦--A3 4
#> 51 °--A4 4
w <- AHPweights(file, "ahp", "pcm")
alternatives_list <- lapply(w$AHPresult, function(x) x$alternatives)
alternatives_list
#> [[1]]
#> A1 A2 A3 A4
#> 0.2106118 0.3923784 0.2168480 0.1801619
#>
#> [[2]]
#> A1 A2 A3 A4
#> 0.2415626 0.3750399 0.2026522 0.1807454
#>
#> [[3]]
#> A1 A2 A3 A4
#> 0.2182743 0.3729974 0.2194256 0.1893028
weights_list <- lapply(w$AHPresult, function(x) x$weights)
weights_list
#> [[1]]
#> C1.1 C1.2 C2.1.1 C2.1.2 C2.2 C2.3.1 C2.3.2
#> 0.15899142 0.07949571 0.13920354 0.04640118 0.10214221 0.11242205 0.22484410
#> C3.1 C3.2
#> 0.03412495 0.10237485
#>
#> [[2]]
#> C1.1 C1.2 C2.1.1 C2.1.2 C2.2 C2.3.1 C2.3.2
#> 0.18015815 0.06005272 0.07036393 0.03518197 0.09589482 0.17425244 0.17425244
#> C3.1 C3.2
#> 0.06994784 0.13989568
#>
#> [[3]]
#> C1.1 C1.2 C2.1.1 C2.1.2 C2.2 C2.3.1 C2.3.2
#> 0.11276775 0.11276775 0.23902978 0.05975744 0.11400866 0.06525367 0.19576101
#> C3.1 C3.2
#> 0.02013079 0.08052314
It is not always that alternatives are compared in an AHP hierarchy - there could be situations when the user is interested in evaluating the weights of the subcriteria.
The following example is one such.
w <- AHPweights(file, "AHP", "PCM")
weights_list <- lapply(w$AHPresult, function(x) x$weights)
weights_list
#> [[1]]
#> CSR EA FR RC SC SE
#> 0.050851816 0.012187988 0.008040779 0.053392885 0.038502932 0.015963667
#> AM ES GT IGI OCL PTS
#> 0.111061676 0.029664571 0.020072923 0.010260333 0.080183544 0.303074804
#> RLA SD SSP TUR
#> 0.006306321 0.051306474 0.018204126 0.190925163
#>
#> [[2]]
#> CSR EA FR RC SC SE
#> 0.036842425 0.045658288 0.044490392 0.016142680 0.030507753 0.068643026
#> AM ES GT IGI OCL PTS
#> 0.076874721 0.017930887 0.006319877 0.007315908 0.374099661 0.137819494
#> RLA SD SSP TUR
#> 0.016002596 0.025174935 0.045404222 0.050773136
#>
#> [[3]]
#> CSR EA FR RC SC SE AM
#> 0.09568503 0.16800008 0.02459511 0.05903037 0.02681632 0.11866651 0.09745699
#> ES GT IGI OCL PTS RLA SD
#> 0.01725606 0.03965254 0.03072147 0.08860727 0.03516382 0.01305820 0.08229763
#> SSP TUR
#> 0.08438625 0.01860636