# 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: Weighted Sum Method - Multi Criteria Decision Making - GeeksforGeeks

I tried using something similar as done here: weightedSum: Weighted sum of evaluations of alternatives. in MCDA: Support for the Multicriteria Decision Aiding Process, 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``````

A matrix must have all numeric or all character values; otherwise, the numeric values will be converted to character and can't be used in calculations such as weighted sums.

``````df1<- matrix(c(9,12000,72,"B1",7.6,8500,68,"B1",8.2,9500,63,"B2",8.5,10000,70,"A2",9.3,14000,72,"A2"),
nrow=5,
ncol=4,
byrow=TRUE)

row.names(df1) <- c("Student1","Student2","Student3","Student4","Student5")
colnames(df1) <- c("CGPA","Expected Stipend","Technical Exam Score","Aptitude Test Grade")
str(df1)
#>  chr [1:5, 1:4] "9" "7.6" "8.2" "8.5" "9.3" "12000" "8500" "9500" "10000" ...
#>  - attr(*, "dimnames")=List of 2
#>   ..\$ : chr [1:5] "Student1" "Student2" "Student3" "Student4" ...
#>   ..\$ : chr [1:4] "CGPA" "Expected Stipend" "Technical Exam Score" "Aptitude Test Grade"
``````

``````library(MCDA)

# avoid embedded blanks in variable names and turn the grades into factor
df2 <- data.frame(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),
# convert to ranked scale

row.names(df2) <- df2\$Student
df2 <- df2[c(2:5)] # remove character variable
weights <- c(1:4)  # assign weights
overall1 <- weightedSum(df2, weights)
overall1
#> Student1 Student2 Student3 Student4 Student5
#>  24237.0  17223.6  19205.2  20222.5  28229.3
``````
1 Like

Thank you very much for your answer @technocrat , but you can take a look at the resolution link, I believe the result is not the same. The idea of ​​the exercise is to select the best candidate among 5 candidates using the weighted sum method. By the resolution, it is concluded that Student 4 is the best choice. But just using `weightedSum` doesn't tell me much, or something is missing that I haven't noticed yet.

That’s a different question from the one I thought was sought, which was to apply the `weightSum()` function to a data frame with all numeric values. The students are identified as alternatives and the remaining variables as weights. Fewer could be used or relative weights could be adjusted to give greater or lesser emphasis, a wider scale for grades could be adopted or changes could be made in combination. Whether and how to do so is a domain question rather than a computational one.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.