Using GNU R in AHP
Scenario:
- The goal is to select the most appropriate sedan from the candidates.
- Selection criterion are:
- Style
- Reliability
- Fuel Consumption
- Price
- Criterion Comparison Table:
- Style Comparison Table:
- Reliability Comparison Table:
- Owing to Fuel Consumption and Cost are both Quantitative criterion, there are no needs of comparison tables for such criterion.
GNU R:
- It is very powerful programmable statistical tool. This material is to demonstrate how GNU R can facilitate the Analytical Hierarchy Process (AHP) in decision making.
- In order to facilitate the calculation during AHP, a function library is designed as follows:
- ahp_dot <- function(m) {
- m -> ret
- for (i in 1:length(m[1,])) {
- for (j in 1:length(m[,1])) {
- sum(m[i,] * m[,j]) -> ret[i,j]
- }
- }
- ret
- }
- ahp_eigen_vector <- function(m) {
- m[1,] -> ret
- for (i in 1:length(m[1,])) {
- sum(m[i,]) -> ret[i]
- }
- ret
- }
- ahp_weight <- function(v) {
- sum(v) -> total
- v -> ret
- for (i in 1:length(v)) {
- v[i]/total -> ret[i]
- }
- ret
- }
- ahp_eigen <- function(m) {
- ahp_weight(ahp_eigen_vector(ahp_dot(m))) -> ret
- ret
- }
- ahp_eigen_check <- function(v1, v2) {
- v1 - v2 -> ret
- ret
- }
- ahp_process <- function(m) {
- ahp_dot(m) -> my_dot
- ahp_eigen(my_dot) -> ret
- ret
- }
- Main R program is as follows:
- read.table("AHP-Criteria-Weight.dat") -> my_data
- ahp_process(my_data) -> my_eigen
- read.table("AHP-Style-Comparison.dat") -> my_data_1
- ahp_process(my_data_1) -> my_eigen_1
- read.table("AHP-Reliability-Comparison.dat") -> my_data_2
- ahp_process(my_data_2) -> my_eigen_2
- read.table("AHP-Fuel-Comparison.dat") -> my_data_3
- ahp_weight(my_data_3[1,]) -> my_eigen_3
- read.table("AHP-Price-Comparison.dat") -> my_data_4
- ahp_weight(my_data_4[1,]) -> my_eigen_4
- matrix(c(my_eigen_1, my_eigen_2, my_eigen_3), length(my_eigen_3)) -> my_matrix
- my_eigen_3 -> ret
- for (i in 1:length(my_eigen_3)) {
- sum(my_matrix[i,] * my_eigen) -> ret
- }
- print(ret * my_eigen_4)
- Weight of Criteria Table:
- Weight Table of Candidates:
- Benefit Comparison Table:
- The best choice is Civic, and the worst one is Clio.