A simple approach would be to calculate the sum score or the mean. Another approach would not assume that all variables are of equal importance and we could calculate a weighted mean.
Let's assume we have the following 10 patients and variables v1
to v5
.
> set.seed(1)
> df <- data.frame(v1 = sample(1:5, 10, replace = TRUE),
+ v2 = sample(1:5, 10, replace = TRUE),
+ v3 = sample(1:5, 10, replace = TRUE),
+ v4 = sample(1:5, 10, replace = TRUE),
+ v5 = sample(1:5, 10, replace = TRUE))
>
> df
v1 v2 v3 v4 v5
1 2 2 5 3 5
2 2 1 2 3 4
3 3 4 4 3 4
4 5 2 1 1 3
5 2 4 2 5 3
6 5 3 2 4 4
7 5 4 1 4 1
8 4 5 2 1 3
9 4 2 5 4 4
10 1 4 2 3 4
1. Sum score and ranks
> df$sum <- rowSums(df)
> df$ranks <- abs(rank(df$sum) - (dim(df)[1] + 1))
> df
v1 v2 v3 v4 v5 sum ranks
1 2 2 5 3 5 17 4.0
2 2 1 2 3 4 12 9.5
3 3 4 4 3 4 18 2.5
4 5 2 1 1 3 12 9.5
5 2 4 2 5 3 16 5.0
6 5 3 2 4 4 18 2.5
7 5 4 1 4 1 15 6.5
8 4 5 2 1 3 15 6.5
9 4 2 5 4 4 19 1.0
10 1 4 2 3 4 14 8.0
2. Mean score and ranks (note: ranks
and ranks2
are equal)
> df$means <- apply(df[, 1:5], 1, mean)
> df$ranks2 <- abs(rank(df$mean) - (dim(df)[1] + 1))
> df
v1 v2 v3 v4 v5 sum ranks means ranks2
1 2 2 5 3 5 17 4.0 3.4 4.0
2 2 1 2 3 4 12 9.5 2.4 9.5
3 3 4 4 3 4 18 2.5 3.6 2.5
4 5 2 1 1 3 12 9.5 2.4 9.5
5 2 4 2 5 3 16 5.0 3.2 5.0
6 5 3 2 4 4 18 2.5 3.6 2.5
7 5 4 1 4 1 15 6.5 3.0 6.5
8 4 5 2 1 3 15 6.5 3.0 6.5
9 4 2 5 4 4 19 1.0 3.8 1.0
10 1 4 2 3 4 14 8.0 2.8 8.0
3. Weighted mean score (i.e. I assume that V3 and V4 are more important than v1, v2 or v5)
> weights <- c(0.5, 0.5, 1, 1, 0.5)
> wmean <- function(x, w = weights){weighted.mean(x, w = w)}
> df$wmeans <- sapply(split(df[, 1:5], 1:10), wmean)
> df$ranks3 <- abs(rank(df$wmeans) - (dim(df)[1] + 1))
> df
v1 v2 v3 v4 v5 sum ranks means ranks2 wmeans ranks3
1 2 2 5 3 5 17 4.0 3.4 4.0 3.571429 2.5
2 2 1 2 3 4 12 9.5 2.4 9.5 2.428571 9.0
3 3 4 4 3 4 18 2.5 3.6 2.5 3.571429 2.5
4 5 2 1 1 3 12 9.5 2.4 9.5 2.000000 10.0
5 2 4 2 5 3 16 5.0 3.2 5.0 3.285714 5.0
6 5 3 2 4 4 18 2.5 3.6 2.5 3.428571 4.0
7 5 4 1 4 1 15 6.5 3.0 6.5 2.857143 6.0
8 4 5 2 1 3 15 6.5 3.0 6.5 2.571429 8.0
9 4 2 5 4 4 19 1.0 3.8 1.0 4.000000 1.0
10 1 4 2 3 4 14 8.0 2.8 8.0 2.714286 7.0