Package 'AHPWR'

Title: Compute Analytic Hierarchy Process
Description: Compute a tree level hierarchy, judgment matrix, consistency index and ratio, priority vectors, hierarchic synthesis and rank. Based on the book entitled "Models, Methods, Concepts and Applications of the Analytic Hierarchy Process" by Saaty and Vargas (2012, ISBN 978-1-4614-3597-6).
Authors: Luciane Ferreira Alcoforado [aut, cre], Lyncoln Sousa [aut], Orlando Celso Longo [aut], Alessandra Simão [ctb], Steven Dutt Ross [ctb], Leonardo Filgueira [ctb]
Maintainer: Luciane Ferreira Alcoforado <[email protected]>
License: GPL-3
Version: 0.1.0
Built: 2024-11-01 06:31:28 UTC
Source: CRAN

Help Index


Calculates the AHP

Description

Calculates AHP in a list of paired arrays or in a properly formatted excel worksheet stipend.

Usage

ahp(base, mapeamento, nomes_alternativas)

Arguments

base

List of paired arrays or excel path containing the properly formatted paired arrays.

mapeamento

Vector containing the number of subscriptions of each criteria, from left to right. mapeamento = rep(0,n) n = number of criteria and no subcriteria; mapeamento = c(1,2) for one subcriteria in criteria 1 anda two subcriteria in criteria 2. If in doubt, see the tutorial vignette.

nomes_alternativas

Vector containing the names of the alternatives in your hierarchy, if not filled returns a vector of LETTERS.

Value

Table containing the relationships of criteria, subscriptions (If any) and Alternatives Using the AHP system.

Author(s)

Lyncoln Oliveira and Luciane Ferreira Alcoforado

Examples

x=paste0(letters[3],1:5)
y=c(5,2,7,3,2)
m1=matrix_ahp(x,y)
x=paste0(letters[1],1:3)
y=c(4.4,5.2,3)
m2=matrix_ahp(x,y)
y=c(2,4,3)
m3=matrix_ahp(x,y)
y=c(4.9,5,3.3)
m4=matrix_ahp(x,y)
y=c(4.4,4.2,4.3)
m5=matrix_ahp(x,y)
y=c(5.4,5.2,5.7)
m6=matrix_ahp(x,y)
base=list(m1, m2, m3, m4, m5, m6)
mapeamento = rep(0,5)
nomes_alternativas = paste0(letters[1],1:3)
ahp(base,mapeamento, nomes_alternativas)

#with subcriteria and 3 criteria and 2 alternatives
mapeamento = c(2,0,0) #2 subcriteria in criteria 1 and 0 subcriteria to others
x=paste0(letters[3],1:3) #3 criteria
y=c(5,2,7)
m1=matrix_ahp(x,y) #compare criteria
x=paste0(letters[4],1:2)
y=c(4,6)
m2=matrix_ahp(x,y) # 2 compare 2 subcriteria of criteria 1
x=paste0(letters[1],1:2)
y=c(2,4)
m3=matrix_ahp(x,y) #alternatives for subcriteria 1
y=c(4.9,5)
m4=matrix_ahp(x,y) #alternatives for subcriteria 2
y=c(4.4,4.2)
m5=matrix_ahp(x,y) #alternatives for criteria 2
y=c(5.4,5.2)
m6=matrix_ahp(x,y) ##alternatives for criteria 3
base=list(m1, m2, m3, m4, m5, m6)

nomes_alternativas = paste0(letters[1],1:2)
ahp(base,mapeamento, nomes_alternativas)

#Other mapeamento: criteria 2 with 2 subcriteria

mapeamento = c(0,2,0)
nomes_alternativas = paste0(letters[1],1:2)
ahp(base,mapeamento, nomes_alternativas)

Calculates the AHP General

Description

Calculates AHP in a list of paired arrays or in a properly formatted excel worksheet stipend.

Usage

ahp_geral(objeto, mapeamento = "PADRAO", nomes_alternativas = "PADRAO")

Arguments

objeto

List of paired arrays or excel path containing the properly formatted paired arrays.

mapeamento

Vector containing the number of subscriptions of each criteria, from left to right. If not filled the pattern and fill with 0. If in doubt, see the tutorial vignette.

nomes_alternativas

Vector containing the names of the alternatives in your hierarchy, if not filled returns a vector of LETTERS\[1\:qtdAlternatives\]

Value

Table containing the relationships of criteria, subscriptions (If any) and Alternatives Using the AHP system.

Author(s)

Lyncoln Oliveira

Examples

