Extreme Optimization > User's Guide > Statistics Library > Continuous Variables > Time Variables

Extreme Optimization User's Guide

User's Guide

Up: Continuous Variables Next: Categorical Variables Previous: Transforming Numerical Variables Contents

Time Variables

Some variables represent time values. In the Extreme Optimization Statistics Library for .NET, such variables are implemented by the DateTimeVariable class. The observations are of type DateTime.

Constructing time variables

Time variables can be constructed in a variety of ways. The DateTimeVariable class has four constructors that come in two groups.

The first group uses a DateTime array as the source of the data. The first variant has two parameters. The first is a string that specifies the name of the variable. The second parameter is a DateTime array. The second variant only takes one parameter: a DateTime array containing the data values.

C# CopyCode imageCopy Code
DateTime[] dataArray = new DateTime[] { /* ... */ }
DateTimeVariable variable1 = new DateTimeVariable(dataArray);
DateTimeVariable variable2 = new DateTimeVariable("Data", dataArray);
Visual Basic CopyCode imageCopy Code
Dim dataArray As DateTime() = New DateTime() {}
Dim variable1 As DateTimeVariable = New DateTimeVariable("Data", dataArray)
Dim variable2 As DateTimeVariable = New DateTimeVariable(dataArray)

The second group of constructors uses a DataColumn as the source of the data. The first variant once again has two parameters. The first is a string that specifies the name of the variable. The second parameter is a DataColumn. This values in the data column must be of a type that can be converted to a DateTime. If not, an InvalidCastException is thrown. The second variant only takes one parameter: a DataColumn containing the data values. The name of the variable is set to the Caption property of the data column.

C# CopyCode imageCopy Code
DataColumn column;
// Connect to a data source and retrieve the column from a DataTable
DateTimeVariable variable3 = new DateTimeVariable(column);
DateTimeVariable variable4 = new DateTimeVariable("Data", column);
Visual Basic CopyCode imageCopy Code
Dim column As DataColumn
' Connect to a data source and retrieve the column from a DataTable
Dim variable3 As DateTimeVariable = New DateTimeVariable("Data", column)
Dim variable4 As DateTimeVariable = New DateTimeVariable(column)

In addition, variables can be created by VariableCollection objects, by performing arithmetic operations on them (see below), and several other means.

Descriptive Statistics

Time variables have more meaningful descriptive statistics than categorical variables, but less than numerical variables. The values are calculated as needed, and cached. The following tables list the descriptive statistics that are available for time variables:

Property Description
Mean Returns the mean or average of all obserrvations.
Median Returns the median.
StandardDeviation Returns the standard deviation of the data as a TimeSpan value.
Range Returns the difference between the largest and the smallest value.
Maximum Returns the largest value.
Minimum Returns the smallest value.
Table 1. Descriptive statistics for time variables.

The median is the middle value of a sorted list of observations. If a variable has an even number of observations, then the median is the average of the two middle values.

The standard deviation and the range are TimeSpan values. Other moments are not available because they do not have a meaningful unit of measure. The examle below shows how to use some of these properties:

C# CopyCode imageCopy Code
Console.WriteLine("Mean:               {0:F1}", variable1.Mean);
Console.WriteLine("Median:             {0:F1}", variable1.Median);
Console.WriteLine("Standard deviation: {0:F1}", variable1.StandardDeviation);
Console.WriteLine("Range:              {0:F1}", variable1.Range.TotalDays);
Visual Basic CopyCode imageCopy Code
Console.WriteLine("Mean:               {0:F1}", variable1.Mean)
Console.WriteLine("Median:             {0:F1}", variable1.Median)
Console.WriteLine("Standard deviation: {0:F1}", variable1.StandardDeviation)
Console.WriteLine("Range:              {0:F1}", variable1.Range.TotalDays)

Handling missing values

By default, missing values have the value DateTime.MinValue. You can change this by setting the variable's MissingValue property.

Missing values are ignored during the calculation of descriptive statistics. To force a different behavior, you must call the ReplaceMissingValues method. This method takes one or two parameters. The first is a MissingValueAction value that determines the action that is to be taken when a missing value is encountered. The options are summarized in the table below. The second, optional parameter is a replacement value, if one is required. It defaults to zero.

 Member Name  Description
Default Missing values are ignored.
Discard All missing observations are discarded.
Ignore Missing values are ignored.
ReplaceWithPrevious Missing values are replaced with the value of the previous observation. If the first observation is missing, it is replaced with a user-specified value, or 0.
ReplaceWithNext Missing values are replaced with the value of the next observation. If the last observation is missing, it is replaced with a user-specified value, or 0.
ReplaceWithValue Missing values are replaced with a user-specified value, or 0.
Fail A MissingValueException is thrown.
Table 6. MissingValueAction values.

The IsMissing method indicates whether an observation is missing. Its only parameter is the index of the observation.

Up: Continuous Variables Next: Categorical Variables Previous: Transforming Numerical 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