R ahp package on github

[This article was first published on ipub » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

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:

devtools::install_github("gluc/ahp", build_vignettes = TRUE)
vignette("car-example", package = "ahp")

Modeling Analytic Hierarchy Process problems

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

ahpFile <- system.file("extdata", "car.ahp", package="ahp")
carAhp <- LoadFile(ahpFile)

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:

Weight Odyssey Accord Sedan  CR-V Accord Hybrid Element Pilot Consistency
1  Buy Car                    100.0%   21.8%        21.6% 16.3%         15.1%   14.7% 10.6%        7.4%
2   ¦--Cost                    51.0%    5.7%        12.3% 11.7%          5.8%   12.5%  3.0%        1.5%
3   ¦   ¦--Purchase Price      24.9%    2.3%         6.1%  6.1%          0.6%    9.1%  0.6%        6.8%
4   ¦   ¦--Fuel Cost           12.8%    2.0%         2.4%  2.1%          2.7%    1.9%  1.7%        0.0%
5   ¦   ¦--Maintenance Cost     5.1%    0.3%         1.8%  0.5%          1.6%    0.4%  0.4%        2.3%
6   ¦   °--Resale Value         8.2%    1.1%         1.9%  2.9%          0.9%    1.1%  0.3%        3.2%
7   ¦--Safety                  23.4%   10.2%         5.1%  0.8%          5.1%    0.5%  1.8%        8.1%
8   ¦--Style                    4.1%    0.3%         1.5%  0.6%          1.5%    0.1%  0.2%       10.2%
9   °--Capacity                21.5%    5.7%         2.8%  3.1%          2.8%    1.5%  5.6%        0.0%
10      ¦--Cargo Capacity       3.6%    0.8%         0.3%  0.7%          0.3%    0.7%  0.7%        0.4%
11      °--Passenger Capacity  17.9%    4.9%         2.4%  2.4%          2.4%    0.8%  4.9%        0.0%

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.

The post R ahp package on github appeared first on ipub.

To leave a comment for the author, please follow the link and comment on their blog: ipub » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)