m1=matrix(c(1, 1/5, 3, 1/5, 1/3,5, 1, 5, 3, 3,
1/3, 1/5, 1, 1/3, 1/3,5, 1/3, 3, 1, 1,3, 1/3,
3, 1, 1),ncol=5,byrow=TRUE)
m2=matrix(c(1, 1/3, 1/6, 3, 1, 1/2,6, 2, 1),nrow=3, byrow=TRUE)
m3=matrix(c(1, 1/2, 1/2,2, 1, 2, 2, 1/2, 1),nrow=3, byrow=TRUE)
m4=matrix(c(1, 1, 2,1, 1, 1, 1/2, 1, 1),nrow=3, byrow=TRUE)
m5=matrix(c(1, 2, 3,1/2, 1, 2, 1/3, 1/2, 1),nrow=3, byrow=TRUE)
m6=matrix(c(1, 5, 3,1/5, 1, 1/3, 1/3, 3, 1),nrow=3, byrow=TRUE)
base=list(m1,m2,m3,m4,m5,m6)
mapeamento=rep(0,5)
nomes_alternativas="PADRAO"
ahp_geral(base,mapeamento, nomes_alternativas)

Calculates the AHP for criteria and subcriteria

Description

Calculates AHP in a list of paired arrays or in a properly formatted excel worksheet stipend.

Usage

ahp_s(base, map)

Arguments

base

List of paired arrays or excel path containing the properly formatted paired arrays.

map

Vector containing the number of subscriptions of each criteria, from left to right. map = rep(0,n) n = number of criteria and no subcriteria; mapeamento = c(1,2) for one subcriteria in criteria 1 and two subcriteria in criteria 2. If in doubt, see the tutorial vignette.

Value

Table containing the relationships of criteria, subscriptions (If any) and Alternatives Using the AHP system.

Author(s)

Luciane Ferreira Alcoforado

Examples

x=paste0(letters[3],1:5)
y=c(5,2,7,3,2)
m1=matrix_ahp(x,y)
x=paste0(letters[1],1:3)
y=c(4.4,5.2,3)
m2=matrix_ahp(x,y)
y=c(2,4,3)
m3=matrix_ahp(x,y)
y=c(4.9,5,3.3)
m4=matrix_ahp(x,y)
y=c(4.4,4.2,4.3)
m5=matrix_ahp(x,y)
y=c(5.4,5.2,5.7)
m6=matrix_ahp(x,y)
base=list(m1, m2, m3, m4, m5, m6)
map = rep(0,5)
ahp_s(base,map)

#with two subcriteria in criteria 1 and 2 alternatives
map = c(2,0,0)
x=paste0(letters[3],1:3) #3 criteria
y=c(5,2,7)
m1=matrix_ahp(x,y) # matrix compare three criteria
x=paste0("SC1",1:2)
y=c(4,6)
m2=matrix_ahp(x,y) # 2 matrix compare two subcriteria of criteria 1
x=paste0(letters[1],1:2)
y=c(2,4)
m3=matrix_ahp(x,y) #alternatives for subcriteria 1
y=c(4.9,5)
m4=matrix_ahp(x,y) #alternatives for subcriteria 2
y=c(4.4,4.2)
m5=matrix_ahp(x,y) #alternatives for criteria 2
y=c(5.4,5.2)
m6=matrix_ahp(x,y) ##alternatives for criteria 3
base=list(m1, m2, m3, m4, m5, m6)


ahp_s(base,map)

#Other mapeamento: criteria 2 with 2 subcriteria and 3 alternatives


map = c(2,2)
x=paste0(letters[3],1:2) #2 criteria
y=c(5,7)
m1=matrix_ahp(x,y) # matrix compare two criteria
x=paste0("SC1",1:2)
y=c(4,6)
m2=matrix_ahp(x,y) # matrix compare two subcriteria of criteria 1
x=paste0(letters[1],1:3)
y=c(2,4,5)
m3=matrix_ahp(x,y) #alternatives for subcriteria 1 - criteria 1
y=c(4.9,5, 2)
m4=matrix_ahp(x,y) #alternatives for subcriteria 2 - criteria 1
y=c(4.4,8, 6)
x=paste0("SC2",1:2)
m5=matrix_ahp(x,y) #matrix compare two subcriteria of criteria 2
y=c(5.4,5.2, 1)
x=paste0(letters[1],1:3)
m6=matrix_ahp(x,y) #alternatives for subcriteria 1 - criteria 2
y=c(9,5.2, 3)
m7=matrix_ahp(x,y) #alternatives for subcriteria 2 - criteria 2
base=list(m1, m2, m3, m4, m5, m6, m7)

ahp_s(base,map)

Calculates the eigen vector of matrix

Description

Calculates the eigen vector of matrix

Usage

autoVetor(matriz)

Arguments

matriz

a paired matrix

Value

