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# | Copy Code |
DateTime[] dataArray = new DateTime[] { /* ... */ }
DateTimeVariable variable1 = new DateTimeVariable(dataArray);
DateTimeVariable variable2 = new DateTimeVariable("Data", dataArray); |
| Visual Basic | Copy 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# | Copy 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 | Copy 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# | Copy 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 | Copy 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
Copyright 2004-2008,
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 Visual Studio Logo are registered trademarks of Microsoft Corporation