I would like to perform Analytical Hierarchy Analysis in R using ahpsurvey.
I will use the table below as an example of my dataset.
Location | Var1 |
---|---|
A | 8 |
B | 3 |
C | 7 |
D | 6 |
E | 4 |
This is the Satty rating I would like to incorporate :
Rating | Explanation |
---|---|
1/9 | The preferred characteristics are absolutely less important |
1/7 | The preferred characteristics are strongly less important |
1/5 | The preferred characteristics are moderately less important |
1/3 | The preferred characteristics are slightly less important |
1 | Two characteristics are equally important |
3 | The preferred characteristics are slightly more important |
5 | The preferred characteristics are moderately more important |
7 | The preferred characteristics are strongly more important |
9 | The preferred characteristics are absolutely more important |
Step 3. This is where I am stuck. I would like to create a loop which compares the values of the variable against one another, make a rating using the Satty ranking above.
num_alternatives <- length(location)
mat <- matrix(0, nrow = num_alternatives, ncol = num_alternatives)
colnames(comparison_matrix) <- location
rownames(comparison_matrix) <- location
#making comparisons between the value of Var1 of location A and the others
x_dta$a_diff <- 8 - x_dta$Var1
x_dta$a_diff <- as.character(x_dta$a_diff)
#assigned Satty ranking to the differences
diff_lookup <- c(`0` = 1, `5` = 7, `1` = 3, `2` = 5, `4` =7)
#location A comparison with other locations.
mat["A","B"] <- 7
mat["A","C"] <- 3
mat["A","D"] <- 5
mat["A","E"] <- 7
#followed the same process until I had a full matrix. The problem is that I have over 100 locations in my dataset and filling the matrix one by one is time consuming.