gluc / ahp Goto Github PK
View Code? Open in Web Editor NEWAnalytical Hierarchy Process (AHP) with R
Analytical Hierarchy Process (AHP) with R
Hi,
I can't match the results of Saaty's publication.
Decision making — the Analytic Hierarchy and Network Processes (AHP/ANP)
From the article (table 3: "Criteria weights with respect to the goal")
The following Priorities
0.152
0.433
0.072
0.305
0.038
are given for the following matrix :
1 1/5 3 1/2 5
5 1 7 1 7
1/3 1/7 1 1/4 3
2 1 4 1 7
1/5 1/7 1/3 1/7 1
In R code :
Culture = c(1,1.0/5,3,1.0/2,5)
Family = c(5,1,7,1,7)
Housing = c(1.0/3,1.0/7,1,1.0/4,3)
Job = c(2,1,4,1,7)
Transportation = c(1.0/5,1.0/7,1.0/3,1.0/7,1)
mat = data.frame(Culture,Family,Housing,Job,Transportation)
PrioritiesFromPairwiseMatrixEigenvalues(mat, allowedConsistency = 0.051)
$priority
1 2 3 4 5
0.12655215 0.04583010 0.26119217 0.05845164 0.50797395
$consistency
[1] 0.05027572
# the consistency trigger seems all right but values for priorities are different.
# alternative priorities derivation do not bring the article's values.
> PrioritiesFromPairwiseMatrixMeanNormalization(mat)
$priority
[1] 0.13099959 0.04873300 0.26082227 0.05945257 0.49999257
$consistency
[1] NA
> PrioritiesFromPairwiseMatrixGeometricMean(mat)
$priority
[1] 0.12473441 0.04501646 0.26341235 0.06047375 0.50636303
$consistency
[1] NA
Hope the issue is on my side. Double checking would be nice.
(Ubuntu 14.04 ; Rstudio 0.98.1062 ; don't know command line to list all linked packages with versions : do not hesitate to indicate command to be run for useful further informations)
BR
Rudy
What if the car model/example I would like to add cars from others vendors besides Honda?
That would be the same in the "Choosing a Leader" example if we would like to have more candidates and group them according some characteristics.
In these two cases I would like to first rank such new characteristic (e.g. vendors) among themselves. Then I would rank the alternatives (e.g. cars/leaders) inside their groups. Finally I would apply the groups' weight to the weight of each alternative in order to get the final weight/priority.
I imagine all of it would be like adding "children" to each "alternative".
Does your R package support it in just 1 time run? Or I would need to run it 2 times and weight the results?
Thanks in advance, and congrats for the package!
https://emptywatson.github.io/tools/gluc-ahp-front/#/
It is a static page that offers the functionality to create new models and assign scores.
I have made a yaml file and am trying to use the ahp package. I can use the yaml.load_file function but cannot use Load() because it returns that it cannot load the ahp model. I have found that it's running into problems with the pairwise comparison sections under preferences. When I use a bare bones version of my yaml file, it's able to be loaded. But once the pairwise comparisons are added back in, I keep getting the same error. It is having issues somewhere with parsing out the information in the pairwise comparison section. Thanks in advance!
My full yaml file is:
Version: 1.0
Alternatives: &alternatives
GIC Monitoring:
Geologic Data:
USGS:
Energy Infrastructure:
Variometer:
Goal:
name: Data Source
preferences:
pairwise:
- [Coverage, Cost, 2]
- [Coverage, Reliability, 1/3]
- [Cost, Reliability, 1/5]
children:
Coverage:
preferences:
pairwise:
- [Temporal, Spatial, 1/5]
children:
Temporal:
preferences:
pairwise:
- [GIC Monitoring, Geologic Data, 8]
- [GIC Monitoring, USGS, 8]
- [GIC Monitoring, Energy Infrastructure, 8]
- [GIC Monitoring, Variometer, 9]
- [Geologic Data, USGS, 1]
- [Geologic Data, Energy Infrastructure, 1]
- [Geologic Data, Variometer, 7]
- [USGS, Energy Infrastructure, 1]
- [USGS, Variometer, 7]
- [Energy Infrastructure, Variometer, 7]
children: *alternatives
Spatial:
preferences:
pairwise:
- [GIC Monitoring, Geologic Data, 1]
- [GIC Monitoring, USGS, 1]
- [GIC Monitoring, Energy Infrastructure, 1/7]
- [GIC Monitoring, Variometer, 5]
- [Geologic Data, USGS, 1]
- [Geologic Data, Energy Infrastructure, 1/7]
- [Geologic Data, Variometer, 5]
- [USGS, Energy Infrastructure, 1/7]
- [USGS, Variometer, 5]
- [Energy Infrastructure, Variometer, 5]
children: *alternatives
Cost:
preferences:
pairwise:
- [GIC Monitoring, Geologic Data, 1]
- [GIC Monitoring, USGS, 1]
- [GIC Monitoring, Energy Infrastructure, 1]
- [GIC Monitoring, Variometer, 1/9]
- [Geologic Data, USGS, 1]
- [Geologic Data, Energy Infrastructure, 1]
- [Geologic Data, Variometer, 1/9]
- [USGS, Energy Infrastructure, 1]
- [USGS, Variometer, 1/9]
- [Energy Infrastructure, Variometer, 1/9]
children: *alternatives
Reliability:
preferences:
pairwise:
- [GIC Monitoring, Geologic Data, 1]
- [GIC Monitoring, USGS, 1]
- [GIC Monitoring, Energy Infrastructure, 1]
- [GIC Monitoring, Variometer, 9]
- [Geologic Data, USGS, 1]
- [Geologic Data, Energy Infrastructure, 1]
- [Geologic Data, Variometer, 9]
- [USGS, Energy Infrastructure, 1]
- [USGS, Variometer, 9]
- [Energy Infrastructure, Variometer, 9]
children: *alternatives
#####################################
Here's what I'm running in R:
Session info -------------------------------------------------------------------------------------------------------------------------------
setting value
version R version 3.3.2 (2016-10-31)
system x86_64, mingw32
ui RStudio (1.0.125)
language (EN)
collate English_United States.1252
tz America/New_York
date 2016-12-01
Packages -----------------------------------------------------------------------------------------------------------------------------------
package * version date source
ahp * 0.2.10 2016-11-27 CRAN (R 3.3.2)
backports 1.0.4 2016-10-24 CRAN (R 3.3.2)
colorspace 1.3-0 2016-11-10 CRAN (R 3.3.2)
curl 2.2 2016-10-21 CRAN (R 3.3.2)
data.tree * 0.6.2 2016-11-24 CRAN (R 3.3.2)
devtools * 1.12.0 2016-06-24 CRAN (R 3.3.2)
DiagrammeR 0.8.4 2016-07-17 CRAN (R 3.3.2)
digest 0.6.10 2016-08-02 CRAN (R 3.3.2)
evaluate 0.10 2016-10-11 CRAN (R 3.3.2)
formattable 0.2.0.1 2016-08-05 CRAN (R 3.3.2)
git2r 0.16.0 2016-11-20 CRAN (R 3.3.2)
htmltools 0.3.5 2016-03-21 CRAN (R 3.3.2)
htmlwidgets 0.8 2016-11-09 CRAN (R 3.3.2)
httr 1.2.1 2016-07-03 CRAN (R 3.3.2)
igraph 1.0.1 2015-06-26 CRAN (R 3.3.0)
influenceR 0.1.0 2015-09-03 CRAN (R 3.3.2)
jsonlite 1.1 2016-09-14 CRAN (R 3.3.2)
knitr 1.15.1 2016-11-22 CRAN (R 3.3.2)
magrittr 1.5 2014-11-22 CRAN (R 3.3.2)
memoise 1.0.0 2016-01-29 CRAN (R 3.3.2)
munsell 0.4.3 2016-02-13 CRAN (R 3.3.2)
plyr 1.8.4 2016-06-08 CRAN (R 3.3.2)
R6 2.2.0 2016-10-05 CRAN (R 3.3.2)
Rcpp 0.12.7 2016-09-05 CRAN (R 3.3.2)
rmarkdown 1.2 2016-11-21 CRAN (R 3.3.2)
rprojroot 1.1 2016-10-29 CRAN (R 3.3.2)
rstudioapi 0.6 2016-06-27 CRAN (R 3.3.2)
scales 0.4.1 2016-11-09 CRAN (R 3.3.2)
stringi 1.1.2 2016-10-01 CRAN (R 3.3.2)
stringr 1.1.0 2016-08-19 CRAN (R 3.3.2)
visNetwork 1.0.2 2016-10-05 CRAN (R 3.3.2)
withr 1.0.2 2016-06-20 CRAN (R 3.3.2)
yaml * 2.1.14 2016-11-12 CRAN (R 3.3.2)
I edited little bit on "car.ahp" file to test and rename it as "car2.ahp".
Then I tried to load it.
The error message for this is as below;
library(ahp)
ahpFile2 <- system.file("extdata", "car2.ahp", package="ahp")
carAhp2 <- LoadFile(ahpFile2)
Warning message:
In file(con, "r") :
file("") only supports open = "w+" and open = "w+b": using the former
How do I handle it?
Do I have to make "example.ahp" by using "yaml" type file?
Then how can I edit and save "yaml" file.
Text editor is not working.
Hi I found this example here:
Version: 2.0
Alternatives: &alternatives
OLD:
cost: 100
NEW:
cost: 100
Goal:
name: Select Between Old and New Chatbots
preferences:
pairwise:
- [Performance, Humanity, 7]
- [Performance, Affect, 7]
- [Performance, Accessibility, 1/3]
- [Humanity, Affect, 1/5]
- [Humanity, Accessibility, 1/7]
- [Affect, Accessibility, 1/7]
children:
Performance:
preferences:
pairwise:
- [UnexpectedInput, Escalation, 7]
children:
UnexpectedInput:
preferences:
pairwise:
- [OLD, NEW, 3]
children: *alternatives
Escalation:
preferences:
pairwise:
- [OLD, NEW, 7]
children: *alternatives
Humanity:
preferences:
pairwise:
- [Transparent, ThemedDiscussion, 1/5]
- [Transparent, SpecificQs, 1/5]
- [ThemedDiscussion, SpecificQs, 1]
children:
Transparent:
preferences:
pairwise:
- [OLD, NEW, 1]
children: *alternatives
ThemedDiscussion:
preferences:
pairwise:
- [OLD, NEW, 1/3]
children: *alternatives
SpecificQs:
preferences:
pairwise:
- [OLD, NEW, 1/5]
children: *alternatives
Affect:
preferences:
pairwise:
- [Personality, Entertaining, 1/5]
children:
Personality:
preferences:
pairwise:
- [OLD, NEW, 1/5]
children: *alternatives
Entertaining:
preferences:
pairwise:
- [OLD, NEW, 1/5]
children: *alternatives
Accessibility:
preferences:
pairwise:
- [MeaningIntent, SocialCues, 7]
children:
MeaningIntent:
preferences:
pairwise:
- [OLD, NEW, 3]
children: *alternatives
SocialCues:
preferences:
pairwise:
- [OLD, NEW, 1]
children: *alternatives
but it seems not to work here what is wrong?
I looked into the reference and also looked into the source for mistakes but cant find a mistake?
source of example
source of ref
Error message:
Error: attempt to apply non-function
Error in unique(c(ahpTree$Get(attribute = function(x) names(x$preferences$children), : attempt to apply non-function
Hello!
I need to resolve a problem with more than eight alternatives. But the function "RI" has limited the number of alternatives in eight. Can you help me?
What is the file format of the loaded file? I assume .ahp but I am unable to load this file. Please help!
Currently, the distributive mode AHP is used for priority calculations. I would suggest adding the ideal mode AHP as an additional option. It's a strong alternative approach that has many worthwhile advantages, such as preventing rank reversal. This way, the user had the option of allowing/preventing rank reversal as desired.
Enhancement request:
Is there any interest in adding one or more methods for performing sensitivity analysis on the results? The paper A Sensitivity Analysis Approach for Some Deterministic Multi-Criteria Decision Making Methods, for example, presents a few techniques.
Attempted to follow this vignette: http://qualityandinnovation.com/2016/01/05/analytic-hierarchy-process-ahp-using-preferencefunction-in-ahp/.
Trying to load a txt file, and I am getting this error:
In readLines(input) : incomplete final line found on 'tomdickharry.txt'
packageVersion("ahp")
[1] ‘0.1.1’
I am not sure why consistency checks are not a part of geomean and normalized mean methods. I would argue they should always be used and included.
Either lamdaMax could be calculated the proper way (same as eigenvalue method) or by using the standard lamdaMax estimation approach. Maybe the lamdaMax estimation approach makes the most sense here, since the only time you will know lamdaMax precisely is when you use the eigenvalue approach.
Thoughts?
First, your package is great!
But, your package can not support utf-8 character in yaml file. It means a lot of people cant not use their home language to show results.
Can you fix this? Please.
Or tell me how to solve this problem.
Hello,
In the summer of 2016, while doing my thesis I used the AHP package to perform part of it. Now I'm in a similar project and I wanted to use it again, since there aren't much more alternatives. However, when I try to load the file, I get the following error:
Error in readChar(ahpFile, file.info(ahpFile)$size) :
invalid 'nchars' argument
In addition: Warning message:
In file(con, "rb") :
file("") only supports open = "w+" and open = "w+b": using the former
I then checked file.info and in fact it loads the file but gets NA in every field of it. I have already checked the syntax on your website and the syntax is correct. Any idea of what might be causing this?
A function in Visualize() will soon deprecate as indicated in:
Node$fields will be deprecated in the next release. Please use Node$attributes instead.
I am going crazy with this YAML code for file.ahp.
Online Yaml code verifier say that it's ok but it isn't!!!
Could you hint at where does the mistake lay?
Please!
I get error:
Error in load(db) :
numero magico errato del file di ripristino (il file potrebbe essere danneggiato) - dati non caricati
Inoltre: Warning message:
file ‘Vacation.ahp’ has magic number 'Versi'
Use of save versions prior to 2 is deprecated
MY CODE:
Version: 2.0
Alternatives: &alternatives
Training
ImpSeed
Transf
FarmOrg
Market
Goal:
name: ImproveAgriSust
decision-makers:
- p1: 1
preferences:
p1:
pairwise:
- [DEC, DEN, 2]
- [DEC, DES, 1/2]
- [DEN, DES, 2]
children:
DEC:
preferences:
-p1:
[RDI, DP, 9]
[RDI, APC, 7]
[RDI, RUAC, 0.1]
[RDI, LE, 6]
[RDI, AFS, 4]
[RDI, ACP, 2]
[RDI, ARP, 5]
[DP, APC, 0.3]
[DP, RUAC, 3]
[DP, LE, 8]
[DP, AFS, 0.4]
[DP, ACP, 7]
[DP, ARP, 0.3]
[APC, RUAC, 9]
[APC, LE, 9]
[APC, AFS, 0.1]
[APC, ACP, 4]
[APC, ARP, 0.2]
[RUAC, LE, 3]
[RUAC, AFS, 0.4]
[RUAC, ACP, 0.3]
[RUAC, ARP, 0.5]
[LE, AFS, 0.1]
[LE, ACP, 0.7]
[LE, ARP, 0.6]
[AFS, ACP, 0.5]
[AFS, ARP, 0.5]
[ACP, ARP, 0.4]
children:
RDI:
children: *alternatives
DP:
children: *alternatives
APC:
children: *alternatives
RUAC:
children: *alternatives
LE:
children: *alternatives
AFS:
children: *alternatives
ACP:
children: *alternatives
ARP:
children: *alternatives
DEN:
preferences:
-p1:
[RDI, DP, 1]
[RDI, APC, 2]
[RDI, RUAC, 0.1]
[RDI, LE, 0.1]
[RDI, AFS, 0.13]
[RDI, ACP, 1]
[RDI, ARP, 2]
[DP, APC, 5]
[DP, RUAC, 0.9]
[DP, LE, 0.9]
[DP, AFS, 2]
[DP, ACP, 6]
[DP, ARP, 6]
[APC, RUAC, 0.1]
[APC, LE, 0.11]
[APC, AFS, 0.13]
[APC, ACP, 2]
[APC, ARP, 1]
[RUAC, LE, 2]
[RUAC, AFS, 2]
[RUAC, ACP, 9]
[RUAC, ARP, 9]
[LE, AFS, 2]
[LE, ACP, 9]
[LE, ARP, 9]
[AFS, ACP, 9]
[AFS, ARP, 9]
[ACP, ARP, 1]
children:
RDI:
children: *alternatives
DP:
children: *alternatives
APC:
children: *alternatives
RUAC:
children: *alternatives
LE:
children: *alternatives
AFS:
children: *alternatives
ACP:
children: *alternatives
ARP:
children: *alternatives
DES:
preferences:
-p1:
[RDI, DP, 3]
[RDI, APC, 4]
[RDI, RUAC, 3]
[RDI, LE, 2]
[RDI, AFS, 2]
[RDI, ACP, 3]
[RDI, ARP, 2]
[DP, APC, 1]
[DP, RUAC, 2]
[DP, LE, 1]
[DP, AFS, 1]
[DP, ACP, 1]
[DP, ARP, 0.13]
[APC, RUAC, 2]
[APC, LE, 2]
[APC, AFS, 1]
[APC, ACP, 1]
[APC, ARP, 0.5]
[RUAC, LE, 0.5]
[RUAC, AFS, 0.33]
[RUAC, ACP, 1]
[RUAC, ARP, 0.5]
[LE, AFS, 1]
[LE, ACP, 2]
[LE, ARP, 1]
[AFS, ACP, 2]
[AFS, ARP, 1]
[ACP, ARP, 1]
children:
RDI:
children: *alternatives
DP:
children: *alternatives
APC:
children: *alternatives
RUAC:
children: *alternatives
LE:
children: *alternatives
AFS:
children: *alternatives
ACP:
children: *alternatives
ARP:
children: *alternatives
Running Visualize(myAhp)
leads to a JavaScript abort as shown in the stack trace below. When running inside RStudio the stack trace appears in the Viewer panel. When running from an R shell the stack trace appears in the browser. Running other AHP commands such as Calculate(myAhp)
, Anaylze(myAhp)
, AnalyzeTable(myAhp)
and tree prints succeed as expected.
However, on the same model, running g <- GetGraph(myAhp)
yields a class from which the DOT notation representation can be copied and pasted to GraphViz for successful drawing. Consequently, the issue may not be associated with AHP itself but rather with the dependent JS libraries.
Stack trace:
abort(0) at jsStackTrace@http://localhost:18175/session/viewhtml6fea52a704ac/lib/viz-0.3/viz.js:5:22072
stackTrace@http://localhost:18175/session/viewhtml6fea52a704ac/lib/viz-0.3/viz.js:5:22258
abort@http://localhost:18175/session/viewhtml6fea52a704ac/lib/viz-0.3/viz.js:28:10656
nullFunc_iii@http://localhost:18175/session/viewhtml6fea52a704ac/lib/viz-0.3/viz.js:5:662065
a8@http://localhost:18175/session/viewhtml6fea52a704ac/lib/viz-0.3/viz.js:21:31634
iC@http://localhost:18175/session/viewhtml6fea52a704ac/lib/viz-0.3/viz.js:9:83383
aD@http://localhost:18175/session/viewhtml6fea52a704ac/lib/viz-0.3/viz.js:9:102098
uF@http://localhost:18175/session/viewhtml6fea52a704ac/lib/viz-0.3/viz.js:9:173805
pG@http://localhost:18175/session/viewhtml6fea52a704ac/lib/viz-0.3/viz.js:9:204484
xc@http://localhost:18175/session/viewhtml6fea52a704ac/lib/viz-0.3/viz.js:11:740
http://localhost:18175/session/viewhtml6fea52a704ac/lib/viz-0.3/viz.js:28:403
ccallFunc@http://localhost:18175/session/viewhtml6fea52a704ac/lib/viz-0.3/viz.js:5:8402
http://localhost:18175/session/viewhtml6fea52a704ac/lib/viz-0.3/viz.js:47:42
renderValue@http://localhost:18175/session/viewhtml6fea52a704ac/lib/grViz-binding-0.8.4/grViz.js:38:27
http://localhost:18175/session/viewhtml6fea52a704ac/lib/htmlwidgets-0.8/htmlwidgets.js:625:30
forEach@[native code]
forEach@http://localhost:18175/session/viewhtml6fea52a704ac/lib/htmlwidgets-0.8/htmlwidgets.js:55:21
http://localhost:18175/session/viewhtml6fea52a704ac/lib/htmlwidgets-0.8/htmlwidgets.js:551:14
forEach@[native code]
forEach@http://localhost:18175/session/viewhtml6fea52a704ac/lib/htmlwidgets-0.8/htmlwidgets.js:55:21
staticRender@http://localhost:18175/session/viewhtml6fea52a704ac/lib/htmlwidgets-0.8/htmlwidgets.js:549:12
http://localhost:18175/session/viewhtml6fea52a704ac/lib/htmlwidgets-0.8/htmlwidgets.js:638:38
R session info:
R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.12.1 (unknown)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ahp_0.2.10
loaded via a namespace (and not attached):
[1] igraph_1.0.1 Rcpp_0.12.8 rstudioapi_0.6 knitr_1.15.1 magrittr_1.5 munsell_0.4.3 colorspace_1.3-1
[8] R6_2.2.0 stringr_1.1.0 plyr_1.8.4 tools_3.2.3 visNetwork_1.0.2 influenceR_0.1.0 DiagrammeR_0.8.4
[15] htmltools_0.3.5 yaml_2.1.14 digest_0.6.10 rprojroot_1.1 htmlwidgets_0.8 evaluate_0.10 rmarkdown_1.2
[22] stringi_1.1.2 scales_0.4.1 backports_1.0.4 data.tree_0.6.2 jsonlite_1.1 formattable_0.2.0.1
I have made a yaml file and am trying to use the ahp package. I can load the file and visualize, but cannot use calculate. I have made a gist with both the ahp file and my R code. If you're able to tell me where I went wrong, it would be much appreciated! You can access the gist here: https://gist.github.com/mayt1992/6e361c5d63854c49e093fc79d8f0b5f5
@gluc
I have written an ahp file in YAML
now when I am running Calculate (ahp) in R, it shows
Warning messages:
1: In is.na(x$consistency) :
is.na() applied to non-(list or vector) of type 'NULL'
2: In is.na(x$consistency) :
is.na() applied to non-(list or vector) of type 'NULL'
3: In is.na(x$consistency) :
is.na() applied to non-(list or vector) of type 'NULL'
4: In is.na(x$consistency) :
is.na() applied to non-(list or vector) of type 'NULL'
5: In is.na(x$consistency) :
is.na() applied to non-(list or vector) of type 'NULL'
however, when I run Visualize(ahp), the tree comes well.
pls help me out
Hi,
I am trying to build the AHP file from the result of a pairwise comparison survey.
Do you have an example for a script that would build the correct YAML format out of a data frame showing the results of a pairwise comparison survey?
Thanks a lot,
Edouard
How to run this gui in windows exactly?
I can imagine a lot of packages use similar function names; those sound very generic but are there only for a specific package / file format. Maybe 'CalculateAHP', 'LoadFileAHP' would be better? Just an idea.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.