Analytic Hierarchy Process for Survey Data in R

Vignettes for the ahpsurvey package (ver 0.4.0)

Frankie Cho

16 February 2019

Introduction

The Analytic Hierarchy Process (AHP), introduced by Saaty (1987), is a versatile multi-criteria decision-making tool that allows individuals to rationally weigh attributes and evaluate alternatives presented to them. While most applications of the AHP are focused on implementation at the individual or small-scale, the AHP was increasingly adopted in survey designs, which involve a large number of decision-makers and a great deal of heterogeneity in responses. The tools currently available in R for the analysis of AHP data, such as the packages ahp by Glur (2018) and Prize by Dargahi (2016), are excellent tools for performing the AHP at a small scale and offers are excellent in terms of interactivity, user-friendliness, and for comparing alternatives.

However, researchers looking to adopt the AHP in the analysis of survey data often have to manually reformat their data, sometimes even involving dragging and copying across Excel spreadsheets, which is painstaking and prone to human error. Hitherto, there are no good ways of computing and visualising the heterogeneity amongst AHP decision-makers, which is common in survey data. Inconsistent choices are also prevalent in AHP conducted in the survey format, where it is impractical for enumerators to identify and correct for inconsistent responses on the spot when the surveys are delivered in paper format. Even if an electronic version that allows immediate feedback of consistency ratio is used, respondents asked to repeatedly change their answers are likely to be mentally fatigued. Censoring observations with inconsistency is likely to result in a greatly decreased statistical power of the sample, or may lead to unrepresentative samples and nonresponse bias.

The ahpsurvey package provides a workflow for researchers to quantify and visualise inconsistent pairwise comparisons that aids researchers in improving the AHP design and adopting appropriate analytical methods for the AHP.

If you are familiar with the AHP and want a rapid way of processing your data, skip to the part about the canned routine towards the end.

The Saaty AHP and the toy dataset

A gentle introduction of the AHP survey methodology:

Rating

Definition

1

Two characteristics are equally important

2

Between 1 and 3

3

The preferred characteristics are slightly more important

4

Between 3 and 5

5

The preferred characteristics are moderately more important

6

Between 5 and 7

7

The preferred characteristics are strongly more important

8

Between 7 and 9

9

The preferred characteristics are absolutely more important

A Saaty scale is composed of 9 items on each end (17 options per pairwise comparison) where decision-makers are asked to indicate how much attribute/ characteristic A is more preferred to B (or vice versa), and how much it is preferred in a 9-point scale. Respondents are asked to make pairwise comparisons for a range of attributes, and indicate their priorities for each of them.

Afterwards, we load the data needed, city200, which consists of randomly generated data of 200 individuals based on the weights provided in Saaty (2004). The methodology of data generation is explained at the end of this vignette.

The simulated dataset consists of ten pairwise comparisons of five attributes, which are “culture”, “family”, “housing”, “jobs” and “transportation.” An individual compares the attributes in a pairwise fashion; if culture is more important than house by 2 units on the Saaty scale, the dataset will code it as -2. This is important to bear in mind as we move on.

Individual and Aggregated priorities

Creating pairwise comparison matrices

Based on the Saaty scale, a pairwise comparison matrix of \(N\) attributes for the \(k^{th}\) individual is obtained:

Where \(a_{i,j}\) represents the pairwise comparison between the attribute \(i\) and \(j\). If \(i\) is more important than \(j\) for 6 units, \(a_{i,j} = 6\) and \(a_{j,i} = \frac{1}{6}\), i.e. the reciprocal. Data must be reformatted into this pairwise comparison matrix format to proceed.

The reformatting of the survey data (with one row per individual) into such a matrix necessary for further analysis is cumbersome for researchers. Furthermore, as researchers conducting the AHP as an integrated part of a survey, we typically receive data in the above format: the pairwise comparisons are coded in positive and negative numbers as opposed to reciprocals. In the pairwise comparison of cult_fam:

