Extreme Optimization™: Complexity made simple.

Numerical Components
for .NET

  • Home
  • Features
    • Math Library
    • Vector and Matrix Library
    • Statistics Library
    • Performance
    • Usability
  • Documentation
    • Introduction
    • Math Library User's Guide
    • Vector and Matrix Library User's Guide
    • Statistics Library User's Guide
    • Reference
  • Resources
    • Downloads
    • QuickStart Samples
    • Sample Applications
    • Frequently Asked Questions
    • Technical Support
  • Blog
  • Order
  • Company
    • About us
    • Testimonials
    • Customers
    • Press Releases
    • Careers
    • Contact us
Introduction
Deployment Guide
Using Parallelism
Expand Mathematics Library User's GuideMathematics Library User's Guide
Expand Vector and Matrix Library User's GuideVector and Matrix Library User's Guide
Expand Statistics Library User's GuideStatistics Library User's Guide
Expand ReferenceReference
  • Home
    • Features
    • Solutions
    • Documentation
    • QuickStart Samples
    • Sample Applications
    • Downloads
    • Technical Support
    • Download trial
    • How to buy
    • Blog
    • Company
    • Resources
  • Documentation
    • Introduction
    • Deployment Guide
    • Using Parallelism
    • Mathematics Library User's Guide
    • Vector and Matrix Library User's Guide
    • Statistics Library User's Guide
    • Reference
  • Statistics Library User's Guide
    • Statistical Variables
    • Continuous Variables
    • Categorical Variables
    • Variable Collections
    • General Linear Models
    • Regression Analysis
    • Analysis of Variance
    • Time Series Analysis
    • Multivariate Analysis
    • Continuous Distributions
    • Discrete Distributions
    • Multivariate Distributions
    • Hypothesis Tests
    • Histograms
    • Random Numbers
    • Appendices
  • Categorical Variables
    • Categorical Scales
    • Numerical Scales
    • Time Scales
    • Categorical Variables
  • Categorical Scales
Collapse image Expand Image Copy image CopyHover image
         




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#  Copy imageCopy
string[] colorArray = new string[]
    {"red", "green", "blue"};
CategoricalScale scale1 = new CategoricalScale(dataArray);
Visual Basic  Copy imageCopy
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#  Copy imageCopy
string[] qualityArray = new string[]
    {"poor", "average", "good"};
CategoricalScale scale2 = new CategoricalScale(dataArray, true);
Visual Basic  Copy imageCopy
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#  Copy imageCopy
enum Shape
{
    Round,
    Square,
    Rectangular
}
CategoricalScale scale3 = new CategoricalScale(typeof(Shape));
Visual Basic  Copy imageCopy
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#  Copy imageCopy
enum Quality
{
    Poor,
    Average,
    Good
}
CategoricalScale scale3 = new CategoricalScale(typeof(Quality), true);
Visual Basic  Copy imageCopy
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[([( Int32])]) 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(Object) 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#  Copy imageCopy
Console.WriteLine(scale2[1]); // Prints 'average.'
Console.WriteLine(scale2.GetLevelIndex("poor")); // Prints '0.'
Visual Basic  Copy imageCopy
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:

  • The NumericalScale class maps real numbers to intervals. This can be used to create histograms.
  • The DateTimeScale class maps DateTime values to time intervals.

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

Send comments on this topic to support@extremeoptimization.com

Copyright (c) 2004-2011 ExoAnalytics Inc.

Copyright © 2003-2013, Extreme Optimization. All rights reserved.
Extreme Optimization, Complexity made simple, M#, and M Sharp are trademarks of ExoAnalytics Inc.
Microsoft, Visual C#, Visual Basic, Visual Studio, Visual Studio.NET, and the Optimized for Visual Studio logo
are registered trademarks of Microsoft Corporation.