Type: | Package |
Title: | Analytic Hierarchy Process for Survey Data |
Version: | 0.4.1 |
Description: | The Analytic Hierarchy Process is a versatile multi-criteria decision-making tool introduced by Saaty (1987) <doi:10.1016/0270-0255(87)90473-8> that allows decision-makers to weigh attributes and evaluate alternatives presented to them. This package provides a consistent methodology for researchers to reformat data and run analytic hierarchy process in R on data that are formatted using the survey data entry mode. It is optimized for performing the analytic hierarchy process with many decision-makers, and provides tools and options for researchers to aggregate individual preferences and test multiple options. It also allows researchers to quantify, visualize and correct for inconsistency in the decision-maker's comparisons. |
License: | MIT + file LICENSE |
Encoding: | UTF-8 |
LazyData: | true |
RoxygenNote: | 7.0.1 |
Imports: | Rdpack, stats, magrittr, knitr, tidyr, dplyr, randomNames |
Suggests: | ggplot2, scales |
RdMacros: | Rdpack |
Collate: | 'ahp_mat.R' 'ahp_indpref.R' 'ahp_pwerror.R' 'ahp_cr.R' 'ahp.R' 'ahp_RI.R' 'ahp_aggjudge.R' 'ahp_aggpref.R' 'ahp_bweight.R' 'ahp_error.R' 'ahp_harker.R' 'ahp_missing.R' 'ahpsurvey.R' 'data.R' |
VignetteBuilder: | knitr |
NeedsCompilation: | no |
Packaged: | 2019-11-24 15:56:21 UTC; chohinting |
Author: | Frankie Cho [aut, cre] |
Maintainer: | Frankie Cho <htcho@connect.hku.hk> |
Repository: | CRAN |
Date/Publication: | 2019-11-24 16:10:02 UTC |
Canned routine for AHP
Description
ahp
is a canned routine that returns a data.frame
of individuals' priorities (based on ahp.indpref), number of missing values, consistency ratios, and top three pairs of inconsistent pairwise comparisons. An optional argument agg
allows the user to generate a data.frame of aggregated priorities alongside individual priorities.
Usage
ahp(
df,
atts,
negconvert = FALSE,
reciprocal = TRUE,
method = "eigen",
aggmethod = "geometric",
qt = 0,
censorcr = Inf,
agg = FALSE,
ID = NULL,
col = NULL,
suppress = "none"
)
Arguments
df |
a dataframe, each row corresponding to one decision-maker, with columns ordered according to |
atts |
a list of attributes in the correct order |
negconvert |
logical, whether to convert all positive values to
negative. In the pairwise comparison A_B, if -6 denotes A is more
important than B by 6 units, set |
reciprocal |
logical, whether to convert negative values (after |
method |
if |
aggmethod |
how to aggregate the individual priorities. By default |
qt |
specifies the quantile which the top and bottom priority weights are trimmed. Used only if |
censorcr |
the threshold of censoring observations. All observations with a consistency ratio higher than the specified CR will be dropped from the routine. By default, |
agg |
by default, |
ID |
the column name, or a vector of column names, of variables in |
col |
a list of column names which contains the columns for the pairwise comparison matrix in chronological order, as specified in |
suppress |
Suppresses the supplementary indices. Can take the values of "all" (suppresses all indices), "pwerror" (suppresses pwerror), or "cr" (suppresses consistency ratio). |
Value
If agg = TRUE
, returns a list of the results with two elements, indpref
and aggpref
. $indpref
contains individual preference weight (same as ahp.indpref
), consistency ratios, and the top three most inconsistent pairwise comparisons (same as ahp.pwerror
). $aggpref
contains the Aggregated Priorities and Standard Deviations. Otherwise (i.e. default setting), outputs a data.frame
with only $indpref
.
Author(s)
Frankie Cho
References
Saaty TL (2004). “Decision making — the Analytic Hierarchy and Network Processes (AHP/ANP).” Journal of Systems Science and Systems Engineering, 13(1), 1–35. ISSN 1861-9576, doi: 10.1007/s11518-006-0151-5, https://doi.org/10.1007/s11518-006-0151-5.
Examples
data(city200)
ahp(df = city200, atts = c('cult', 'fam', 'house', 'jobs', 'trans'), negconvert = TRUE)
Aggregate individual judgments
Description
Aggregate individual judgments from pairwise comparison matrices
Usage
ahp.aggjudge(ahpmat, atts, aggmethod = "geometric", qt = 0)
Arguments
ahpmat |
A list of pairwise comparison matrices of each decision maker generated by |
atts |
a list of attributes in the correct order |
aggmethod |
The method of aggregating the judgments by all decision-makers. Five modes aggregation are available: |
qt |
specifies the quantile which the top and bottom priority weights are trimmed. Used only if |
Value
A data.frame
of the aggregated pairwise judgments of all the decision-makers.
Author(s)
Frankie Cho
Examples
## Computes individual judgments with geometric mean and aggregates them
## with a trimmed arithmetic mean
data(city200)
atts <- c('cult', 'fam', 'house', 'jobs', 'trans')
cityahp <- ahp.mat(df = city200, atts = atts, negconvert = TRUE)
ahp.aggjudge(cityahp, atts, aggmethod = 'tmean', qt = 0.1)
Aggregate priority weights
Description
Compute and aggregate individual priority weights from pairwise comparison matrices
Usage
ahp.aggpref(ahpmat, atts, method = "geometric", aggmethod = method, qt = 0)
Arguments
ahpmat |
A list of pairwise comparison matrices of each decision maker generated by |
atts |
a list of attributes in the correct order |
method |
if |
aggmethod |
how to aggregate the individual priorities. By default |
qt |
specifies the quantile which the top and bottom priority weights are trimmed. Used only if |
Value
A data.frame
of the aggregated priorities of all the decision-makers.
Author(s)
Frankie Cho
References
Saaty TL (2003). “Decision-making with the AHP: Why is the principal eigenvector necessary.” European Journal of Operational Research, 145(1), 85 - 91. ISSN 0377-2217, http://www.sciencedirect.com/science/article/pii/S0377221702002278.
Examples
## Computes individual priorities with geometric mean and aggregates them
## with a trimmed arithmetic mean
library(magrittr)
data(city200)
atts <- c('cult', 'fam', 'house', 'jobs', 'trans')
cityahp <- ahp.mat(df = city200, atts = atts, negconvert = TRUE)
ahp.aggpref(cityahp, atts, method = 'geometric', aggmethod = 'tmean', qt = 0.1)
Calculates the consistency ratio of each decision-maker
Description
The ahp.cr
function calculates the consistency ratio of each decision-maker, defined by the following equation:
CR = (\lambda-n)/((n-1)(RI))
Where \lambda
is the maximum eigenvalue of the pairwise comparison matrix, n
is the number of attributes, and RI is the random index. Following Saaty and Tran (2007), the RI is a function of n
and is the consistency ratio of randomly generated pairwise comparison matrices.
Usage
ahp.cr(ahpmat, atts, ri = NULL)
Arguments
ahpmat |
A list of pairwise comparison matrices of each decision maker generated by |
atts |
a list of attributes in the correct order. The RI is asymptotic as it approaches n=15, thus it is set to be equal to 1.6 if the number of attributes exceeds 16. |
ri |
A user-supplied random index value, probably user generated using |
Value
A list
of consistency ratios of each decision-maker.
Author(s)
Frankie Cho
References
Saaty TL, Tran LT (2007). “On the invalidity of fuzzifying numerical judgments in the Analytic Hierarchy Process.” Mathematical and Computer Modelling, 46(7), 962 - 975. ISSN 0895-7177, Decision Making with the Analytic Hierarchy Process and the Analytic Network Process, http://www.sciencedirect.com/science/article/pii/S0895717707000787.
Examples
data(city200)
atts <- c('cult', 'fam', 'house', 'jobs', 'trans')
cityahp <- ahp.mat(df = city200, atts = atts, negconvert = TRUE)
ahp.cr(cityahp, atts)
Matrix of the product between the pairwise comparison value and pj/pi
Description
Consider the comparison matrix where element a_{ij}
contains the pairwise comparison between the attributes i and j. The weights of the matrix was constructed as in agg.indpref
using the Perron eigenvector where p_{i}
and p_{j}
are the weights of the i^{th}
and the j^{th}
element respectively. ahp.error
constructs a matrix \epsilon_{ij} = a_{ij}p_{j}/p_{i}
.
Usage
ahp.error(ahpmat, atts, reciprocal = FALSE)
Arguments
ahpmat |
A list of pairwise comparison matrices of each decision maker generated by |
atts |
a list of attributes in the correct order |
reciprocal |
whether to remove all numbers lower than 1 and put all numbers above 1 in the upper triangular matrix. Useful for visualizing the inconsistency rapidly. |
Value
A list of matrices containing \epsilon_{ij} = a_{ij}p_{j}/p_{i}
for each decision-maker, with elements from the lower triangle set as NA automatically (since it is essentially equal to the element in the upper triangle).
Author(s)
Frankie Cho
References
Saaty TL (2004). “Decision making — the Analytic Hierarchy and Network Processes (AHP/ANP).” Journal of Systems Science and Systems Engineering, 13(1), 1–35. ISSN 1861-9576, doi: 10.1007/s11518-006-0151-5, https://doi.org/10.1007/s11518-006-0151-5.
Examples
atts <- c('cult', 'fam', 'house', 'jobs', 'trans')
data(city200)
cityahp <- ahp.mat(city200, atts, negconvert = TRUE)
ahp.error(cityahp, atts)
Replace inconsistent pairwise comparisons
Description
Based on the matrix derived from ahp.error
, replaces the top n
number of inconsistent pairwise comparisons with a value calculated by from the method in Harker (1987). 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 consistency ratio < 0.1 (see Saaty and Tran (2007)), it is often not possible for enumerators to ask respondents to change their answers based on consistency, 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, and whenever possible, use a lower number of iterations.
Usage
ahp.harker(
ahpmat,
atts,
round = FALSE,
limit = FALSE,
iterations = 1,
stopcr = 0,
printiter = TRUE
)
Arguments
ahpmat |
A list of pairwise comparison matrices of each decision maker generated by |
atts |
A list of attributes in the correct order |
round |
Rounds the imputation values of the matrix to the nearest integer if |
limit |
If set to |
iterations |
The number of comparisons with the highest inconsistency to be changed. For example, if |
stopcr |
The stopping Consistency Ratio, which was calculated by |
printiter |
Whether the number of iterations taken for each pairwise matrix is reported or not. If |
Value
A list of matrices with values replaced with consistent values.
Author(s)
Frankie Cho
References
Harker P (1987).
“Incomplete pairwise comparisons in the analytic hierarchy process.”
Mathematical Modelling, 9(11), 837 - 848.
ISSN 0270-0255, http://www.sciencedirect.com/science/article/pii/0270025587905033.
Saaty TL, Tran LT (2007).
“On the invalidity of fuzzifying numerical judgments in the Analytic Hierarchy Process.”
Mathematical and Computer Modelling, 46(7), 962 - 975.
ISSN 0895-7177, Decision Making with the Analytic Hierarchy Process and the Analytic Network Process, http://www.sciencedirect.com/science/article/pii/S0895717707000787.
See Also
ahp.error ahp.cr
Examples
atts <- c('cult', 'fam', 'house', 'jobs', 'trans')
data(city200)
cityahp <- ahp.mat(city200, atts, negconvert = TRUE)
ahp.harker(cityahp, atts)
Computes priority weights of individual decision-makers
Description
ahp.indpref
computes the individual priorities of the decision-makers, and returns a data.frame
containing the priority weights of the decision-makers.
Usage
ahp.indpref(ahpmat, atts, method = "geometric")
Arguments
ahpmat |
A list of pairwise comparison matrices of each decision maker generated by |
atts |
a list of attributes in the correct order |
method |
if |
Value
A data.frame
of the individual priorities of all the decision-makers.
Author(s)
Frankie Cho
References
Saaty TL (2003). “Decision-making with the AHP: Why is the principal eigenvector necessary.” European Journal of Operational Research, 145(1), 85 - 91. ISSN 0377-2217, http://www.sciencedirect.com/science/article/pii/S0377221702002278.
Examples
data(city200)
atts <- c('cult', 'fam', 'house', 'jobs', 'trans')
cityahp <- ahp.mat(df = city200, atts = atts, negconvert = TRUE)
ahp.indpref(cityahp, atts, method = "eigen")
Generate AHP pairwise matrices from survey data
Description
ahp.mat
takes in paired comparisons from survey data with questions using the
analytic hierarchy process and converts it into pairwise comparison matrices
for each individual decision-maker. Examples based on Saaty (2004).
Usage
ahp.mat(df, atts, negconvert = FALSE, reciprocal = TRUE)
Arguments
df |
a dataframe, each row corresponding to one decision-maker, with columns ordered according to |
atts |
a list of attributes in the correct order |
negconvert |
logical, whether to convert all positive values to
negative. In the pairwise comparison A_B, if -6 denotes A is more
important than B by 6 units, set |
reciprocal |
logical, whether to convert negative values (after |
Value
A list of pairwise comparison matrices of each decision-maker.
Author(s)
Frankie Cho
References
Saaty TL (2004). “Decision making — the Analytic Hierarchy and Network Processes (AHP/ANP).” Journal of Systems Science and Systems Engineering, 13(1), 1–35. ISSN 1861-9576, doi: 10.1007/s11518-006-0151-5, https://doi.org/10.1007/s11518-006-0151-5.
Examples
data(city200)
atts <- c('cult', 'fam', 'house', 'jobs', 'trans')
ahp.mat(df = city200, atts = atts, negconvert = TRUE)
Impute missing observations using the method in Harker (1987)
Description
Imputes the missing values of a list of matrices produced by ahp.mat
using the methods and assumptions made in Harker (1987). Missing values must be coded as NA
. As suggested in Harker (1987), a minimum of n-1 comparisons must be made, where n is the number of attributes (assuming that the decision-maker is perfectly consistent). Note that the algorithm assumes that the NA values will be imputed under perfect consistency with the other pairwise comparisons made.
Usage
ahp.missing(ahpmat, atts, round = FALSE, limit = FALSE)
Arguments
ahpmat |
A list of pairwise comparison matrices of each decision maker generated by |
atts |
A list of attributes in the correct order |
round |
Rounds the imputation values of the matrix to the nearest integer if |
limit |
If set to |
Value
A list of matrices with all NA
values imputed.
Author(s)
Frankie Cho
References
Harker P (1987). “Incomplete pairwise comparisons in the analytic hierarchy process.” Mathematical Modelling, 9(11), 837 - 848. ISSN 0270-0255, http://www.sciencedirect.com/science/article/pii/0270025587905033.
Examples
library(magrittr)
atts <- c('cult', 'fam', 'house', 'jobs', 'trans')
data(city200)
set.seed(42)
## Make a dataframe that is missing at random
missing.df <- city200[1:10,]
for (i in 1:10){
missing.df[i, round(stats::runif(1,1,10))] <- NA
}
missingahp <- ahp.mat(missing.df, atts, negconvert = TRUE)
ahp.missing(missingahp, atts)
Finds the pairwise comparisons with the maximum amount of inconsistency
Description
After constructing a list of matrices with \epsilon_{ij} = a_{ij}w_{j}/w_{i}
(following ahp.error
), this algorithm extracts the top n
numbers of pairwise comparison matrices with the highest \epsilon_{ij}
for each decision-maker.
Usage
ahp.pwerror(ahpmat, atts, npw = 3)
Arguments
ahpmat |
A list of pairwise comparison matrices of each decision maker generated by |
atts |
a list of attributes in the correct order |
npw |
Number of pairwise comparisons |
Value
A list of matrices containing \epsilon_{ij} = a_{ij}w_{j}/w_{i}
for each decision-maker, with elements from the lower triangle set as NA automatically (since it is essentially equal to the element in the upper triangle).
Author(s)
Frankie Cho
References
Saaty TL (2004). “Decision making — the Analytic Hierarchy and Network Processes (AHP/ANP).” Journal of Systems Science and Systems Engineering, 13(1), 1–35. ISSN 1861-9576, doi: 10.1007/s11518-006-0151-5, https://doi.org/10.1007/s11518-006-0151-5.
Examples
library(magrittr)
atts <- c('cult', 'fam', 'house', 'jobs', 'trans')
data(city200)
cityahp <- ahp.mat(city200, atts, negconvert = TRUE)
ahp.error(cityahp, atts)
Generate random indices
Description
The ahp.ri
function calculates the mean consistency indices of a specific numbers of random number pairwise comparison matrices.
The random index of one pairwise comparison matrix is given as below, where lambda
is the maximum eigenvalue and n
is the number of attributes.
RI = (\lambda-n)/((n-1)
ahp.ri
creates nsims
number of pairwise comparison matrices with number of dimensions=dim
, and returns its average.
Usage
ahp.ri(nsims, dim, seed = 42)
Arguments
nsims |
Number of random pairwise comparison matrices to be generated. Processing time increases substantially with higher |
dim |
Number of dimensions of the matrix. |
seed |
The random number generator seed for reproducibility, which is same as |
Value
The generated random index, which is numeric.
Author(s)
Frankie Cho
Examples
ahp.ri(nsims = 10000, dim = 5, seed = 42)
AHP Survey package
Description
The ahpsurvey
package provides a workflow for researchers to reformat data and run analytic hierarchy process on data that are originally formatted using the survey data entry mode. A diversified toolbox is available for researchers to explore ways to impute missing pairwise comparisons or to adjust comparisons based on consistency, and to conveniently customize the methods which weights derived from surveys are extracted and aggregated.
Author(s)
Frankie Cho htcho@connnect.hku.hk
Dataframe of one decision-maker based on Saaty (2004)
Description
A data.frame of one decision-maker with weights the same as Saaty (2004), with the pairwise comparisons of atts
: c('cult', 'fam', 'house', 'jobs', 'trans')
, about a choosing the best city to live in based on five attributes: Culture, Family, House, Jobs, and Transportation. Negative values in the data denote that the attribute on the left is more important than the right, thus if used with ahp.mat
, negconvert
must be set to TRUE
.
Usage
data(city1)
Format
A data frame with 1 row and 10 variables, which are pairwise comparisons of atts
.
Source
Saaty (2004)
A dataframe of 200 simulated decision-makers based on Saaty (2004)
Description
A data.frame of one decision-maker with weights the same as Saaty (2004), with the pairwise comparisons of atts
: c('cult', 'fam', 'house', 'jobs', 'trans')
, about a choosing the best city to live in based on five attributes: Culture, Family, House, Jobs, and Transportation. The choices of 200 decision-makers are simulated based on the underlying weights and randomness generated by a normal random distribution. The true weights are stored in data(city1)
. The normal random distribution was set with a mean at the true weight value and a standard deviation of 2,1,2,1.5,2,1.5,2.5,0.5,0.5,1
in chronological order of the columns in city200
.
Usage
data(city200)
Format
A data.frame
with 200 row and 10 variables, which are pairwise comparisons of atts
.
Source
Saaty TL (2004). “Decision making — the Analytic Hierarchy and Network Processes (AHP/ANP).” Journal of Systems Science and Systems Engineering, 13(1), 1–35. ISSN 1861-9576, doi: 10.1007/s11518-006-0151-5, https://doi.org/10.1007/s11518-006-0151-5.