Returns a normalized eigenvector

Author(s)

Lyncoln Oliveira

Examples

m=diag(16)+2-2*diag(16)
m
autoVetor(m)

Calculates the priority vector of a paired matrix

Description

Calculates the priority vector of a paired array based on a list

Usage

calcula_prioridades(lista)

Arguments

lista

a paired matrix list

Value

Returns a list containing priority vectors for each matrix in the read list

Author(s)

Lyncoln Oliveira


calculates saaty's consistency index

Description

Function to calculate the saaty's consistency index

Usage

CI(m)

Arguments

m

is a matrice of pairwise comparison

Value

Returns saaty's consistency index

Author(s)

Luciane Ferreira Alcoforado

Examples

x=c("c1", "c2", "c3", "c4")
y=c(3, 9, 2, 8)
m=matrix_ahp(x,y)
CI(m)

x=c("a1", "a2", "a3", "a4", "a5")
y=c(1, 9, 1.5, 8, 6)
m=matrix_ahp(x,y)
CI(m)

m=diag(16)+2-2*diag(16)
m
CI(m)
CR(m)

calculates saaty's consistency ratio

Description

Function to calculate the saaty's consistency ratio

Usage

CR(m)

Arguments

m

is a matrice of pairwise comparison

Value

Returns saaty's consistency ratio in [0,1]

Author(s)

Luciane Ferreira Alcoforado

Examples

x=c("c1", "c2", "c3", "c4")
y=c(3, 9, 2, 8)
m=matrix_ahp(x,y)
CR(m)

x=c("a1", "a2", "a3", "a4", "a5")
y=c(1, 9, 1.5, 8, 6)
m=matrix_ahp(x,y)
CR(m)

m=diag(16)+2-2*diag(16)
m
CI(m)
CR(m)

creates a hierarchical structure

Description

Function to build the Diagram of hierarchies

Usage

flow_chart(names, c, a)

Arguments

names

is a vector with names for goal, criteria and choices in this exact sequence

c

is a integer number of criteria, c>=2

a

is a integer number of choices, a>=2

Value

Returns Diagram of hierarchies

Author(s)

Luciane Ferreira Alcoforado

Examples

p=flow_chart(names=NULL, a=2, c=2)
p

p=flow_chart(names=NULL, a=2, c=3)
p+ggplot2::theme_void()

flow_chart(names=c("G", "cost", "time", "hour", "home", "beach"),c=3, a=2)

Format an AHP table created by the general ahp() function

Description

Format an AHP table created by the general ahp() function

Usage

formata_tabela(tabela, cores = "PADRAO")

Arguments

tabela

AHP table created by the general ahp() function

cores

Color pattern to format the table. If "PADRAO" returns the color pattern (green, blue, green or blue); if "GRAY" returns the default gray color; if "WHITE" returns the table without colors

Value

Returns a table formatted with background colors responsive to element priority amounts

Author(s)

Lyncoln Oliveira


Format an AHP table created by the general ahp() function

Description

Format an AHP table created by the general ahp() function

Usage

formata_tabela2(tabela, cores = "PADRAO")

Arguments

tabela

AHP table created by the general ahp() function

cores

Color pattern to format the table. If "PADRAO" returns the color pattern (green, blue, green or blue); if "GRAY" returns the default gray color; if "WHITE" returns the table without colors

Value

Retorna uma tabela formatada com cores defundo responsivas as quantidades de prioridade dos elementos

Author(s)

Lyncoln Oliveira


Read an excel file containing the paired matrices and turn all your spreadsheets into a list of matrices in R

Description

Function to Read an excel file containing the paired matrices and turn all your spreadsheets into a list of matrices in Re

Usage

ler(caminho)

Arguments

caminho

Address to an excel file that contains the worksheets

Value

Returns a list containing the paired arrays from the excel file

Author(s)

Lyncoln Oliveira

Examples

caminho  <- system.file("tests", "test_import.xlsx", package = "xlsx")
lista = ler(caminho)

creates a dataframe containing the judments holistic

Description

Function to build the judment matrix

Usage

matrix_ahp(x, y)

Arguments

x

is a vector of names criteria or choices

y

is a vector of weigth scale Saaty, in [1,9]

Value

Returns a judment matrice.

Author(s)

Luciane Ferreira Alcoforado

Examples

x=c("c1", "c2", "c3", "c4")
y=c(3, 9, 2, 8)
matrix_ahp(x,y)

x=c("a1", "a2", "a3", "a4", "a5")
y=c(1, 9, 1.5, 8, 6)
matrix_ahp(x,y)

Create paired matrix and can test saaty consistency rate

Description

Function that Create paired matrix and can test saaty consistency rate

Usage

