层次分析法r语言代码
时间: 2023-11-12 08:16:23 浏览: 143
Sure! Here is an example of how you can implement the Analytic Hierarchy Process (AHP) in R using the `ahp` package:
```R
# Install and load the ahp package
install.packages("ahp")
library(ahp)
# Define the decision hierarchy
hierarchy <- ahp(matrix(c(
1, 3, 1/5, 1/7,
1/3, 1, 1/7, 1/9,
5, 7, 1, 1/3,
7, 9, 3, 1
), nrow = 4),
c("Criterion 1", "Criterion 2", "Criterion 3", "Criterion 4"),
c("Alternative 1", "Alternative 2", "Alternative 3", "Alternative 4"))
# Perform the AHP analysis
result <- ahp::ahp(hierarchy)
# Print the final ranking of alternatives
print(result$rank)
```
In this example, we define a decision hierarchy with four criteria and four alternatives. The pairwise comparison matrix is created using the `matrix()` function, where the elements represent the relative importance of each criterion or alternative compared to others. The `ahp()` function performs the AHP analysis and returns the final ranking of alternatives.
阅读全文