In the case where the decision-maker chose 6, the sensible codebook maker would code it as -6, which denotes that Culture is more important than Family in 6 units for that decision-maker. For ahp.mat to work, the value in A_B variable have to be the importance A has over B in positive values. In this case, the values should be converted from negative to positive, and the negative values would be converted to its reciprocal in the pairwise matrix. When data is coded in the above way, set negconvert = TRUE. If the data is already coded in the reciprocal (as opposed to negatives), set reciprocal = FALSE.

Some caveats prior to entering the data into the ahp.mat function. ahp.mat does not recognise the names of the original dataframe, and figures out which attribute corresponds to which entirely based on the order of the columns. For example, when the attributes are A, B, C and D, the dataframe should be ordered in A_B, A_C, A_D, B_C, B_D, C_D, and the attributes listed as c(A,B,C,D), in that order.

ahp.mat takes four arguments:

df: the dataframe

atts: a list of attributes in the correct order

negconvert: whether to convert all positive values to negative (logical, defaults to FALSE)

The ahp.mat function creates a list of pairwise comparison matrices for all decision-makers. As seen above, the pairwise matrices resembles the original Saaty criteria weights, which is a good sanity check.

Individual preference weights

The ahp.indpref function computes the individual priorities of the decision-makers, and returns a data.frame containing the preference weights of the decision-makers. The three arguments are as follows:

ahpmat: The list of matrices created by ahp.mat.

atts: a list of attributes in the correct order.

method: It normalises the matrices so that all of the columns add up to 1, and then computes the averages of the row as the preference weights of each attribute. Four modes of finding the averages are available:

arithmetic: the arithmetic mean

geometric: the geometric mean

rootmean: the square root of the sum of the squared value

eigen: the individual preference weights are computed using the Dominant Eigenvalues method described in Saaty (2003)

Here I demonstrate the difference of using arithmetic aggregation and dominant eigenvalue methods. In my own testing with real datasets, a much higher proportion of respondents have at least one attribute with a difference larger than 0.05 due to presence of inconsistent and heterogeneous responses.

Aggregated preference weights

The ahp.aggpref function computes the aggregated priorities of all decision-makers using the specified methods. The following arguments are given:

method: Same as ahp.indpref. It normalises the matrices so that all of the columns add up to 1, and then computes the averages of the row as the preference weights of each attribute. Four modes of finding the averages are available:

arithmetic: the arithmetic mean

geometric: the geometric mean

rootmean: the square root of the sum of the squared value

eigen: the individual preference weights are computed using the Dominant Eigenvalues method described in Saaty (2003)

aggmethod: how to aggregate the individual priorities.

arithmetic, geometric and rootmean (same principle as method)

tmean trimmed mea

tgmean trimmed geometric mean

sd returns the standard deviation from the arithmetic mean.

When tmean or tgmean is specified, ahpsurvey needs an additional argument qt, which specifes the quantile which the top and bottom preference weights are trimmed. qt = 0.25 specifies that the aggregation is the arithmetic mean of the values from the 25 to 75 percentile. This visualisation offers researchers a good way to determine the amount of preference weights to be trimmed. By default, qt = 0, hence the result you would get by using tmean and tgmean and not specifying qt is the same as arithmetic and geometric respectively.

Compute the individual priorities of each decision-maker (using method)

Aggregate the priorities (using aggmethod)

By default, the two steps rely on the same aggregation method as specified in method (unless when method = "eigen", where aggmethod defaults to arithmetic). However, it is possible to specify different aggregation methods for the individual and group level. For instance, one can specify that in the individual level, the arithmetic mean is used to compute the individual priorities; the priorities are aggregated using a trimmed mean by trimming observations higher and lower quantile.

Aggregated individual judgements

