Title: | Analytic Hierarchy Process for Survey Data |
---|---|
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. |
Authors: | Frankie Cho [aut, cre] |
Maintainer: | Frankie Cho <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.4.2 |
Built: | 2025-02-21 04:15:54 UTC |
Source: | https://github.com/frankiecho/ahpsurvey |
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.
ahp( df, atts, negconvert = FALSE, reciprocal = TRUE, method = "eigen", aggmethod = "geometric", qt = 0, censorcr = Inf, agg = FALSE, ID = NULL, col = NULL, suppress = "none" )
ahp( df, atts, negconvert = FALSE, reciprocal = TRUE, method = "eigen", aggmethod = "geometric", qt = 0, censorcr = Inf, agg = FALSE, ID = NULL, col = NULL, suppress = "none" )
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). |
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
.
Frankie Cho
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.
data(city200) ahp(df = city200, atts = c('cult', 'fam', 'house', 'jobs', 'trans'), negconvert = TRUE)
data(city200) ahp(df = city200, atts = c('cult', 'fam', 'house', 'jobs', 'trans'), negconvert = TRUE)
Aggregate individual judgments from pairwise comparison matrices
ahp.aggjudge(ahpmat, atts, aggmethod = "geometric", qt = 0)
ahp.aggjudge(ahpmat, atts, aggmethod = "geometric", qt = 0)
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 |
A data.frame
of the aggregated pairwise judgments of all the decision-makers.
Frankie Cho
## 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)
## 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)
Compute and aggregate individual priority weights from pairwise comparison matrices
ahp.aggpref(ahpmat, atts, method = "geometric", aggmethod = method, qt = 0)
ahp.aggpref(ahpmat, atts, method = "geometric", aggmethod = method, qt = 0)
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 |
A data.frame
of the aggregated priorities of all the decision-makers.
Frankie Cho
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.
## 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)
## 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)
The ahp.cr
function calculates the consistency ratio of each decision-maker, defined by the following equation:
Where is the maximum eigenvalue of the pairwise comparison matrix,
is the number of attributes, and RI is the random index. Following Saaty and Tran (2007), the RI is a function of
and is the consistency ratio of randomly generated pairwise comparison matrices.
ahp.cr(ahpmat, atts, ri = NULL)
ahp.cr(ahpmat, atts, ri = NULL)
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 |
A list
of consistency ratios of each decision-maker.
Frankie Cho
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.
data(city200) atts <- c('cult', 'fam', 'house', 'jobs', 'trans') cityahp <- ahp.mat(df = city200, atts = atts, negconvert = TRUE) ahp.cr(cityahp, atts)
data(city200) atts <- c('cult', 'fam', 'house', 'jobs', 'trans') cityahp <- ahp.mat(df = city200, atts = atts, negconvert = TRUE) ahp.cr(cityahp, atts)
Consider the comparison matrix where element 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 and
are the weights of the
and the
element respectively.
ahp.error
constructs a matrix .
ahp.error(ahpmat, atts, reciprocal = FALSE)
ahp.error(ahpmat, atts, reciprocal = FALSE)
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. |
A list of matrices containing 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).
Frankie Cho
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.
atts <- c('cult', 'fam', 'house', 'jobs', 'trans') data(city200) cityahp <- ahp.mat(city200, atts, negconvert = TRUE) ahp.error(cityahp, atts)
atts <- c('cult', 'fam', 'house', 'jobs', 'trans') data(city200) cityahp <- ahp.mat(city200, atts, negconvert = TRUE) ahp.error(cityahp, atts)
Deprecated in version 0.4.2. Use ahp.md
instead, which contains exactly the same functionality but with the correct name of the algorithm.
ahp.harker( ahpmat, atts, round = FALSE, limit = FALSE, iterations = 1, stopcr = 0, printiter = TRUE )
ahp.harker( ahpmat, atts, round = FALSE, limit = FALSE, iterations = 1, stopcr = 0, printiter = TRUE )
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 |
A list of matrices with values replaced with consistent values.
Frankie Cho
There are no references for Rd macro \insertAllCites
on this help page.
ahp.error ahp.cr
atts <- c('cult', 'fam', 'house', 'jobs', 'trans') data(city200) cityahp <- ahp.mat(city200, atts, negconvert = TRUE) ahp.md(cityahp, atts)
atts <- c('cult', 'fam', 'house', 'jobs', 'trans') data(city200) cityahp <- ahp.mat(city200, atts, negconvert = TRUE) ahp.md(cityahp, atts)
ahp.indpref
computes the individual priorities of the decision-makers, and returns a data.frame
containing the priority weights of the decision-makers.
ahp.indpref(ahpmat, atts, method = "geometric")
ahp.indpref(ahpmat, atts, method = "geometric")
ahpmat |
A list of pairwise comparison matrices of each decision maker generated by |
atts |
a list of attributes in the correct order |
method |
if |
A data.frame
of the individual priorities of all the decision-makers.
Frankie Cho
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.
data(city200) atts <- c('cult', 'fam', 'house', 'jobs', 'trans') cityahp <- ahp.mat(df = city200, atts = atts, negconvert = TRUE) ahp.indpref(cityahp, atts, method = "eigen")
data(city200) atts <- c('cult', 'fam', 'house', 'jobs', 'trans') cityahp <- ahp.mat(df = city200, atts = atts, negconvert = TRUE) ahp.indpref(cityahp, atts, method = "eigen")
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).
ahp.mat(df, atts, negconvert = FALSE, reciprocal = TRUE)
ahp.mat(df, atts, negconvert = FALSE, reciprocal = TRUE)
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 |
A list of pairwise comparison matrices of each decision-maker.
Frankie Cho
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.
data(city200) atts <- c('cult', 'fam', 'house', 'jobs', 'trans') ahp.mat(df = city200, atts = atts, negconvert = TRUE)
data(city200) atts <- c('cult', 'fam', 'house', 'jobs', 'trans') ahp.mat(df = city200, atts = atts, negconvert = TRUE)
Based on the matrix derived from ahp.error
, replaces the top n
number of inconsistent pairwise comparisons with a value calculated by from the maximum deviation method. For a full explication of the method see Saaty (2003). Replaces the old ahp.harker
function before 0.4.2 but contains exactly the same functionality.
ahp.md( ahpmat, atts, round = FALSE, limit = FALSE, iterations = 1, stopcr = 0, printiter = TRUE )
ahp.md( ahpmat, atts, round = FALSE, limit = FALSE, iterations = 1, stopcr = 0, printiter = TRUE )
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 |
A list of matrices with values replaced with consistent values.
Frankie Cho
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.
ahp.error ahp.cr
atts <- c('cult', 'fam', 'house', 'jobs', 'trans') data(city200) cityahp <- ahp.mat(city200, atts, negconvert = TRUE) ahp.md(cityahp, atts)
atts <- c('cult', 'fam', 'house', 'jobs', 'trans') data(city200) cityahp <- ahp.mat(city200, atts, negconvert = TRUE) ahp.md(cityahp, atts)
Imputes the missing values of a list of matrices produced by ahp.mat
using the maximum deviation method. Missing values must be coded as NA
. 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.
ahp.missing(ahpmat, atts, round = FALSE, limit = FALSE)
ahp.missing(ahpmat, atts, round = FALSE, limit = FALSE)
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 |
A list of matrices with all NA
values imputed.
Frankie Cho
There are no references for Rd macro \insertAllCites
on this help page.
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)
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)
After constructing a list of matrices with (following
ahp.error
), this algorithm extracts the top n
numbers of pairwise comparison matrices with the highest for each decision-maker.
ahp.pwerror(ahpmat, atts, npw = 3)
ahp.pwerror(ahpmat, atts, npw = 3)
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 |
A list of matrices containing 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).
Frankie Cho
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.
library(magrittr) atts <- c('cult', 'fam', 'house', 'jobs', 'trans') data(city200) cityahp <- ahp.mat(city200, atts, negconvert = TRUE) ahp.error(cityahp, atts)
library(magrittr) atts <- c('cult', 'fam', 'house', 'jobs', 'trans') data(city200) cityahp <- ahp.mat(city200, atts, negconvert = TRUE) ahp.error(cityahp, atts)
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 is the maximum eigenvalue and
is the number of attributes.
ahp.ri
creates nsims
number of pairwise comparison matrices with number of dimensions=dim
, and returns its average.
ahp.ri(nsims, dim, seed = 42)
ahp.ri(nsims, dim, seed = 42)
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 |
The generated random index, which is numeric.
Frankie Cho
ahp.ri(nsims = 10000, dim = 5, seed = 42)
ahp.ri(nsims = 10000, dim = 5, seed = 42)
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.
Frankie Cho [email protected]
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
.
data(city1)
data(city1)
A data frame with 1 row and 10 variables, which are pairwise comparisons of atts
.
Saaty (2004)
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
.
data(city200)
data(city200)
A data.frame
with 200 row and 10 variables, which are pairwise comparisons of atts
.
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.