Examples of FuzzyAHP package application (ver. `r packageDescription('FuzzyAHP')$Version`)"



The package consists several S4 objects that are used in set of functions. For each object various validation conditions are checked in order to ensure that objects are valid and that their usage in functions will provide valid result. Each problem that can occur is described as best as possible in the error message which should help with solving the issue.

AHP (non fuzzy)

Pairwise Comparison Matrix Creation

The pairwise comparison matrix can either be loaded from a file or inputted manually. Since the version 0.6.9 the values can be represented as either character or double. However, the character representation seem as slightly better idea because it allows printing more comprehensible output. The matrix needs to be squared reciprocal matrix with maximal value smaller or equal to 9.

The matrix in text file can have the following form.


Since version 0.9.0 it is also possible to use only upper or lower triangle of the pairwise comparison matrix (including the main diagonal). So the definition above can also look like this:


In case of numerical matrix the values representing undefined comparisons is either 0 or NA.

The loading is then done as:

matrixFile =  "comparison_matrix.csv"
comparisonMatrix = read.csv(matrixFile, sep = ";",
                   stringsAsFactors = FALSE, header = TRUE, row.names = 1, strip.white = TRUE)
comparisonMatrix = as.matrix(comparisonMatrix)

If the matrix is inputted manually then it can be done by following commands:

comparisonMatrixValues = c(1,9,5,
comparisonMatrix = matrix(comparisonMatrixValues, nrow = 3, ncol = 3, byrow = TRUE)

In the case that the values are represented as double. If the values are represented as character then the code looks like this:

comparisonMatrixValues = c("1","9","5",
comparisonMatrix = matrix(comparisonMatrixValues, nrow = 3, ncol = 3, byrow = TRUE)

Either way the comparison matrix is created using command pairwiseComparisonMatrix. After printing we can see that the S4 object contains two representation of the matrix, one as characters and other one as numeric as well as slot for variables names, which in this case is filled automatically.

comparisonMatrix = pairwiseComparisonMatrix(comparisonMatrix)

The textual representation of the pairwise comparison matrix can be obtained as:

textMatrix = textRepresentation(comparisonMatrix, whole = FALSE)

The whole parameter specifies if the full matrix is printed or only the upper triangle including main diagonal. Setting the parameter to TRUE is equal to using:


Testing consistency of Pairwise Comparison Matrix

There are three consistency checks implemented in FuzzyAHP package. The first is consistency ratio as defined by @Saaty1980. The functions output short message summarizing the calculation and provides value of the consistency ratio. The consistency ration can be calculated for matrices with size up to $15 \times 15$ according to @Saaty2007.

CR = consistencyRatio(comparisonMatrix, print.report = FALSE)

Another check is a weak consistency that checks if for $a_{ij}>1$ and $a_{jk}>1$ applies that $a_{ik}>=\max(a_{ij},a_{jk})$ for every $i,j,k = 1,2,\dots,n$, where $n$ is a size of matrix $a$ [@Stoklasa2013]. The functions returns TRUE if the matrix passes the test or FALSE if it fails and print short message (warning message summarizing the issues, if they exist, is printed as well).

weakConsistency = weakConsistency(comparisonMatrix)

Strict consistency is much stronger prerequisite that is generally true only for absolutely consistent evaluator. It might be problematic to fulfill this condition for more complex matrices. However, it seems reasonable to try this verification just to study the outcome. The strict consistency checks that $a_{ik} = a_{ij} \times a_{jk}$ for every $i,j,k = 1,2,\dots,n$, where $n$ is a size of matrix $a$ [@Basile1997]. Again TRUE or FALSE value is returned along with short message.

strictConsistency = strictConsistency(comparisonMatrix)

Calculations with Pairwise Comparison Matrix

If the matrix is consistent for calculation according to users conditions subsequent calculations can be made. First step is obtaining weights of criteria. The weights are calculated as geometric mean of each row of the pairwise comparison matrix.

weights = calculateWeights(comparisonMatrix)

To calculate the AHP some data are needed. As mentioned in the description the FuzzyAHP package is prepared for data that uses scale (categorical) ranking of alternatives (the higher the value the better), although classic AHP can be calculated as well. In order to calculate AHP we need matrix of data that has the same number of columns as there are weights.

Data that have even one element equal to NA are to taken into account at all, the result is automatically determined as NA.

values = c(4,5,3,
values = matrix(values, nrow = length(values)/length(weights@weights), ncol = length(weights@weights), byrow = TRUE)

Now we can calculate the result according to the weights. The values with higher resulting value are better solutions of the AHP problem.

result = calculateAHP(weights, values)

If we wan to rank solutions from the best to the worst, we can do that.

rank = compareResults(result)

It is also possible to put the results together to produce better outcome.

result = cbind(values, result, rank)
colnames(result) = c("crit1", "crit2", "crit3", "result_value", "ranking")

Obviously, since AHP is a hierarchical process the result from one calculation can be merged with outcomes from another calculation (ie. using cbind command) and used as input to another AHP calculation.

Fuzzy AHP

Fuzzy Pairwise Comparison Matrix Creation

The fuzzy pairwise comparison matrix is an extended version of pairwise comparison matrix constructed with respect to fuzzy scale. Details about fuzzy AHP are provided in several articles by @Laarhoven1983 and @Chang1996.

comparisonMatrixValues = c("1","9","5",
comparisonMatrix = matrix(comparisonMatrixValues, nrow = 3, ncol = 3, byrow = TRUE)
comparisonMatrix = pairwiseComparisonMatrix(comparisonMatrix)

Due to the fact, that checking of fuzzy comparison matrix consistency is relatively complicated, it is simpler to check the non fuzzy matrix and assume that if non fuzzy matrix is consisted than so is the fuzzy matrix. The checks are described above.

The comparison matrix is fuzzified with respect to the fuzzy scale. Default fuzzy scale ranging from 1 to 9 with width of fuzzy number equal to 2 is provided. However, user can specify his own fuzzy scale. For the details please see documentation.

fuzzyComparisonMatrix = fuzzyPairwiseComparisonMatrix(comparisonMatrix)

Calculations with Fuzzy Pairwise Comparison Matrix

With the fuzzy comparison matrix the result of AHP process can be calculated in the same way as with classic comparison matrix. The weights of fuzzy comparison matrix are calculated by approach described by @Krejci2016.

result = calculateAHP(fuzzyComparisonMatrix, values)

The resulting values have issue of representing uncertain value. Such values are hard to present to user directly. Even though it is possible. The user can extract singe fuzzy numbers from the set.

fuzzyNumer = getFuzzyNumber(result, as.integer(2))

It might be reasonable for user to either defuzzify the values into single output or rank then using fuzzy ranking methods. Defuzzification can be done using several approaches, here Yager's index is used as described by @Tesfamariam2006. The results of defuzzification can be ranked as classic results of AHP.

defuzzified = defuzziffy(result, "Yager")
rank = (nrow(values)+1) - sum(is.na(defuzzified)) - rank(defuzzified, na.last = "keep", ties.method= "max")

Ranking of fuzzy numbers can be done using various approaches. One of them is Chen's method described by @Tesfamariam2006.

ranked = compareFuzzyNumbers(result, "Chen")

Another possibility is the utilization of possibility theory as described by @Dubois1983. These indices work very well if there is a relatively bigger set of very good solutions. Unlike defuzzification or other methods these indices can rank them very well. However, if there is only one dominant best solution the result might not be very descriptive.

For large datasets the calculation might take a while. Because of that a graphical progress-bar can be printed if it is turn on by progress-bar parameter.

ranked = compareFuzzyNumbers(result, "possibilityTheory")
# ranked = compareFuzzyNumbers(result, "possibilityTheory", progressBar = TRUE)

Other methods for determination of fuzzy weights

Since version 0.8.0 three methods for determination of fuzzy weights were added to the package. These are implemented in function:

calculateWeights_old_methods(fuzzyComparisonMatrix, type)

and should only be used for comparison to the new approach proposed by @Krejci2016. All three methods do not provide optimal outputs and significantly overestimate the amount of uncertainty of fuzzy weights in fuzzy AHP. The implemented methods are from publications @Chang1996, @Tesfamariam2006 and @Wang2008b.

All three mentioned methods are often used to calculate so called weighting (or priority) vector of crisp weights based on comparisons of fuzzy weights (@Chang1996). However, @Wang2008b showed that the priority vector can assign irrational weights at specific situations and thus is not suitable for practical calculations. For the purpose of comparison the method for determination of fuzzy vector is implemented as:


Author's contribution

Jan Caha - creator, programmer

Aneta Drážná - tester


Try the FuzzyAHP package in your browser

Any scripts or data that you put into this service are public.

FuzzyAHP documentation built on Dec. 6, 2019, 5:10 p.m.