Similarly, ahp.aggjudge aggregates the individual judgements of all decision-makers to generate a row-standardised pairwise comparison matrix of all decision-makers. This allows one to compare priorities directly based on the aggregated pairwise judgements of all decision-makers. It takes the argument aggmethod with the exact same options as ahp.aggpref.

Measuring and visualising consistency

Measuring consistency

Where \(\lambda_{max}\) is the maximum eigenvalue of the pairwise comparison vector and \(n\) is the number of attributes. The \(RI\) when five attributes are present is 1.11. See the documentation for ahp.ri to generate your own RI based on a specific number of dimensions and random seed.

The RI below was generated from ahp.ri with 500000 simulations (which takes some time), as follows:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

RI

0

0

0.525

0.884

1.11

1.25

1.34

1.41

1.45

1.49

1.51

1.54

1.55

1.57

1.58

Saaty showed that when the \(CR\) is higher than 0.1, the choice is deemed to be inconsistent. The ahpsurvey package allows researchers to quantify the inconsistency among the decision-makers and make decisions in their analysis, either to drop inconsistent observations or look for ways to adjust for inconsistency. As a proof of concept, I use the original weights to compute the consistency ratio, and it returned the value which Saaty got, 0.05.

The processing time of ahp.ri increases exponentially as nsims increase, and unfortunately I haven’t written it to optimise for speed. Generally I wouldn’t go beyond 6 digits of nsims unless I have too much time lying around.

Visualising individual priorities and consistency ratios

The ahp.indpref function provides a detailed account of each individuals’ priorities and its corresponding weighting. An overlay of the violin density, boxplots and jitter plots is useful in visualising the heterogeneity in weights each respondent gives.

Dealing with inconsistent and missing data

Identifying inconsistent pairwise comparisons

Not only are survey designers interested in the level of inconsistency present in their surveys, they are also interested in the source of inconsistency. Are respondents making inconsistent choices because some attributes are ill-defined, or that a pairwise comparison between those attributes simply do not make sense? ahpsurvey provides easy tools for researchers to identify the pairwise comparisons which respondents make inconsistent choices, which could contribute to better survey designs.

The ahp.pwerror compares the pairwise matrix of each individual with a Saaty Matrix (that has the property of \(CR = 0\)) generated using the obtained preference weights. It is always better to understand this with an example.

Where \(p_{i}\) and \(p_{j}\) are the final weights of the \(i^{th}\) and \(j^{th}\) attribute respectively, and \(N\) is the number of attributes.

I am no math major, and I find linear algebra intimidating. Here, I will demonstrate with an example from Saaty’s original matrix how we arrive the consistency error matrix from the original pairwise matrix.

Consider this matrix of the original pairwise comparison and the resultant preference weights below.

The matrix is generated by multiplying its transposed reciprocal version of itself. This is no rocket science – for example, the cult fam comparison is calculated by dividing weight of cult by the weight of fam, 0.152 / 0.433 = 0.351.

The transposed Saaty matrix is multiplied element-by-element with the original pairwise comparison matrix (or taken its reciprocals if the product is smaller than 1) to generate a measure of how well the pairwise matrix resembles the Saaty matrix. If the matrix perfectly resembles the transposed Saaty matrix, the consistency error matrix (shown below) should very close to 1. This matrix is expressed as the following:

\[\epsilon_{ij} = a_{ij}\frac{p_{j}}{p_{i}}\] Where \(a_{ij}\) is the value in the pairwise comparison matrix. The values can be obtained with a simple matrix multiplication of the transpose of \(\mathbf{S}\).

The process is automated in ahp.error. ahp.error also loops through all pairwise comparison matrices generated by ahp.mat, and returns a list of error consistency matrices. The consistency matrices quantifies the inconsistency underlying each pairwise comparison of each decision-maker. I can also use reciprocal = TRUE to put all the errors that are above 1 into the upper triangular matrix. If reciprocal = FALSE, the below output will be essentially the same as the matrix above.

