# Multi criteria decision analysis

Source: `R/mcda.R`
`mcda.Rd`

Conduct a multi criteria decision analysis (MCDA) and compute scores for competing treatment strategies using output from a probabilistic sensitivity analysis (PSA).

    mcda(x, sample, strategy, criteria, criteria_min = NULL,
      criteria_max = NULL, optimal = NULL, weights, score_min = 0,
      score_max = 100)

## Arguments

x | A `data.frame` or `data.table` of simulation output characterizing the probability distribution of model outcomes.
sample | Character name of column from `x` denoting a randomly sampled parameter set from the PSA.
strategy | Character name of column from `x` denoting treatment strategy.
criteria | A vector of character names of columns from `x` denoting the criteria to use in the MCDA.
criteria_min | A vector of minimum values for each criterion. If `NULL`, then the minimum value is computed automatically.
criteria_max | A vector of maximum values for each criterion. If `NULL`, then the maximum value is computed automatically.
optimal | A character vector denoting whether the optimal value of each criteria is `"low"` or `"high"`. If an element is `"low"`, then lower performance on that criterion is better, and, if an element is `"high"`, then higher performance on that criterion is better. Must be specified if either `criteria_min` or `criteria_min` is `NULL`.
weights | Weights to apply to each criteria. Internally normalized to sum to 1.
score_min | Minimum of total value score. Default is 0.
score_max | Maximum of total value score. Default is 100.

## See also

`performance_matrix`, `lpvf_plot_data`

## Examples

    n_samples <- 5
    strategies <- c("Strategy 1", "Strategy 2")
    outcome1 <- c(rnorm(n_samples, mean = 10, sd = 5),
                  rnorm(n_samples, mean = 8, sd = 4))
    outcome2 <- c(rnorm(n_samples, mean = 1500, sd = 90),
                  rnorm(n_samples, mean = 1000, sd = 100))
    outcomes <- data.frame(sample = rep(1:n_samples, length(strategies)),
                           strategy_id = rep(strategies, each = n_samples),
                           criteria1 = outcome1,
                           criteria2 = outcome2)

    # Performance matrix
    performance_mat <- performance_matrix(outcomes,
                                          strategy = "strategy_id",
                                          criteria = c("criteria1", "criteria2"),
                                          rownames = c("Criteria 1", "Criteria 2"),
                                          colnames = strategies)
    print(performance_mat)#>            Strategy 1             Strategy 2
    #> Criteria 1 "8.82 (1.14, 15.55)"   "3.77 (0.99, 6.83)"
    #> Criteria 2 "1,447 (1,316, 1,574)" "974 (822, 1,181)"
    # MCDA
    weights <- c(.7, .3)
    mcda <- mcda(outcomes, sample = "sample", strategy = "strategy_id",
                 criteria = c("criteria1", "criteria2"),
                 weights = weights,
                 optimal = c("low", "high"))
    names(mcda)#> [1] "scores"          "weighted_scores" "total_value"     "prob_rank"
    # Scores on common scale
    print(mcda$scores)#>     sample strategy_id criteria1 criteria2
    #>  1:      1  Strategy 1  34.92297  79.33347
    #>  2:      2  Strategy 1 100.00000 100.00000
    #>  3:      3  Strategy 1  69.20929  81.52684
    #>  4:      4  Strategy 1   0.00000  63.60754
    #>  5:      5  Strategy 1  30.51387  86.45465
    #>  6:      1  Strategy 2  99.16234  31.71191
    #>  7:      2  Strategy 2  86.55179  49.55827
    #>  8:      3  Strategy 2  58.46559  11.85367
    #>  9:      4  Strategy 2  82.03813   0.00000
    #> 10:      5  Strategy 2  72.69201  11.65839
    # "Total value"
    print(mcda$total_value)#>     sample strategy_id     score rank
    #>  1:      1  Strategy 1  48.24612    2
    #>  2:      2  Strategy 1 100.00000    1
    #>  3:      3  Strategy 1  72.90455    1
    #>  4:      4  Strategy 1  19.08226    2
    #>  5:      5  Strategy 1  47.29610    2
    #>  6:      1  Strategy 2  78.92721    1
    #>  7:      2  Strategy 2  75.45374    2
    #>  8:      3  Strategy 2  44.48201    2
    #>  9:      4  Strategy 2  57.42669    1
    #> 10:      5  Strategy 2  54.38192    1
    # "Total value" decomposed by criteria
    print(mcda$weighted_scores)#>     sample strategy_id  criteria weighted_score
    #>  1:      1  Strategy 1 criteria1      24.446082
    #>  2:      2  Strategy 1 criteria1      70.000000
    #>  3:      3  Strategy 1 criteria1      48.446501
    #>  4:      4  Strategy 1 criteria1       0.000000
    #>  5:      5  Strategy 1 criteria1      21.359708
    #>  6:      1  Strategy 2 criteria1      69.413638
    #>  7:      2  Strategy 2 criteria1      60.586255
    #>  8:      3  Strategy 2 criteria1      40.925914
    #>  9:      4  Strategy 2 criteria1      57.426691
    #> 10:      5  Strategy 2 criteria1      50.884407
    #> 11:      1  Strategy 1 criteria2      23.800041
    #> 12:      2  Strategy 1 criteria2      30.000000
    #> 13:      3  Strategy 1 criteria2      24.458051
    #> 14:      4  Strategy 1 criteria2      19.082263
    #> 15:      5  Strategy 1 criteria2      25.936395
    #> 16:      1  Strategy 2 criteria2       9.513574
    #> 17:      2  Strategy 2 criteria2      14.867482
    #> 18:      3  Strategy 2 criteria2       3.556100
    #> 19:      4  Strategy 2 criteria2       0.000000
    #> 20:      5  Strategy 2 criteria2       3.497517
    # Probability of ranking
    print(mcda$prob_rank)#>    strategy_id rank N prob
    #> 1:  Strategy 1    1 2  0.4
    #> 2:  Strategy 1    2 3  0.6
    #> 3:  Strategy 2    1 3  0.6
    #> 4:  Strategy 2    2 2  0.4