Learn R Programming

DEXiR (version 1.0.2)

compare_alternatives: compare_alternatives

Description

Compare Alternatives Analysis: Compare alternative with each of alternatives. Display only values that differ and, optionally when compare = TRUE, include preference-relational operators.

Usage

compare_alternatives(
  model,
  alternative,
  alternatives = NULL,
  root = NULL,
  compare = TRUE,
  deep = TRUE,
  print = TRUE,
  as_character = FALSE,
  round = NULL,
  id = NULL,
  evaluate = FALSE,
  ...
)

Value

Returns or prints a data.frame consisting of columns: id (if requested), structure (if requested), values of alternative and comparison results for each alternative from alternatives.

Arguments

model

A DexiModel object. Required.

alternative

Either a data.frame representing a single alternative or an integer index to model$alternatives.

alternatives

Either a data.frame representing one or more alternatives, or an integer numeric vector representing indices to model$alternatives. By default, alternatives are set to model$alternatives, possibly excluding alternative when indexed.

root

Optional DexiAttribute object. When specified, only attributes that affect root are included in the analysis. Otherwise, all model$attributes are included.

compare

logical(1). Whether or not preference relations "<", ">", "<=", ">=" are included in results.

deep

logical(1). Whether of not "deep" comparison (see compare_two_alternatives()) is carried out.

print

logical(1). When TRUE, pretty print (left justify) the results.

as_character

logical(1). Whether to represent alternative values numerically (FALSE) or using text (TRUE).

round

An integer number, argument to value_text().

id

character(1). Determines the contents of the first or first two columns of the resulting data.frame:

"id"

Attribute ID.

"structure"

Attribute $structure() + $name.

anything else

Equivalent to both "id" and "structure".

evaluate

logical(1). Whether or not to evaluate alternative and alternatives beforehand.

...

Optional parameters for evaluate().

See Also

compare_two_alternatives(), evaluate()

Examples

Run this code
# Load "Car.dxi"
CarDxi <- system.file("extdata", "Car.dxi", package = "DEXiR")
Car <- read_dexi(CarDxi)

# Extend Car$alternatives
car3 <- set_alternative(Car, Car$alternatives[2,], name = "Car3", LUGGAGE = 2)
Car$alternatives[3,] <- car3
car4 <- set_alternative(Car, Car$alternatives[2,], name = "Car4", LUGGAGE = 1)

# Compare Car1 with the other two, varying some arguments
compare_alternatives(Car, 1, evaluate=TRUE, compare=FALSE)
compare_alternatives(Car, 1, evaluate=TRUE, compare=TRUE)
compare_alternatives(Car, 1, evaluate=TRUE, compare=TRUE, deep=FALSE)

# Compare Car2 with Car1
compare_alternatives(Car, 2, 1)

# Compare car3 with Car1 and Car2
compare_alternatives(Car, car3, 1:2)

# Compare car4 with Car$alternatives
compare_alternatives(Car, car4)

# Compare Car$alternatives[1,] with car3
compare_alternatives(Car, 1, car3)
compare_alternatives(Car, Car$alternatives[1,], car3)

Run the code above in your browser using DataLab