The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
::opts_chunk$set(warning = FALSE, message = FALSE)
knitrlibrary(AHPWR)
library(kableExtra)
#> Warning: package 'kableExtra' was built under R version 4.2.2
This is the introduction to our package AHPWR. All theory about this method is concerned about Saaty and Vargas (2012). The examples are inspired by this reference.
According to Saaty and Vargas (2012), The Analytic Hierarchy Process (AHP) is a basic approach to decision making. It is designed to cope with both the rational and the intuitive to select the best from a number of alternatives evaluated with respect to several criteria. In this process, the decision maker carries out simple pairwise comparison judgments which are then used to develop overall priorities for ranking the alternatives. The AHP both allows for inconsistency in the judgments and provides a means to improve consistency.
The simplest form used to structure a decision problem is a hierarchy consisting of three levels: the goal of the decision at the top level, followed by a second level consisting of the criteria by which the alternatives, located in the third level, will be evaluated.
In the AHPWR package we can create the tree level hierarchy of the problem, as in the following example:
#generic, c= 4 criteria and a = 3 alternatives
flow_chart(names=NULL, c=4, a=3)
You can change the graphics according to ggplot2 options:
#generic, c= 4 criteria and a = 3 alternatives
=flow_chart(names=NULL, c=4, a=3)
p+ggplot2::labs(title = "A tree level hierarchy", x="", y="") p
#generic, c= 4 criteria and a = 3 alternatives
=flow_chart(names=NULL, c=4, a=3)
p+ggplot2::labs(title = "A tree level hierarchy", x="", y="")+ggplot2::theme_void() p
#generic, c= 4 criteria and a = 3 alternatives
= "Satisfation with House"
goal = c("Size", "Age", "Yard", "Neighborhood" )
criterios = c("house A", "house B", "house C")
alternatives = c(goal, criterios, alternatives)
names =flow_chart(names, c=4, a=3)
p+ggplot2::labs(title = "A tree level hierarchy", x="", y="")+ggplot2::theme_void() p
The next step is comparative judgment. The elements on the second level are arranged into a matrix and the family buying the house makes judgments about the relative importance of the elements with respect to the overall goal, Satisfaction with House.
The questions to ask when comparing two criteria are of the following kind: of the two alternatives being compared, which is considered more important by the family and how much more important is it with respect to family satisfaction with the house, which is the overall goal?
Paired comparison judgments in the AHP are applied to pairs of homogeneous elements. The fundamental scale of values to represent the intensities of judgments is shown in Table 1. This scale has been validated for effectiveness, not only in many applications by a number of people, but also through theoretical justification of what scale one must use in the comparison of homogeneous elements.
Intensity.of.importance | Definicion |
---|---|
1 | Equal Importance |
2 | Weak |
3 | Moderate importance |
4 | Moderate plus |
5 | Strong importance |
6 | Strong plus |
7 | Very strong or demonstrated importance |
8 | Very, very strong |
9 | Extreme importance |
Here we will use the holistic judgment criterion proposed by Godoy (2014). It provides weights for each criterion using the Saaty scale: assuming that there are \(n\) criteria, establish different weights for each of the criteria according to their importance, with \(w1\) being the weight of criterion 1; \(w2\) the weight of criterion 2 and so on.
The judge, before assigning a holistic weight, should order the items from the most important to the least important and then establish the weights that should be different for each item and descending according to the established order, unless two consecutive items have the same importance, only in this case can they have the same weight. For example, if \(w1 < w2 < ... < wn\) so order the items are A1 is less important than A2 which is less important than A3 and so on ; or An is more important than An-1 which is more important than An-2 and so on.
The hierarchy matrix will be constructed by making \(a_{ij} = wi – wj +1\) if \(wi > wj\) (ie, criterion \(i\) has greater importance than criterion \(j\)); \(aij = 1/(wj – wi +1)\) if \(wi < wj\).
The problem is to determine the best choice between two alternatives A1 = construction of a bridge connecting two points; A2 = construction of a tunnel connecting two points, based on the following criteria: C1-life cycle, C2-maintenance cost, C3-environmental impacts, C4-construction cost.
Holistic Judgment:
M1 - Criteria judgment matrix Weights attributed by the evaluators to each criterion: w1=2; w2 = 5; w3 = 2; w4 = 3, therefore, the order of importance of the criteria according to the judge is criterion 2 followed by criterion 4 followed by both criterion 1 and 3 with the same importance.
= c("life cycle", "maintenance cost", "environmental impacts", "construction cost") #criteria
x = c(2,5,2,3) #weights
y = matrix_ahp(x,y)
m1
m1#> life cycle maintenance cost environmental impacts
#> life cycle 1 0.2500000 1
#> maintenance cost 4 1.0000000 4
#> environmental impacts 1 0.2500000 1
#> construction cost 2 0.3333333 2
#> construction cost
#> life cycle 0.5
#> maintenance cost 3.0
#> environmental impacts 0.5
#> construction cost 1.0
The table with all date about the matrix, the first line informs the weights assigned by the evaluators, the following lines up to the penultimate one show the comparison matrix between criteria or alternatives and the last line informs the priority vector and the CR consistency index.
names(y) = x
=tabela_holistica(pesos=y)
table
table#> # A tibble: 6 × 6
#> ...1 `life cycle` `maintenance cost` environm…¹ const…² CR
#> <chr> <dbl> <dbl> <dbl> <dbl> <chr>
#> 1 weights 2 5 2 3 _
#> 2 life cycle 1 0.25 1 0.5 _
#> 3 maintenance cost 4 1 4 3 _
#> 4 environmental impacts 1 0.25 1 0.5 _
#> 5 construction cost 2 0.333 2 1 _
#> 6 priority 0.121 0.538 0.121 0.220 0.01
#> # … with abbreviated variable names ¹`environmental impacts`,
#> # ²`construction cost`
::kable(table) knitr
…1 | life cycle | maintenance cost | environmental impacts | construction cost | CR |
---|---|---|---|---|---|
weights | 2.0000000 | 5.0000000 | 2.0000000 | 3.0000000 | _ |
life cycle | 1.0000000 | 0.2500000 | 1.0000000 | 0.5000000 | _ |
maintenance cost | 4.0000000 | 1.0000000 | 4.0000000 | 3.0000000 | _ |
environmental impacts | 1.0000000 | 0.2500000 | 1.0000000 | 0.5000000 | _ |
construction cost | 2.0000000 | 0.3333333 | 2.0000000 | 1.0000000 | _ |
priority | 0.1209627 | 0.5384703 | 0.1209627 | 0.2196042 | 0.01 |
We can customize our table, highlighting the main information in gray:
require(magrittr)
require(kableExtra)
::kable(as.data.frame(table), align = 'c', digits = 2) %>%
knitrrow_spec(1, italic = TRUE, background = 'gray') %>%
row_spec(2:5, color = 'black', background = 'yellow') %>%
row_spec(6, underline = TRUE, color = 'black',background = 'gray',bold = TRUE,) %>%
column_spec(6, background = 'gray')
…1 | life cycle | maintenance cost | environmental impacts | construction cost | CR |
---|---|---|---|---|---|
weights | 2.00 | 5.00 | 2.00 | 3.00 | _ |
life cycle | 1.00 | 0.25 | 1.00 | 0.50 | _ |
maintenance cost | 4.00 | 1.00 | 4.00 | 3.00 | _ |
environmental impacts | 1.00 | 0.25 | 1.00 | 0.50 | _ |
construction cost | 2.00 | 0.33 | 2.00 | 1.00 | _ |
priority | 0.12 | 0.54 | 0.12 | 0.22 | 0.01 |
M2 -Judgment matrix of alternatives in relation to criterion C1 - life cycle Weights assigned by evaluators for each Alternative: w1= 1, w2 = 3
= c("bridge", "tunnel") #criteria life cycle
x = c(1,3) #weights
y = matrix_ahp(x,y)
m2
m2#> bridge tunnel
#> bridge 1 0.3333333
#> tunnel 3 1.0000000
names(y) = x
=tabela_holistica(pesos=y)
table
table#> # A tibble: 4 × 4
#> ...1 bridge tunnel CR
#> <chr> <dbl> <dbl> <chr>
#> 1 weights 1 3 _
#> 2 bridge 1 0.333 _
#> 3 tunnel 3 1 _
#> 4 priority 0.25 0.75 0
M3 -Judgment matrix of alternatives in relation to criterion C2 - maintenance cost Weights assigned by evaluators for each Alternative: w1= 1, w2 = 4
= c("bridge", "tunnel") #criteria maintenance cost
x = c(1,4) #weights
y = matrix_ahp(x,y)
m3
m3#> bridge tunnel
#> bridge 1 0.25
#> tunnel 4 1.00
names(y) = x
=tabela_holistica(pesos=y)
table
table#> # A tibble: 4 × 4
#> ...1 bridge tunnel CR
#> <chr> <dbl> <dbl> <chr>
#> 1 weights 1 4 _
#> 2 bridge 1 0.25 _
#> 3 tunnel 4 1 _
#> 4 priority 0.2 0.8 0
M4 -Judgment matrix of alternatives in relation to criterion C3 - environmental impacts Weights assigned by evaluators for each Alternative: w1= 1, w2 = 2
= c("bridge", "tunnel") #criteria environmental impacts
x = c(1,2) #weights
y = matrix_ahp(x,y)
m4
m4#> bridge tunnel
#> bridge 1 0.5
#> tunnel 2 1.0
names(y) = x
=tabela_holistica(pesos=y)
table
table#> # A tibble: 4 × 4
#> ...1 bridge tunnel CR
#> <chr> <dbl> <dbl> <chr>
#> 1 weights 1 2 _
#> 2 bridge 1 0.5 _
#> 3 tunnel 2 1 _
#> 4 priority 0.333 0.667 0
M5 -Judgment matrix of alternatives in relation to criterion C4 - construction cost Weights assigned by evaluators for each Alternative: w1= 5, w2 = 3
= c("bridge", "tunnel") #criteria construction cost
x = c(5,3) #weights
y = matrix_ahp(x,y)
m5
m5#> bridge tunnel
#> bridge 1.0000000 3
#> tunnel 0.3333333 1
names(y) = x
=tabela_holistica(pesos=y)
table
table#> # A tibble: 4 × 4
#> ...1 bridge tunnel CR
#> <chr> <dbl> <dbl> <chr>
#> 1 weights 5 3 _
#> 2 bridge 1 3 _
#> 3 tunnel 0.333 1 _
#> 4 priority 0.75 0.25 0
If \(a_{ij}\) represents the importance of alternative i over alternative j and \(a_{jk}\) represents the importance of alternative j over alternative k and \(a_{ik}\), the importance of alternative i over alternative k, must equal \(a_{ij}a_{jk}\) or \(a_{ij}a_{jk} = a_{ik}\) for the judgments to be consistent.
The consistency index of a matrix of comparisons is given by \(ic = (\lambda_{max} - n)/(n - 1)\). The consistency ratio (RC) is obtained by comparing the C.I. with the appropriate one of the following set of numbers (See Table 1.2) each of which is an average random consistency index derived from a sample of randomly generated reciprocal matrices using the scale 1/9, 1/8,…, 1,…, 8, 9. If it is not less than 0.10, study the problem and revise the judgments.
#consistency index
CI(m1)
#> [1] 0.006873396
CI(m2)
#> [1] 0
CI(m3)
#> [1] 0
CI(m4)
#> [1] 0
CI(m5)
#> [1] 0
#consistency ratio
CR(m1)
#> [1] 0.007637107
CR(m2)
#> [1] 0
CR(m3)
#> [1] 0
CR(m4)
#> [1] 0
CR(m5)
#> [1] 0
All the consistency ratio are less than 0.1, therefore all judgment matrices are considered consistent.
= list(m1, m2, m3, m4, m5)
lista calcula_prioridades(lista)
#> [[1]]
#> [1] 0.1209627 0.5384703 0.1209627 0.2196042
#>
#> [[2]]
#> [1] 0.25 0.75
#>
#> [[3]]
#> [1] 0.2 0.8
#>
#> [[4]]
#> [1] 0.3333333 0.6666667
#>
#> [[5]]
#> [1] 0.75 0.25
Each vector shows the weight of the criterio or alternative relative to the corresponding judgment matrix.
For example, the first vector matches the m1 matrix, so it provides the relative weights of each criteria: 0.12 for criteria 1; 0.54 for criteria 2, 0.12 for criteria 3 and 0.22 for criteria 4. The second vector corresponds to the m2 matrix, so it provides the weights of each alternative when considering criterion 1: 0.25 for alternative 1 and 0.75 for alternative 2, and so on.
Let be a problem with m alternatives, \(A_1, A_2, ..., A_m\) and n criteria \(C_1, C_2, ..., C_n\).
The first matrix produces \(P(C_i)\) = priority of the ith criterion for i = 1, 2, …, n
The second until n+1 matrix produces \(P(A_j|C_i)\) = priority of the j-th alternative conditional on the i-th criterion in case the problem has only one level of criteria, j=1, 2, …, m and i=1, 2, …,n. In this case
\(P(A_j) = \sum_{i=1}^{n}P(A_j|C_i)P(C_i)\), \(j=1, 2, ...,m\)
The function ahp_geral() will provide a table containing the marginal weights of each criterion, the conditional weights of each alternative given a certain criterion, the global weights of each alternative and a consistency ratio CR.
Criteria | Weights | A1 | A2 | … | Am | CR | |
---|---|---|---|---|---|---|---|
Alternatives -> | 1 | \(P(A1)\) | \(P(A2)\) | … | \(P(Am)\) | ||
\(C1\) | \(P(C1)\) | \(P(A1|C1)P(C1)\) | \(P(A2|C1)P(C1)\) | … | \(P(Am|C1)P(C1)\) | \(CR(M_1)\) | |
\(C2\) | \(P(C2)\) | \(P(A1|C2)P(C2)\) | \(P(A2|C2)P(C2)\) | … | \(P(Am|C2)P(C2)\) | \(CR(M_2)\) | |
… | … | … | … | … | … | ||
\(Cn\) | \(P(Cn)\) | \(P(A1|Cn)P(Cn)\) | \(P(A2|Cn)P(Cn)\) | … | \(P(Am|Cn)P(Cn)\) | \(CR(M_{n+1}\)) | |
Observe that
\(\sum_{j=1}^{m}P(A_j) =1\), \(\sum_{i=1}^{n}P(C_i) =1\), \(P(A_j) = \sum_{i=1}^{n}P(A_j|C_i)P(C_i)\), \(j=1, 2, ...,m\)
The alternative with the highest priority value may be the decision maker’s final choice.
Hierarchic synthesis is obtained by a process of weighting and adding down the hierarchy leading to a multilinear form.
lista#> [[1]]
#> life cycle maintenance cost environmental impacts
#> life cycle 1 0.2500000 1
#> maintenance cost 4 1.0000000 4
#> environmental impacts 1 0.2500000 1
#> construction cost 2 0.3333333 2
#> construction cost
#> life cycle 0.5
#> maintenance cost 3.0
#> environmental impacts 0.5
#> construction cost 1.0
#>
#> [[2]]
#> bridge tunnel
#> bridge 1 0.3333333
#> tunnel 3 1.0000000
#>
#> [[3]]
#> bridge tunnel
#> bridge 1 0.25
#> tunnel 4 1.00
#>
#> [[4]]
#> bridge tunnel
#> bridge 1 0.5
#> tunnel 2 1.0
#>
#> [[5]]
#> bridge tunnel
#> bridge 1.0000000 3
#> tunnel 0.3333333 1
ahp_geral(lista)
#> # A tibble: 5 × 5
#> Criteria Weights A B CR
#> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 ---Alternatives 1 0.343 0.657 0.00764
#> 2 --C1 0.121 0.0302 0.0907 0
#> 3 --C2 0.538 0.108 0.431 0
#> 4 --C3 0.121 0.0403 0.0806 0
#> 5 --C4 0.220 0.165 0.0549 0
=paste0(letters[3],1:5) #criteria names C1, C2, ..., C5
x=c(5,2,7,3,2) #judgments
y=matrix_ahp(x,y)
m1=paste0(letters[1],1:3) #alternatives names A1, A2, A3
x=c(4.4,5.2,3)
y=matrix_ahp(x,y)
m2=c(2,4,3)
y=matrix_ahp(x,y)
m3=c(4.9,5,3.3)
y=matrix_ahp(x,y)
m4=c(4.4,4.2,4.3)
y=matrix_ahp(x,y)
m5=c(5.4,5.2,5.7)
y=matrix_ahp(x,y)
m6=list(m1, m2, m3, m4, m5, m6)
base
base#> [[1]]
#> c1 c2 c3 c4 c5
#> c1 1.0000000 4 0.3333333 3.0 4
#> c2 0.2500000 1 0.1666667 0.5 1
#> c3 3.0000000 6 1.0000000 5.0 6
#> c4 0.3333333 2 0.2000000 1.0 2
#> c5 0.2500000 1 0.1666667 0.5 1
#>
#> [[2]]
#> a1 a2 a3
#> a1 1.0000000 0.5555556 2.4
#> a2 1.8000000 1.0000000 3.2
#> a3 0.4166667 0.3125000 1.0
#>
#> [[3]]
#> a1 a2 a3
#> a1 1 0.3333333 0.5
#> a2 3 1.0000000 2.0
#> a3 2 0.5000000 1.0
#>
#> [[4]]
#> a1 a2 a3
#> a1 1.0000000 0.9090909 2.6
#> a2 1.1000000 1.0000000 2.7
#> a3 0.3846154 0.3703704 1.0
#>
#> [[5]]
#> a1 a2 a3
#> a1 1.0000000 1.2 1.1000000
#> a2 0.8333333 1.0 0.9090909
#> a3 0.9090909 1.1 1.0000000
#>
#> [[6]]
#> a1 a2 a3
#> a1 1.0000000 1.2 0.7692308
#> a2 0.8333333 1.0 0.6666667
#> a3 1.3000000 1.5 1.0000000
calcula_prioridades(base) #fornece somente os vetores prioridades
#> [[1]]
#> [1] 0.25002869 0.06547834 0.50960586 0.10940877 0.06547834
#>
#> [[2]]
#> [1] 0.3237132 0.5272156 0.1490712
#>
#> [[3]]
#> [1] 0.1634241 0.5396146 0.2969613
#>
#> [[4]]
#> [1] 0.4046683 0.4366744 0.1586573
#>
#> [[5]]
#> [1] 0.3646121 0.3030041 0.3323838
#>
#> [[6]]
#> [1] 0.3197529 0.2699673 0.4102798
lapply(base,tabela_holistica) #fornece uma tabela com a matriz de comparação o vetor prioridade e o CR.
#> [[1]]
#> ...1 c1 c2 c3 c4 c5 CR
#> 1 c1 1.0000000 4.00000000 0.3333333 3.0000000 4.00000000 _
#> 2 c2 0.2500000 1.00000000 0.1666667 0.5000000 1.00000000 _
#> 3 c3 3.0000000 6.00000000 1.0000000 5.0000000 6.00000000 _
#> 4 c4 0.3333333 2.00000000 0.2000000 1.0000000 2.00000000 _
#> 5 c5 0.2500000 1.00000000 0.1666667 0.5000000 1.00000000 _
#> 6 priority 0.2500287 0.06547834 0.5096059 0.1094088 0.06547834 0.02
#>
#> [[2]]
#> ...1 a1 a2 a3 CR
#> 1 a1 1.0000000 0.5555556 2.4000000 _
#> 2 a2 1.8000000 1.0000000 3.2000000 _
#> 3 a3 0.4166667 0.3125000 1.0000000 _
#> 4 priority 0.3237132 0.5272156 0.1490712 0.01
#>
#> [[3]]
#> ...1 a1 a2 a3 CR
#> 1 a1 1.0000000 0.3333333 0.5000000 _
#> 2 a2 3.0000000 1.0000000 2.0000000 _
#> 3 a3 2.0000000 0.5000000 1.0000000 _
#> 4 priority 0.1634241 0.5396146 0.2969613 0.01
#>
#> [[4]]
#> ...1 a1 a2 a3 CR
#> 1 a1 1.0000000 0.9090909 2.6000000 _
#> 2 a2 1.1000000 1.0000000 2.7000000 _
#> 3 a3 0.3846154 0.3703704 1.0000000 _
#> 4 priority 0.4046683 0.4366744 0.1586573 0
#>
#> [[5]]
#> ...1 a1 a2 a3 CR
#> 1 a1 1.0000000 1.2000000 1.1000000 _
#> 2 a2 0.8333333 1.0000000 0.9090909 _
#> 3 a3 0.9090909 1.1000000 1.0000000 _
#> 4 priority 0.3646121 0.3030041 0.3323838 0
#>
#> [[6]]
#> ...1 a1 a2 a3 CR
#> 1 a1 1.0000000 1.2000000 0.7692308 _
#> 2 a2 0.8333333 1.0000000 0.6666667 _
#> 3 a3 1.3000000 1.5000000 1.0000000 _
#> 4 priority 0.3197529 0.2699673 0.4102798 0
ahp_geral(base)
#> # A tibble: 6 × 6
#> Criteria Weights A B C CR
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 ---Alternatives 1 0.359 0.441 0.201 0.0195
#> 2 --C1 0.250 0.0809 0.132 0.0373 0.00863
#> 3 --C2 0.0655 0.0107 0.0353 0.0194 0.00793
#> 4 --C3 0.510 0.206 0.223 0.0809 0.000317
#> 5 --C4 0.109 0.0399 0.0332 0.0364 0.00000660
#> 6 --C5 0.0655 0.0209 0.0177 0.0269 0.000147
= ahp_geral(base)
table1 transforma_tabela(table1)
#> # A tibble: 6 × 6
#> Criteria Weights A B C CR
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 ---Alternatives 100% 35.87% 44.05% 20.08% 1.95%
#> 2 --C1 25% 8.09% 13.18% 3.73% 0.86%
#> 3 --C2 6.55% 1.07% 3.53% 1.94% 0.79%
#> 4 --C3 50.96% 20.62% 22.25% 8.09% 0.03%
#> 5 --C4 10.94% 3.99% 3.32% 3.64% 0%
#> 6 --C5 6.55% 2.09% 1.77% 2.69% 0.01%
formata_tabela(table1)
Criteria | Weights | A | B | C | CR |
---|---|---|---|---|---|
—Alternatives | 100% | 35.87% | 44.05% | 20.08% | 1.95% |
–C1 | 25% | 8.09% | 13.18% | 3.73% | 0.86% |
–C2 | 6.55% | 1.07% | 3.53% | 1.94% | 0.79% |
–C3 | 50.96% | 20.62% | 22.25% | 8.09% | 0.03% |
–C4 | 10.94% | 3.99% | 3.32% | 3.64% | 0% |
–C5 | 6.55% | 2.09% | 1.77% | 2.69% | 0.01% |
formata_tabela(table1, cores = "GRAY")
Criteria | Weights | A | B | C | CR |
---|---|---|---|---|---|
—Alternatives | 100% | 35.87% | 44.05% | 20.08% | 1.95% |
–C1 | 25% | 8.09% | 13.18% | 3.73% | 0.86% |
–C2 | 6.55% | 1.07% | 3.53% | 1.94% | 0.79% |
–C3 | 50.96% | 20.62% | 22.25% | 8.09% | 0.03% |
–C4 | 10.94% | 3.99% | 3.32% | 3.64% | 0% |
–C5 | 6.55% | 2.09% | 1.77% | 2.69% | 0.01% |
formata_tabela(table1, cores = "WHITE")
Criteria | Weights | A | B | C | CR |
---|---|---|---|---|---|
—Alternatives | 100% | 35.87% | 44.05% | 20.08% | 1.95% |
–C1 | 25% | 8.09% | 13.18% | 3.73% | 0.86% |
–C2 | 6.55% | 1.07% | 3.53% | 1.94% | 0.79% |
–C3 | 50.96% | 20.62% | 22.25% | 8.09% | 0.03% |
–C4 | 10.94% | 3.99% | 3.32% | 3.64% | 0% |
–C5 | 6.55% | 2.09% | 1.77% | 2.69% | 0.01% |
ranque(table1)
#> # A tibble: 3 × 3
#> Ranque Alternativas Pesos
#> <int> <chr> <dbl>
#> 1 1 B 0.441
#> 2 2 A 0.359
#> 3 3 C 0.201
When the problem has one level of criteria and a second level of subcriteria, it will be necessary to map the hierarchical structure as follows:
Let \(n\) be the number of criteria in the problem with \(m\) alternatives and \(n_{i}\) the number of sub-criteria of the ith criterion, so let’s define the mapping vector \(map = c(n_1, n_2, ..., n_n)\).
This mapping must match the list of paired matrices \(M_1, M_2, ..., M_h\), as follows:
For example suppose a problem with n=5 criteria, m=2 alternatives and \(n_1=0, n_2=2, n_3=4, n_4=0, n_5=0\) the number of sub-criterion for each corresponding criterion. So,
M1 will be a 5x5 matrix comparing all five criteria
M2 will be a 2x2 matrix comparing all two alternatives in the light of criterion 1 because n1=0
M3 will be a 2x2 matrix comparing all two sub-criteria of criteria 2, because n2=2
M4 will be a 2x2 matrix comparing all two alternatives in the light of sub-criterion 1 of criteria 2
M5 will be a 2x2 matrix comparing all two alternatives in the light of sub-criterion 2 of criteria 2
M6 will be a 4x4 matrix comparing all four sub-criteria of criteria 3, because n3=4
M7 will be a 2x2 matrix comparing all two alternatives in the light of sub-criterion 1 of criteria 3
M8 will be a 2x2 matrix comparing all two alternatives in the light of sub-criterion 2 of criteria 3
M9 will be a 2x2 matrix comparing all two alternatives in the light of sub-criterion 3 of criteria 3
M10 will be a 2x2 matrix comparing all two alternatives in the light of sub-criterion 4 of criteria 3
M11 will be a 2x2 matrix comparing all two alternatives in the light of criterion 4 because n4=0
M12 will be a 2x2 matrix comparing all two alternatives in the light of criterion 5 because n5=0
It is extremely important that the list of matrices be in this order because the method takes this matched mapping into account.
#two criteria, each with two subcriteria
= c(2,2)
map #x with names and y with holistic judgment
=paste0(letters[3],1:2) #2 criteria
x=c(5,7)
y=matrix_ahp(x,y) # matrix compare two criteria
m1=paste0("SC1",1:2)
x=c(4,6)
y=matrix_ahp(x,y) # matrix compare two subcriteria of criteria 1
m2=paste0(letters[1],1:3)
x=c(2,4,5)
y=matrix_ahp(x,y) #alternatives for subcriteria 1 - criteria 1
m3=c(4.9,5, 2)
y=matrix_ahp(x,y) #alternatives for subcriteria 2 - criteria 1
m4=c(4.4,8, 6)
y=paste0("SC2",1:2)
x=matrix_ahp(x,y) #matrix compare two subcriteria of criteria 2
m5=c(5.4,5.2, 1)
y=paste0(letters[1],1:3)
x=matrix_ahp(x,y) #alternatives for subcriteria 1 - criteria 2
m6=c(9,5.2, 3)
y=matrix_ahp(x,y) #alternatives for subcriteria 2 - criteria 2
m7
=list(m1, m2, m3, m4, m5, m6, m7)
base
base#> [[1]]
#> c1 c2
#> c1 1 0.3333333
#> c2 3 1.0000000
#>
#> [[2]]
#> SC11 SC12
#> SC11 1 0.3333333
#> SC12 3 1.0000000
#>
#> [[3]]
#> a1 a2 a3
#> a1 1 0.3333333 0.25
#> a2 3 1.0000000 0.50
#> a3 4 2.0000000 1.00
#>
#> [[4]]
#> a1 a2 a3
#> a1 1.0000000 0.9090909 3.9
#> a2 1.1000000 1.0000000 4.0
#> a3 0.2564103 0.2500000 1.0
#>
#> [[5]]
#> SC21 SC22
#> SC21 1.0 0.2173913
#> SC22 4.6 1.0000000
#>
#> [[6]]
#> a1 a2 a3
#> a1 1.0000000 1.2000000 5.4
#> a2 0.8333333 1.0000000 5.2
#> a3 0.1851852 0.1923077 1.0
#>
#> [[7]]
#> a1 a2 a3
#> a1 1.0000000 4.8000 7.0
#> a2 0.2083333 1.0000 3.2
#> a3 0.1428571 0.3125 1.0
Let be a problem with m alternatives, \(A_1, A_2, ..., A_m\), n criteria \(C_1, C_2, ..., C_n\) with n_k_i sub-criteria corresponding to the ith criterion.
The first matrix produces \(P(C_i)\) or \(P(SCi_k|C_i)\) = priority of the ith criterion or kth subcriterion of ith criterion for \(i = 1, 2, ..., n\) and \(k = 1, ..., n_{i}\).
The next matrices produce comparisons of criteria versus alternatives or criteria versus subcriteria followed by comparisons of alternatives versus each subcriteria corresponding to the parent criteria, according to the established mapping, \(map = c(n_{k1}, n_{k2}, ..., n_{kn})\). We will consider two situations:
\(C_i = SC_{i1}\cup SC_{i2}\cup...\cup SC_{in_i}\)
\(P(SC_{ik}) = P(SC_{ik}|C_i)P(C_i)\), \(k=1, 2, ...,n_{i}, i=1,2,...n\)
\(P(C_i) = \sum_{k=1}^{n_{i}}P(SC_{ik})\), \(i=1, 2, ...,n\)
\(P(A_j|C_i) = \sum_{k=1}^{n_i}P(Aj|SCik)P(SCik|Ci)\)
\(P(A_j) = \sum_{i=1}^{n}P(A_j|C_i)P(C_i)\), \(j=1, 2, ...,m\)
\(P(A_j) = \sum_{i=1}^{n}P(A_j|C_i)P(C_i)\), \(j=1, 2, ...,m\)
The function ahp_s() will provide a table containing the marginal weights of each criterion/subcriterion, the conditional weights of each alternative given a certain criterion/sucriterion and the global weights of each alternative.
Criteria | Weights | A1 | A2 | … | Am | CR | |
---|---|---|---|---|---|---|---|
Alternatives -> | 1 | \(P(A1)\) | \(P(A2)\) | … | \(P(Am)\) | \(CR(M_1)\) | |
\(SC_{11}\) | \(P(SC_{11}|C1)\) | \(P(A1|SC_{11})P(SC_{11}|C1)\) | \(P(A2|SC11)P(SC11|C1)\) | … | \(P(Am|SC11)P(SC11|C1)\) | \(CR(M_3)\) | |
\(SC_{12}\) | \(P(SC_{12}|C1)\) | \(P(A1|SC_{12})P(SC_{12}|C1)\) | \(P(A2|SC_{12})P(SC_{12}|C1)\) | … | \(P(Am|SC_{12})P(SC_{12}|C1)\) | \(CR(M_4)\) | |
… | |||||||
\(SC_{1n_1}\) | \(P(SC_{1n_1}|C1)\) | \(P(A1|SC_{1n_1})P(SC_{1n_1}|C1)\) | \(P(A2|SC_{1n_1})P(SC_{1n_1}|C1)\) | … | \(P(Am|SC_{1n_1})P(SC_{1n_1}|C1)\) | \(CR(M_{2+n_1})\) | |
\(C1\) | \(P(C1)\) | \(P(A1|C1)P(C1)\) | \(P(A2|C1)P(C1)\) | … | \(P(Am|C1)P(C1)\) | \(CR(M_{2})\) | |
… | … | … | … | … | … | ||
\(Cn\) | \(P(Cn)\) | \(P(A1|Cn)P(Cn)\) | \(P(A2|Cn)P(Cn)\) | \(P(Am|Cn)P(Cn)\) | \(CR(M_{1+n+n_1+...+n_n})\) | ||
Observe that
\(\sum_{j=1}^{m}P(A_j) =1\), \(\sum_{i=1}^{n}P(C_i) =1\), \(\sum_{k=1}^{n_i}P(SC_{ik}|Ci) =1\), \(P(C_i) = \sum_{k=1}^{n_{i}}P(SC_{ik})\), \(i=1, 2, ...,n\) and \(P(A_j) = \sum_{i=1}^{n}P(A_j|C_i)P(C_i)\), \(j=1, 2, ...,m\)
The alternative with the highest priority value may be the decision maker’s final choice.
Hierarchic synthesis is obtained by a process of weighting and adding down the hierarchy leading to a multilinear form.
#Priority vector and CR
#
calcula_prioridades(base) #fornece somente os vetores prioridades
#> [[1]]
#> [1] 0.25 0.75
#>
#> [[2]]
#> [1] 0.25 0.75
#>
#> [[3]]
#> [1] 0.1219572 0.3196183 0.5584245
#>
#> [[4]]
#> [1] 0.4278814 0.4598156 0.1123030
#>
#> [[5]]
#> [1] 0.1785714 0.8214286
#>
#> [[6]]
#> [1] 0.48757884 0.42637711 0.08604404
#>
#> [[7]]
#> [1] 0.72429277 0.19608181 0.07962542
lapply(base,tabela_holistica) #fornece uma tabela com a matriz de comparação o vetor prioridade e o CR.
#> [[1]]
#> ...1 c1 c2 CR
#> 1 c1 1.00 0.3333333 _
#> 2 c2 3.00 1.0000000 _
#> 3 priority 0.25 0.7500000 0
#>
#> [[2]]
#> ...1 SC11 SC12 CR
#> 1 SC11 1.00 0.3333333 _
#> 2 SC12 3.00 1.0000000 _
#> 3 priority 0.25 0.7500000 0
#>
#> [[3]]
#> ...1 a1 a2 a3 CR
#> 1 a1 1.0000000 0.3333333 0.2500000 _
#> 2 a2 3.0000000 1.0000000 0.5000000 _
#> 3 a3 4.0000000 2.0000000 1.0000000 _
#> 4 priority 0.1219572 0.3196183 0.5584245 0.02
#>
#> [[4]]
#> ...1 a1 a2 a3 CR
#> 1 a1 1.0000000 0.9090909 3.900000 _
#> 2 a2 1.1000000 1.0000000 4.000000 _
#> 3 a3 0.2564103 0.2500000 1.000000 _
#> 4 priority 0.4278814 0.4598156 0.112303 0
#>
#> [[5]]
#> ...1 SC21 SC22 CR
#> 1 SC21 1.0000000 0.2173913 _
#> 2 SC22 4.6000000 1.0000000 _
#> 3 priority 0.1785714 0.8214286 0
#>
#> [[6]]
#> ...1 a1 a2 a3 CR
#> 1 a1 1.0000000 1.2000000 5.40000000 _
#> 2 a2 0.8333333 1.0000000 5.20000000 _
#> 3 a3 0.1851852 0.1923077 1.00000000 _
#> 4 priority 0.4875788 0.4263771 0.08604404 0
#>
#> [[7]]
#> ...1 a1 a2 a3 CR
#> 1 a1 1.0000000 4.8000000 7.00000000 _
#> 2 a2 0.2083333 1.0000000 3.20000000 _
#> 3 a3 0.1428571 0.3125000 1.00000000 _
#> 4 priority 0.7242928 0.1960818 0.07962542 0.06
ahp_s(base,map)
#> # A tibble: 7 × 6
#> criteria Weithts A1 A2 A3 CR
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 Alternatives-> 1 0.599 0.284 0.117 0
#> 2 --SC11 0.25 0.0305 0.0799 0.140 0.0158
#> 3 --SC12 0.75 0.321 0.345 0.0842 0.000469
#> 4 -C1 0.25 0.0879 0.106 0.0560 0
#> 5 --SC21 0.179 0.0871 0.0761 0.0154 0.00200
#> 6 --SC22 0.821 0.595 0.161 0.0654 0.0595
#> 7 -C2 0.75 0.512 0.178 0.0606 0
= ahp_s(base,map)
tb
transforma_tabela(tb)
#> # A tibble: 7 × 6
#> criteria Weithts A1 A2 A3 CR
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 Alternatives-> 100% 59.94% 28.41% 11.65% 0%
#> 2 --SC11 25% 3.05% 7.99% 13.96% 1.58%
#> 3 --SC12 75% 32.09% 34.49% 8.42% 0.05%
#> 4 -C1 25% 8.79% 10.62% 5.6% 0%
#> 5 --SC21 17.86% 8.71% 7.61% 1.54% 0.2%
#> 6 --SC22 82.14% 59.5% 16.11% 6.54% 5.95%
#> 7 -C2 75% 51.15% 17.79% 6.06% 0%
formata_tabela(tb)
criteria | Weithts | A1 | A2 | A3 | CR |
---|---|---|---|---|---|
Alternatives-> | 100% | 59.94% | 28.41% | 11.65% | 0% |
–SC11 | 25% | 3.05% | 7.99% | 13.96% | 1.58% |
–SC12 | 75% | 32.09% | 34.49% | 8.42% | 0.05% |
-C1 | 25% | 8.79% | 10.62% | 5.6% | 0% |
–SC21 | 17.86% | 8.71% | 7.61% | 1.54% | 0.2% |
–SC22 | 82.14% | 59.5% | 16.11% | 6.54% | 5.95% |
-C2 | 75% | 51.15% | 17.79% | 6.06% | 0% |
The ahp_geral() function constructs the summary table equal from ahp_s, for problem with no subcriteria. Anyway, both produce the criteria and alternative weights, in this respect the functions return the same value when problem has one level of criteria. We recommend using ahp_s when the problem has subcriteria.
Consider the problem with 6 criteria and 4 alternatives
=c(2,4,5,1,6,3) #holistcs weights for compare 6 criteria
p1=c(5, 4, 6, 7) #holistcs weights for compare 4 alternatives for criterion 1
p2=c(2, 8, 2, 7) #holistcs weights for compare 4 alternatives for criterion 2
p3=c(5, 1, 4, 1) #holistcs weights for compare 4 alternatives for criterion 3
p4=c(3.4, 4, 2, 3) #holistcs weights for compare 4 alternatives for criterion 4
p5=c(6, 4, 2, 2.5) #holistcs weights for compare 4 alternatives for criterion 5
p6=c(5, 3, 6, 1.8) #holistcs weights for compare 4 alternatives for criterion 6
p7
=paste0("C",1:6)
x1= paste0("A",1:4)
x
= matrix_ahp(x1,p1)
m1 = matrix_ahp(x,p2)
m2 = matrix_ahp(x,p3)
m3 = matrix_ahp(x,p4)
m4 = matrix_ahp(x,p5)
m5 = matrix_ahp(x,p6)
m6 = matrix_ahp(x,p7)
m7
=list(m1,m2, m3, m4, m5, m6, m7)
baseformata_tabela(ahp_geral(base))
Criteria | Weights | A | B | C | D | CR |
---|---|---|---|---|---|---|
—Alternatives | 100% | 40.13% | 23.5% | 19.61% | 16.77% | 1.98% |
–C1 | 6.41% | 1.03% | 0.61% | 1.78% | 2.99% | 1.15% |
–C2 | 15.96% | 1.04% | 8.4% | 1.04% | 5.48% | 1.35% |
–C3 | 25.04% | 12.62% | 2.23% | 7.97% | 2.23% | 1.03% |
–C4 | 4.28% | 1.17% | 1.72% | 0.5% | 0.89% | 0.42% |
–C5 | 38.25% | 21.19% | 9.27% | 3.37% | 4.42% | 1.74% |
–C6 | 10.06% | 3.09% | 1.28% | 4.96% | 0.74% | 2.04% |
formata_tabela(ahp_s(base, map=c(0,0,0,0,0,0)))
criteria | Weithts | A1 | A2 | A3 | A4 | CR |
---|---|---|---|---|---|---|
Alternatives-> | 100% | 40.13% | 23.5% | 19.61% | 16.77% | 1.98% |
-C1 | 6.41% | 1.03% | 0.61% | 1.78% | 2.99% | 1.15% |
-C2 | 15.96% | 1.04% | 8.4% | 1.04% | 5.48% | 1.35% |
-C3 | 25.04% | 12.62% | 2.23% | 7.97% | 2.23% | 1.03% |
-C4 | 4.28% | 1.17% | 1.72% | 0.5% | 0.89% | 0.42% |
-C5 | 38.25% | 21.19% | 9.27% | 3.37% | 4.42% | 1.74% |
-C6 | 10.06% | 3.09% | 1.28% | 4.96% | 0.74% | 2.04% |
Alcoforado, L.F. (2021) Utilizando a Linguagem R: conceitos, manipulação, visualização, Modelagem e Elaboração de Relatório, Alta Books, Rio de Janeiro.
Godoi, W.C. (2014). Método de construção das matrizes de julgamento paritário no AHP – método de julgamento holístico. Revista Gestão Industrial, ISSN 1808-0448 / v. 10, n. 03: p.474- 493, D.O.I: 10.3895/gi.v10i3.1970
Longo, O.C., Alcoforado, L.F., Levy, A (2022). Utilização do pacote AHP na tomada de decisão. In IX Xornada de Usuarios de R en Galicia,
Oliveira, L.S., AHP, Github.com. (2020) URL = https://github.com/Lyncoln/AHP, Acesso em 20/09/2022.
Oliveira, L.S., Alcoforado, L.F., Ross, S.D., Simão, A.S. (2019). Implementando a AHP com R. Anais do SER, ISSN 2526-7299, v.4, n.2. URL: https://periodicos.uff.br/anaisdoser/article/view/29331
Saaty, T.L., Vargas, L.G. (2012), Models, Methods, Concepts and Applications of the Analytic Hierarchy Process, Second Edition, Springer, New York.
Triantaphyllou, E., Shu, B., Nieto Sanchez, S., Ray, T. (1998). Multi-Criteria Decision Making: An Opera-tions Research Approach. Encyclopedia of Electrical and Electronics Engineering, (J.G. Webster, Ed.), John Wiley & Sons, New York, NY, Vol. 15, pp. 175-186.
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.