R ahp package on github 8

AHP lets you analyse complex decision making problems. We have recently released the initial version of the R ahp package on github: gluc/ahp.

What is AHP?

The Analytic Hierarchy Process is a decision making framework developed by Thomas Saaty. Read this entry on Wikipedia for more information.

There is commercial software available to use this methodology for complex decision making problems. In R, there are a few packages that help with the calculation part. However, there has not been a framework to model entire AHP problems. This is the goal of the ahp package.

How to get started

For more information, see the package vignette, either using vignette("car-example"), or on rpubs. That vignette models the well-known AHP example, which is, for example, explained here.

To install the package and read the vignette, you want to do this:

Modeling Analytic Hierarchy Process problems

Once the package is installed, you can run the sample yourself, like so:

This illustrates the basic workflow, which is:

The basic workflow with this package is:

  1. specify your ahp problem in an ahp file
  2. load an ahp file, using LoadFile
  3. calculate model, using Calculate
  4. output model analysis, either using GetDataFrame or using ShowTable

ahp File Format

The entire ahp problem is specified in a single file, in YAML format. For an example, see here.



There are two options for the analysis. The first one prints to the console:

What you will see is something like this:

The Odyssey comes out first, but only slightly better than the Accord Sedan.


The ShowTable method displays the same analysis as an html table, using color codes:

AHP ShowTable

Here, it’s easy to see that the Odyssey is more expensive then the Accord Sedan, however Safety and Passenger Capacity make more than up for this.

Also note the exclamation mark at the Style Consistency: A consistency ratio of above 10% is considered inconsistent, and we might want to review the style preferences in the ahp file.

As a side note: This table is generated with the fantastic formattable package.

Feedback and Future Developments

This is an early version, and thus feedback is more than welcome. You can ask questions and open issues directly on github issues page. Also, I appreciate if you star the package on github if you like.

The plan is to add a few test cases, error handling, and submit it to CRAN. A future development I am currently considering is to add a simple Shiny app to the package, letting you specify and tweak your file directly in your web browser, and showing the analysis also in your Browser.

For your information, there is now an app that lets you play around with the package at http://ipub.com/apps/ahp/

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

8 thoughts on “R ahp package on github

  • Hansoo

    Awesome!! Great job!!!! ShowTable is beautiful!!

    I have two questions!

    First, how can I load another dataset to calculate AHP?
    Do I have to make “car.ahp” style file and load it?

    Second, in many cases, the respondents of AHP are more than 20 peoples.
    We have to calculate CR of each person to identify his/her consistency.
    Then, we have to calculate an arithmetic mean of each person’s preference value to calculate and make them one value.

    Maybe it’s quite complicated coding.

    Thank you again for your hard work.

    • gluc Post author

      Thanks. Yes, currently there is no GUI, so you need to model your ahp problem in a file (similar to car.ahp), and then you can load it with LoadFile.
      Regarding your second question: You can create a sub-tree per person, and then combine these sub-trees in a big ahp tree. Though I admit that the ShowTable is not too nice for that situation, as you would not see the weights aggregated per criteria. I’ll think of something…

  • Garrett

    Hello Gluc,

    Awesome script!

    In regards to the YAML format, I would like to create a survey that outputs into the YAML format that would be accepted into your utility. Are you aware of any survey tools or R scripts that would be capable of this?

    I am also willing to create the survey in R, but i am not sure how to output the collected data into a YAML friendly format.


  • Jeremy Yap

    I’ve been trying to use LoadFile(ahpFile), but it seems that in the newer versions, it takes Load(ahpFile) to work. Maybe an edit would be good. Overall, it’s a great job. Thanks!