ahp 함수화

ahp_base <- function(i1)
{
  mn <- ncol(i1)
  
  lamda_max <- max(Re(eigen(i1)$value))
  lm_index <- which(lamda_max == Re(eigen(i1)$value))
  
  ci1 <- (lamda_max - mn)/(mn - 1)
  ci1
  
  temp_w <- abs(Re(eigen(i1)$vectors[,lm_index]))
  w1 <- temp_w/sum(temp_w)
  return(w1)
}

ahp 예시

temp1 <- read.csv("D:\\_work_category\\개인 프로젝트\\ahp\\input1.csv", header = FALSE)
input <- as.matrix(temp1)

input
##             V1  V2        V3        V4        V5
## [1,] 1.0000000 3.0 7.0000000 3.0000000 1.0000000
## [2,] 0.3333333 1.0 5.0000000 0.3333333 1.0000000
## [3,] 0.1428571 0.2 1.0000000 3.0000000 0.2000000
## [4,] 0.3333333 3.0 0.3333333 1.0000000 0.3333333
## [5,] 1.0000000 1.0 5.0000000 3.0000000 1.0000000
ahp_base(input)
## [1] 0.34081738 0.16725123 0.09882908 0.13483287 0.25826945