Here I demonstrate how to perform ahp.error in our 200 simulated decision-makers and compute the mean consistency error for each pairwise comparison. By using reciprocal = TRUE, I put all the errors that are above 1 into the upper triangular matrix so that we can summarise (by taking geometric mean) quickly the average error of each pairwise comparison (larger means more error).

The above matrix is a quick way for revealing inconsistencies within the data, but it is not the best way as it can be biased. If one or more decision-maker makes an incredibly inconsistent pairwise comparison, the consistency error for that pairwise comparison will be very high, which biases the mean error consistency of that pairwise comparison upwards even if many other decision-makers are making perfectly consistent choices.

Finding inconsistent pairwise comparisons by maximum

A better way, as I reckon, would be to extract the pairwise comparison with the maximum inconsistency error, and returning a list of the most inconsistent pairwise comparisons for each decision-maker. This process is automated in the ahp.pwerror function, which returns a dataframe of the top three most inconsistent pairwise comparison made by each decision-maker.

## Warning: attributes are not identical across measure variables;
## they will be dropped

Pairwise comparison and its frequency as the most, second-most, and third most inconsistent pairwise comparsion

The results are favorable – the frequency which a pairwise comparison is the most inconsistent for that decision-maker is reflective of the degree of randomness I have used to generate the dataset. The cult_fam, cult_jobs and fam_trans are assigned the highest standard deviations for the normal random draw, which partly contributes to its high frequency of being in the most inconsistent pairwise comparison in the chart.

Transforming inconsistent matrices

Inconsistent pairwise matrices are problematic for AHP survey analysts. Harker (1987) described a method to replace inconsistent values: using the error matrix we have derived above, we can suggest a value that would reduce the inconsistency. Consider the below pairwise matrix found in Saaty’s explication of Harker’s method:

As seen here, element [3,7] is the most inconsistent pairwise comparison, thus it was replaced with a more consistent value 0.459.

ahp.harker takes five optional arguments:

round is logical and tells ahp.harker whether to convert the newly replaced values to integers and its reciprocals, and can be set to TRUE if desired.

iterations denotes how many pairwise comparisons should be changed. For example, if iterations = 3, ahp.harker changes the first, second, and third most inconsistent pairwise comparisons using that method. Researchers should think carefully how many pairwise comparisons should be replaced, as every time a pairwise comparison is replaced, some information is inevitably lost. Note that the maximum number of iterations is capped at \(iterations \leq \frac{1}{2}n(n-1)\) with \(n\) being the number of attributes.

stopcr: The stopping Consistency Ratio. It complements iterations by giving iterations a criteria to stop when a matrix is sufficiently consistent. ahp.harker will continue looping and replacing more elements of the pairwise comparison matrices until the consistency ratio of the new matrix is lower than stopcr, or the maximum number of iterations is reached, and will stop and move onto the next individual. When stopcr is set, the number of replaced elements will differ amongst each decision-maker. Thus, it is advised that the analyst set printiter = TRUE to see how many iterations has the pairwise matrix of that individual has been modified by the algorithm.

limit: In many cases, the algorithm will intend to replace a value with a number higher than 9 or lower than 1/9. limit caps the maximum and minimum value of the replacement to 9 and 1/9 respectively.

printiter is a logical argument of whether the number of iterations taken for each pairwise matrix is reported or not. Generally it is not needed if stopcr is not specified. When stopcr is specified, this is a good way of identifying how many pairwise comparisons are actually replaced by the algorithm for each decision maker. The printout above shows "Ind 1 Iterations: 1", which shows that although I specified iterations = 10, individual 1 (Ind 1) was only iterated one time before it reached the target consistency ratio, 0.1. Only one element was replaced.

I will demonstrate how ahp.harker improved the consistency of the decision-makers in our fictitious sample.

While using Harker’s method cannot completely lower the CR of all decision-makers to desired levels, it allows researchers to keep a lot more observations; whereas we would have to truncate 70 samples, now we only have to censor 22 samples with 1 iteration.

