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.
Generate 100 location names
IT'S IMPORTANT. Now you should decide about your variable range. Saaty's scale has only 9 values, so differences of the variable values for locations must be only 4 classes. You must aggregate differences into 9 classes or initial values into 4 classes. In your example I see the lowest value is 3 and the highest value is 8. You don't have any 5-s. But if you have them, you will get possible differences
You can't aggregate it into 9 classes. So your variable's range can be only 4 (e.g. from 3 to 7), not 5 (from 3 to 8).
Generate 100 random values
Make the template matrix
Make vector of values for Saaty's scores
You have small amount of data, so why you ignore simple loops?
A loop to fill the matrix
You should make (for the ahpsurvey package) a list of some matrices from each decision-maker (even if you have only one maker), so: