weights_mpsi <- function(df) { criteria_direction <- df[1, 2:ncol(df)] criterias <- colnames(df)[2:ncol(df)] matrix_decis <- as.data.frame(df[3:nrow(df), 2:ncol(df)]) colnames(matrix_decis) <- criterias matrix_decis <- matrix_decis %>% mutate_all(as.numeric) matrix_decis_norm <- data.frame(matrix(NA, ncol = ncol(matrix_decis), nrow = nrow(matrix_decis))) for(i in 1:ncol(matrix_decis_norm)) { if(criteria_direction[i] == "MAX") { matrix_decis_norm[,i] <- matrix_decis[,i] / max(matrix_decis[,i]) } else { matrix_decis_norm[,i] <- min(matrix_decis[,i]) / matrix_decis[,i] } } pv <- rep(0, ncol(matrix_decis_norm)) for(j in 1:ncol(matrix_decis_norm)) { for(i in 1:nrow(matrix_decis_norm)) { pv[j] <- pv[j] + ((matrix_decis_norm[i,j]) - mean(matrix_decis_norm[,j]))^2 } } weights_MPSI <- pv / sum(pv) weights_MPSI <- as.data.frame(t(weights_MPSI)) colnames(weights_MPSI) <- criterias return(weights_MPSI) } # # pesos_mpsi <- weights_mpsi(df) # ordem_psi <- rank_psi(df, pesos_mpsi) # ordem_cocoso <- rank_cocoso(df, weights_cocoso = pesos_mpsi, alpha = 0.5) # ordem_topsis <- rank_topsis(df, weights_topsis = pesos_mpsi)