# Use the Weighted Sum Method in R

I would like to use the Weighted Sum Method (Multi Criteria Decision Making) in R in this database below. The resolution of the issue is here: https://www.geeksforgeeks.org/weighted-sum-method-multi-criteria-decision-making/

I tried using something similar as done here: https://rdrr.io/cran/MCDA/man/weightedSum.html, however the result was not right.

   df1<- structure(list(Student = c("Student1", "Student2", "Student3", "Student4", "Student5"),
CGPA = c(9, 7.6, 8.2, 8.5, 9.3),
Expected Stipend = c(12000L, 8500L, 9500L, 10000L, 14000L),
Technical Exam Score = c(72L, 68L, 63L, 70L, 72L),
Aptitude Test Grade = c("B1", "B1", "B2", "A2", "A2")),
class = "data.frame", row.names = c(NA, -5L))

> df1
Student CGPA Expected Stipend Technical Exam Score Aptitude Test Grade
1 Student1  9.0            12000                   72                  B1
2 Student2  7.6             8500                   68                  B1
3 Student3  8.2             9500                   63                  B2
4 Student4  8.5            10000                   70                  A2
5 Student5  9.3            14000                   72                  A2


The edited version fixed one problem (numeric fields being character strings). Before using the weightedSum function (or doing any other calculations), you also need to do two things, both explained in the GeeksForGeeks page. First, you need to convert the letter grades to points, using the 1-5 scale on the GFG page (below Table 3). Next, you have to scale the columns. For three of them, you divide by their max values. For "Expected Stipend", you divide by the min value and take a reciprocal.

Here is some code using the dplyr package to do data frame modifications. I calculated the scores and ranks manually, without using weightedSum.

# Convert the grades to point values.
df1 <- df1 |> mutate(Aptitude Test Grade = recode(Aptitude Test Grade, "A1" = 5, "A2" = 4, "B1" = 3, "B2" = 2, "C1" = 1))
# Set up the vector of weights.
weights <- c(0.3, 0.2, 0.25, 0.25)
# Copy the data frame and scale each column appropriately.
scaled <- df1 |>
mutate(CGPA = CGPA / max(CGPA),
Expected Stipend = min(Expected Stipend) / Expected Stipend,
Technical Exam Score = Technical Exam Score / max(Technical Exam Score),
Aptitude Test Grade = Aptitude Test Grade / max(Aptitude Test Grade)
)
# Compute the weighted scores.
scaled <- scaled |>
rowwise() |>
mutate(Performance Score = weighted.mean(c(CGPA, Expected Stipend, Technical Exam Score, Aptitude Test Grade), w = weights))
# Assign ranks.
scaled$$Rank <- (nrow(scaled) + 1) - rank(scaled$$Performance Score)
# View the results.
scaled
Student   CGPA Expected Stipend Technical Exam… Aptitude Test… Performance S…  Rank
<chr>    <dbl>              <dbl>             <dbl>            <dbl>            <dbl> <dbl>
1 Student1 0.968              0.708             1                 0.75            0.869     3
2 Student2 0.817              1                 0.944             0.75            0.869     4
3 Student3 0.882              0.895             0.875             0.5             0.787     5
4 Student4 0.914              0.85              0.972             1               0.937     1
5 Student5 1                  0.607             1                 1               0.921     2


The rank() function ranks lowest to highest, and we want highest to lowest, so we have to get a little creative. You could rank the negative of the score, or the reciprocal of the score, or (as I did here) you could rank the scores and subtract the computed ranks from 1 more than the number of scores.

• Thanks for explanation @prubin. I can do this example, but using the PROMETHEE method? If so, would you know which R function I could use? Feb 15, 2022 at 2:45
• I have no experience with the PROMETHEE method, but there seems to be an R package for it: cran.r-project.org/web/packages/PROMETHEE/index.html.
– prubin
Feb 15, 2022 at 4:18
• Thanks @prubin. I will check. Please, can you look at this question:or.stackexchange.com/questions/7843/… It is very similar to this question that you solved, however, I wanted to know if it's the same solving procedure, without having to use the weightedSum function. Feb 15, 2022 at 13:12
• Sorry, I'm not understanding this. You want to know if what is the same solving procedure as what else?
– prubin
Feb 15, 2022 at 17:00