Extreme Optimization > User's Guide > Statistics Library > Categorical Variables > Categorical Scales

Extreme Optimization User's Guide

User's Guide

Up: Categorical Variables Next: Numerical Scales Previous: Categorical Variables Contents

Categorical Scales

A scale represents the possible values that a variable can have. In this section, we will only deal with discrete or categorical scales, where the number of possible values is finite. These possible values are often referred to as the levels of the scale. Each level is assigned a numerical value called the level index.

A scale can be ordered or unordered. On an ordered scale, it is meaningful to compare different values. For example, the values 'good', 'average', 'bad' have a clear order, while 'red', 'orange', and 'purple' do not. An unordered categorical scale is sometimes called a nominal scale. An ordered categorical scale is sometimes called an ordinal scale.

Scales are implemented by the CategoricalScale class. The levels of the scale can be any object.

Two derived classes, NumericalScale and DateTimeScale, implement scales whose levels represent an interval of numerical values or DateTime values, respectively. These are covered in subsequent sections.

Constructing Scales

The CategoricalScale class has four constructors.

The first constructor takes one argument: an object that implements the ICollection interface. This can be, for example, an array or an array list. The members of the collection are taken as the levels of the scale. The scale is unordered.

C# CopyCode imageCopy Code
string[] colorArray = new string[]
    {"red", "green", "blue"};
CategoricalScale scale1 = new CategoricalScale(dataArray);
Visual Basic CopyCode imageCopy Code
Dim colorArray As String() = New String() _
    {"red", "green", "blue"}
Dim scale1 As CategoricalScale = New CategoricalScale(dataArray)

The second constructor takes one additional boolean parameter that specifies whether the scale is ordered. A value of true indicates that the scale is ordered.

C# CopyCode imageCopy Code
string[] qualityArray = new string[]
    {"poor", "average", "good"};
CategoricalScale scale2 = new CategoricalScale(dataArray, true);
Visual Basic CopyCode imageCopy Code
Dim qualityArray As String() = New String() _
    {"poor", "average", "good"}
Dim scale2 As CategoricalScale = New CategoricalScale(dataArray, True)

The third constructor takes one System.Type parameter, which must be an enumeration type. The levels of the scale are the values of the enum variable. By default, the scale is unordered.

C# CopyCode imageCopy Code
enum Shape
{
    Round,
    Square,
    Rectangular
}
CategoricalScale scale3 = new CategoricalScale(typeof(Shape));
Visual Basic CopyCode imageCopy Code
Enum Shape
    Round,
    Square,
    Rectangular
End Enum
Dim scale3 As CategoricalScale = New CategoricalScale(GetType(Shape))

The fourth constructor adds a boolean parameter that indicates if the scale is ordered.

C# CopyCode imageCopy Code
enum Quality
{
    Poor,
    Average,
    Good
}
CategoricalScale scale3 = new CategoricalScale(typeof(Quality), true);
Visual Basic CopyCode imageCopy Code
Enum Quality
    Poor,
    Average,
    Good
End Enum
Dim scale4 As CategoricalScale = New CategoricalScale(GetType(Quality), True)

In addition, scales can be constructed from categorical variables. This is covered in a later section.

Properties and Methods

The Count property returns the number of levels in the scale. The IsOrdered property indicates whether the scale is ordered or unordered. Certain descriptive statistics, such as the median, are only available for ordered scales.

The CategoricalScale class has an Item property, which serves as the indexer property in C#. It returns the object that represents the level corresponding to the specified level index. Level indices range from 0 to Count-1 The GetLevelIndex method performs the inverse operation: it returns the level index corresponding to the specified level. If the level isn't found, the value -1 is returned. The GetLevels method returns an object array containing all the levels.

C# CopyCode imageCopy Code
Console.WriteLine(scale2[1]); // Prints 'average.'
Console.WriteLine(scale2.GetLevelIndex("poor")); // Prints '0.'
Visual Basic CopyCode imageCopy Code
Console.WriteLine(scale2.Item(1)) ' Prints 'average.'
Console.WriteLine(scale2.GetLevelIndex("poor")) ' Prints '0.'

The GetCaption method returns the text label of the level at the specified level index. The GetCaptions method returns a string array containing the captions for each level.

The GetEnumerator method returns an IEnumerator object that can be used to iterate through the levels of the scale.

Scales as Mappings

It often happens that some numerical measurement must be converted into one of a number of categories. For example, a blood pressure reading may be classified as 'low,' 'normal,' or 'high.' A scale can be used for this purpose. Or we may be interested in the month of the year a certain date fell in. Two Map methods support this functionality.

The first Map overload takes an object as its argument and returns the level index of the level the object maps to. The second Map overload takes an array of objects and returns an integer array of the level indexes corresponding to those objects.

The CategoricalScale class only supports the trivial mapping from each level to itself. But several derived classes support more meaningful mappings:

These classes are discussed in greater detail in the next two sections.

Up: Categorical Variables Next: Numerical Scales Previous: Categorical Variables Contents

Overview
Introduction
Features
Documentation
QuickStart Samples
Sample Applications
Downloads
Get it now!
Download trial version
How to Buy
Information
Resources
Contact Us
Search

"The Extreme Optimization Statistics Library for .NET is a major boon for those doing statistical work in .NET. I strongly recommend this product."
- Marc Brooks

"I have made it my mission to institutionalize the value of good API design.  I strongly believe that this is key to making developers more productive and happy on our platform. It is clear that you value good API design in your work, and take to heart developer productivity and synergy with the .NET framework."
- Brad Abrams,
Lead Program Manager, Microsoft.

This is a partial list of companies who are using our libraries:
ABB Robotics
Allstate
Applied Materials
Arcam
Astra Schedule
Babson College
Canadian Council on Learning
Canyon Associates
Caxton Associates
CECity
Constellation Energy
CreditSights
DeepOcean
Duke University
Dynamotive
Elecsoft
Engelhard Corporation
Epcor
Equipoise Software
Galileo International
GAM UK
Gammex
GlaxoSmithKline
Global Matrix
The Hartford
Infinera Corporation
Intel
JDS Uniphase
LaBranche & Co.
Learning & Skills Council
Jacobs Consultancy
Litman Gregory
Lucas Systems
Malvern Instruments
Medrio
Merck & Co.
Mintera.
Monitor Software
MorningStar
NanoString Technologies
Paletta Invent
Parametric Portfolio Associates
Prosanos
RATA Associates
RiskShield
Ramboll
Standard & Poor's
Strategic Analysis Corporation
Univ. of Alicante
Univ. of South Carolina
vielife
Xerox
US Army