matriz_julgamento(n_comp, CR = TRUE, n_matrix = 1)

Arguments

n_comp

Number of elements to be evaluated

CR

If TRUE also returns the consistency rate of saaty, if FALSE returns only matrix

n_matrix

Number of matrix to be created

Value

Returns a list with 2 positions. First position contains the paired matrices and the second position their consistency rates

Author(s)

Lyncoln Oliveira


generates vectors of weights for criteria and alternatives

Description

Function that generates vectors of weights for criteria and alternatives

Usage

normaliza(lista)

Arguments

lista

is a list with judment matrices

Value

Returns auxiliary list

Author(s)

Lyncoln Oliveira

Examples

lista = list(M1=diag(3), M2=diag(3)+4-4*diag(3))
normaliza(lista)

Calculates the ranking of alternatives

Description

Calculates ranking of alternatives for a list of judment matrix

Usage

ranque(tabela)

Arguments

tabela

table building by ahp_s or ahp_geral

Value

Table containing the ranking of alternatives

Author(s)

Lyncoln Oliveira

Examples

x=paste0(letters[3],1:5)
y=c(5,2,7,3,2)
m1=matrix_ahp(x,y)
x=paste0(letters[1],1:3)
y=c(4.4,5.2,3)
m2=matrix_ahp(x,y)
y=c(2,4,3)
m3=matrix_ahp(x,y)
y=c(4.9,5,3.3)
m4=matrix_ahp(x,y)
y=c(4.4,4.2,4.3)
m5=matrix_ahp(x,y)
y=c(5.4,5.2,5.7)
m6=matrix_ahp(x,y)
base=list(m1, m2, m3, m4, m5, m6)
mapeamento = rep(0,5)
nomes_alternativas = paste0(letters[1],1:3)
tabela = ahp(base,mapeamento, nomes_alternativas)
ranque(tabela)

#with subcriteria and 3 criteria and 2 alternatives
mapeamento = c(2,0,0) #2 subcriteria in criteria 1 and 0 subcriteria to others
x=paste0(letters[3],1:3) #3 criteria
y=c(5,2,7)
m1=matrix_ahp(x,y) #compare criteria
x=paste0(letters[4],1:2)
y=c(4,6)
m2=matrix_ahp(x,y) # 2 compare 2 subcriteria of criteria 1
x=paste0(letters[1],1:2)
y=c(2,4)
m3=matrix_ahp(x,y) #alternatives for subcriteria 1
y=c(4.9,5)
m4=matrix_ahp(x,y) #alternatives for subcriteria 2
y=c(4.4,4.2)
m5=matrix_ahp(x,y) #alternatives for criteria 2
y=c(5.4,5.2)
m6=matrix_ahp(x,y) ##alternatives for criteria 3
base=list(m1, m2, m3, m4, m5, m6)

nomes_alternativas = paste0(letters[1],1:2)
tabela = ahp(base,mapeamento, nomes_alternativas)
ranque(tabela)

organizes a table with comparison matrix data

Description

Function to organizes a table with comparison matrix data

Usage

tabela_holistica(pesos)

Arguments

pesos

vector with holistic weights for comparison or comparison matrix data

Value

Returns a table with assigned holistic weights, comparison matrix, priority vector and consistency ratio

Author(s)

Luciane Ferreira Alcoforado & Orlando Longo

Examples

pesos = c(3, 7, 9, 2)
names(pesos) = paste0("C",1:4)
tabela_holistica(pesos)

m = matrix_ahp(y=c(3,4,3,2.5), x=paste0("A",1:4))
tabela_holistica(pesos=m)

Transforms table with numbers into percentage with 2 decimal places

Description

Function to Transforms table with numbers into percentage with 2 decimal places

Usage

transforma_tabela(tabela)

Arguments

tabela

table to transforms

Value

Returns a transform table with percentage

Author(s)

Lyncoln Oliveira

Examples

tabela=data.frame(x=c(0.5, 0.25), y=c(0.55, 0.93))
transforma_tabela(tabela)

build file with judment matrices

Description

Function to buil file with judment matrices

Usage

xlsx_ahp(m, file, sheet, append)

Arguments

m

is a matrice of pairwise comparison

file

is the path to the output file.

sheet

is a character string with the sheet name.

append

is a logical value indicating if m should be appended to an existing file. If TRUE the file is read from disk.

Value

Returns a xlsx document

#m=diag(10) #file1 = xlsx_ahp(m, file = "Example_1.xlsx", sheet = "M1", append = FALSE) #file2=xlsx_ahp(m, file = "Example_1.xlsx", sheet = "M2", append = TRUE)

#see file Example_1.XLSX in working directory

Author(s)

Luciane Ferreira Alcoforado