topsis: TOPSIS Method for Multi-Criteria Decision Making

View source: R/topsis.R

topsisR Documentation

TOPSIS Method for Multi-Criteria Decision Making

Description

Implements the Technique for Order of Preference by Similarity to Ideal Solution (TOPSIS) method to rank alternatives based on multiple criteria. The decision matrix A must contain positive indicators (larger values are better) or be preprocessed using functions like rescale, normalize, rescale_middle, or rescale_interval from the mathmodels package. The function normalizes the matrix, applies weights, and computes relative closeness to the ideal solution.

Usage

topsis(A, w)

Arguments

A

Numeric matrix, the decision matrix where rows are alternatives and columns are criteria. All criteria must be positive indicators (larger is better) or preprocessed to satisfy this condition.

w

Numeric vector, weights for each criterion. Must be non-negative and sum to a positive value.

Details

The TOPSIS method ranks alternatives by:

  1. Normalizing the decision matrix using L2 norm (similar to normalize).

  2. Applying weights to form a weighted normalized matrix.

  3. Identifying positive and negative ideal solutions (column max/min).

  4. Computing Euclidean distances to ideal solutions.

  5. Calculating relative closeness as S0 / (S0 + Sstar), where S0 is the distance to the negative ideal and Sstar is the distance to the positive ideal.

Since A must contain positive indicators, use rescale for Min-Max normalization, rescale_middle for centered indicators, or rescale_interval for interval indicators before calling topsis(). NA values in A may affect results and trigger a warning.

Value

A named numeric vector of the same length as the number of rows in A, containing relative closeness scores in 0, 1. Higher values indicate better alternatives. Names are taken from rownames(A) or default to "Sample1", "Sample2", etc.

References

Hwang, C. L., & Yoon, K. (1981). Multiple Attribute Decision Making: Methods and Applications. The mathmodels_penguins dataset is derived from the palmerpenguins package.

Examples

A = data.frame(
  X1 = c(2, 5, 3),  # "+"
  X2 = c(8, 1, 6)   # "+"
)
w = c(0.6, 0.4)
topsis(A, w)

zhjx19/mathmodels documentation built on June 2, 2025, 12:18 a.m.