Learn R Programming

DEXiR (version 1.0.2)

convert_alternatives: convert_alternatives

Description

Converts a data.frame of alternatives' data to another data.frame. The conversion generally involves: aggregating DEXi values originally represented by sets or distributions, scaling aggregated values to a given interval and/or reversing values assigned to "descending" DexiScales.

Usage

convert_alternatives(
  model,
  alternatives = NULL,
  interpret = c("set", "distribution", "none"),
  aggregate = min,
  omin = 0,
  omax = 1,
  map_values = TRUE,
  reverse_descending = TRUE,
  verbatim = "name",
  skip = NULL,
  continuous = convert_data_continuous,
  discrete = convert_data_discrete
)

Value

A converted data.frame.

Arguments

model

A DexiModel object. Required.

alternatives

A data.frame of alternatives (normally an output of evaluate()) or indices to model$alternatives. The default value NULL selects model$alternatives.

interpret

character(1). Determines how the original values in alternatives are interpreted, i.e., converted prior to submitting them to aggregate():

"set"

As a set of values. Any distribution-type value is converted to a set, thus discarding the numeric membership information.

"distribution"

As a value distribution, i.e., a numeric vector of membership values.

"none"

No conversion.

Values corresponding to continuous attributes are not converted nor affected by these settings.

aggregate

A function accepting the interpreted DEXi value (see interpret) and converting it to become part of the output data frame. Normally, this function is assumed to accept a numeric vector argument and aggregate it in a single numeric value. The default aggregation function is min(). Typical alternatives include max() and mean().

omin

numeric(1). Lower bound of the output value interval (see map_values). Default: 0.

omax

numeric(1). Upper bound of the output value interval (see map_values). Default: 1.

map_values

logical(1). When TRUE, values produced by aggregate() are further scaled to the interval [omin:omax]. Input bounds are determined from the corresponding attribute scales (for discrete attributes) or as minimum/maximum values from alternatives (for continuous attributes).

reverse_descending

logical(1). Whether or not to reverse the values of attributes whose scales are of a "descending" preference order.

verbatim

character(). Names of alternatives' data columns that are included in the output without conversion. Default: "name".

skip

character(). Names of alternatives' data columns that are ignored in the process. Default: NULL.

continuous

A function converting a data column that corresponds to a continuous attribute. Default: convert_data_continuous(). Setting continuous to NULL excludes all continuous attributes from conversion.

discrete

A function converting a data column that corresponds to a discrete attribute. Default: convert_data_discrete(). Setting discrete to NULL excludes all discrete attributes from conversion.

Details

The rationale for convert_alternatives() is that data frames representing alternatives, particularly those produced by evaluate(), generally contain DEXi values of various and mixed data types, such as numbers and numeric vectors (sets and distributions). As such, this data is difficult to work with in R, as most R functions expect simpler and more uniform data structures. convert_alternatives() produces data frames that are more suitable for standard R data analysis and graph drawing. However, as the conversion generally involves aggregation and mapping of DEXi values, it may distort or lose information along the way.

See Also

convert_data_continuous(), convert_data_discrete(), scale_alternatives(), DEXiR-package notes on values in DEXi models.

Examples

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

# Map Car$alternatives' values to the [0, 1] interval.
convert_alternatives(Car)

#  name     CAR.1 PRICE BUY.PRICE MAINT.PRICE TECH.CHAR. COMFORT X.PERS   X.DOORS LUGGAGE SAFETY
# 1 Car1 1.0000000   1.0       0.5         1.0  1.0000000       1      1 0.6666667       1    1.0
# 2 Car2 0.6666667   0.5       0.5         0.5  0.6666667       1      1 0.6666667       1    0.5

Run the code above in your browser using DataLab