Here I present the aggregated weights of the pairwise matrices without and with treatment with Harker’s method, the aggregated priorities derived from the true weights of the sample, as well as the deviation of the priorities from the true weights. Because improving the consistency of the matrix does not necessarily increase the validity of the matrix, it is imperative that researchers consider other ways to improve consistency, ideally asking respondents to reconsider their choices, whenever inconsistency arises.

While there are strong arguments against replacing inconsistent values without the decision-maker’s consent for the sake of satisfying the consistency ratio criterion of CR < 0.1 (see Saaty and Tran (2007)), it is often not possible for survey executers to resolicit answers from their respondents after AHP analysis, whereas truncating inconsistent decisions may make the dataset unrepresentative of the population. Researchers should think carefully and explain fully the methods used to process AHP data.

Imputing missing pairwise comparison matrices

Missing data is a common feature in surveys. Harker’s method was originally developed to complete incomplete pairwise comparison matrices, and can be implemented here using the same strategy as ahp.harker.

Here, similar to ahp.harker, ahp.missing replaces the NA values in the pairwise comparison matrices with the most consistent pairwise choice available, thus the consistency ratio is increased after imputing missing values. The randomness and inconsistency of each decision-maker cannot be accounted for in the algorithm. Missing value imputation should be avoided whenever possible, but is a valid alternative if missing values are reasonably small in number.

AHP on steroids: a canned routine

As of version 0.3.0, you can quickly execute most of the functions described in this vignette with a canned routine. Here I demonstrate how the city200 dataset is processed using the AHP to output the aggregated and individual priorities of individuals, using the simplest arithmetic mean method.

You can also see clearly the individual priorities calculated using the arithmetic mean method, the consistency ratio of each individual, and which three pairwise comparisons are the most inconsistent.

You can also quickly censor inconsistent observations and estimate the aggregated preference weight of the population, and its standard deviation. The unique command here in this canned routine is censorcr, where you may specify the consistency ratio censoring threshold, which allows you to remove observations a higher consistency ratio than you specified. Usually, researchers censor observations with a CR higher than 0.1. But sometimes it is different depending on your discipline. Note that specifying qt only affects aggpref calculation, and does not censor the observations in $indpref.

For many researchers, it would be useful if an ID identifier was included in the input dataframe, so that one can directly join the output to the existing dataset for further analysis. For example, here in this case the data in city200 was coded with the name of an individual and their educational attainment. By specifying ID, I can retain a column or many columns containing an inidviduals’ characteristics, and extract their preferences by educational attainment.

To add a bit of flavour to this example, I am going to use a package called randomNames that can be installed from CRAN by Betebenner (2017).

Here we have created a fictitious sample of the population with their pairwise comparisons of which city to live in. We can specify which columns to keep. We can also specify how the pairwise comparisons were ordered directly to the AHP routine so that it saves you a step from extracting the columns you need in the order you want.

Oops! There seems to be an irrelevant catowner column (that I’ve added) that you just want the routine to ignore. Fortunately, we could avoid this error by directly specifying the names and order of the columns that contain the pairwise comparisons using the col argument. The col argument also reorders your data.frame so that you don’t have to do it manually if you want.

Appendix I: data generation process

The dataset city200 is generated based on Saaty’s example of choosing a city to live in described in Saaty (2004). I recreated Saaty’s example of criteria weights by simulating 200 decision-makers who make their choices based on the underlying true weights. The dataset is generated using a normal random sample from the Saaty scale with the mean set as the true weight and the standard deviation set manually. With a higher standard deviation, it is expected that the pairwise comparison will be less consistent. The methods employed later will reveal which pairwise comparison is less consistent than others.

Here, we have simulated the responses of 200 individual decision-makers regarding the attributes they consider when deciding which city to live in, based on the true weights from Saaty’s journal article, with some added random deviations from the weight.