DataFrames in Statistics - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Statistics and Data Analysis : Statistics Package : Statistics/DataFrames

DataFrames in Statistics

 

Description

Examples

Description

• 

This help page describes how to use Statistics commands on DataFrame objects, and other spreadsheet-type data in matrices, sometimes called Matrix data sets.

• 

Many of the data sets you might encounter are two-dimensional in nature. They will have information about a number of items or events; for each item or event, the same properties are known. Such data sets can easily be represented in a DataFrame by having each row correspond to an item and each column to one property of all these items. This is how you would typically store such data in a spreadsheet. You can also store such data in a Matrix, as long as you keep track of labels for the rows and columns yourself.

• 

Many commands in the Statistics package can be used with this type of data:

– 

The following computational commands can be run on DataFrame objects (or Matrices). They are computed per column and the results are returned in a DataSeries object. The labels for the DataSeries are the column labels of the DataFrame. Alternatively, they are computed per column of a Matrix and the results are returned in a row Vector.

AbsoluteDeviation

CentralMoment

Count

CountMissing

Cumulant

DataSummary

Decile

Detrend

Difference

ExpectedValue

FivePointSummary

GeometricMean

HarmonicMean

HodgesLehmann

InterquartileRange

Kurtosis

Mean

MeanDeviation

Median

MedianDeviation

Mode

Moment

Percentile

QuadraticMean

Quantile

Quartile

Range

RousseeuwCrouxQn

RousseeuwCrouxSn

Scale

Skewness

StandardDeviation

StandardError

StandardizedMoment

TrimmedMean

Variance

Variation

WinsorizedMean

 

 

  

 

– 

The following visualization commands, listed on the Statistics Visualization help page, also accept DataFrame objects. Generally, the row and column labels are used to label data points and data sets, respectively, as appropriate.

AgglomeratedPlot

AreaChart

BarChart

Biplot

BoxPlot

BubblePlot

ColumnGraph

CumulativeSumChart

ErrorPlot

FrequencyPlot

GridPlot

LineChart

ParetoChart

PointPlot

ScatterPlot

ScreePlot

ViolinPlot

 

 

 

  

 

– 

Statistics[SplitByColumn] and Statistics[Join] split Matrices into submatrices and join them back together.

– 

DataFrame/Aggregate does similar things for DataFrame objects.

• 

Additional examples are found in the Statistics with DataFrames example worksheet.

Examples

with(Statistics):

We construct a DataFrame with housing data. The first column has number of bedrooms, the second has the area in square feet, the third has price.

bedrooms := <3, 4, 2, 4, 3, 2, 2, 3, 4, 4, 2, 4, 4, 3, 3>;

_rtable18446883940617134078

(1)

area := <1130, 1123, 1049, 1527, 907, 580, 878, 1075, 1040, 1295, 1100, 995, 908, 853, 856>;

_rtable18446883940499542014

(2)

price := <114700, 125200, 81600, 127400, 88500, 59500, 96500, 113300, 104400, 136600, 80100, 128000, 115700, 94700, 89400>;

_rtable18446883940499543814

(3)

HouseSalesData := DataFrame([bedrooms, area, price], columns=[Bedrooms, Area, Price]);

DataFrame_rtable18446883940499536582&comma;rows&equals;1&comma;2&comma;3&comma;4&comma;5&comma;6&comma;7&comma;8&comma;9&comma;10&comma;11&comma;12&comma;13&comma;14&comma;15&comma;columns&equals;Bedrooms&comma;Area&comma;Price

(4)

We can determine the average number of bedrooms, average area, and average price with just the Mean command.

Mean(HouseSalesData);

DataSeries3.13333333333333331021.06666666666671.0370666666666667105&comma;labels&equals;Bedrooms&comma;Area&comma;Price&comma;datatype&equals;float8

(5)

We can also determine the standard error for this mean.

StandardError(Mean, HouseSalesData);

DataSeries0.2152886581991869756.083226137306445615.399461401755&comma;labels&equals;Bedrooms&comma;Area&comma;Price&comma;datatype&equals;float8

(6)

Or the 30th percentile for each column.

Percentile(HouseSalesData, 30);

DataSeries2.9333333333333327905.066666666666689340.0&comma;labels&equals;Bedrooms&comma;Area&comma;Price&comma;datatype&equals;float8

(7)

The GridPlot command can display scatter plots of pairs of columns.

GridPlot(HouseSalesData);

Tabulate

(8)

Bedrooms

Area

Price

 

We can use the lower diagonal entries to display the values for the correlation.

GridPlot(HouseSalesData, lower = Correlation);

Tabulate0

(9)

Bedrooms

0.488597380223581068

Area

0.835789649694966386

0.704398937794964319

Price

 

We can determine the average area and price for subgroups of sales defined by number of bedrooms. (The Aggregate command is part of the DataFrame object, not the Statistics package, so it is not available for Matrices.)

Aggregate(HouseSalesData, Bedrooms);

DataFrame2901.7579425.03964.21.00120010541148.01.2288333333333333105&comma;rows&equals;1&comma;2&comma;3&comma;columns&equals;Bedrooms&comma;Area&comma;Price

(10)

To create a box plot of prices for each number of bedrooms requires a little more effort.

split := SplitByColumn(HouseSalesData, Bedrooms);

splitBedroomsAreaPrice3210498160062580595007287896500112110080100&comma;BedroomsAreaPrice13113011470053907885008310751133001438539470015385689400&comma;BedroomsAreaPrice2411231252004415271274009410401044001041295136600124995128000134908115700

(11)

price_split := map(df -> convert(df[Price], Vector), split);

81600595009650080100&comma;114700885001133009470089400&comma;125200127400104400136600128000115700

(12)

BoxPlot(price_split, datasetlabels=[2, 3, 4]);

Most of the things mentioned above can be done with a Matrix, too. Consider the following examples.

HSD_Matrix := convert(HouseSalesData, Matrix);

_rtable18446883940452906518

(13)

Mean(HSD_Matrix);

3.13333333333333331021.06666666666671.0370666666666667105

(14)

Percentile(HSD_Matrix, 30);

2.9333333333333327905.066666666666689340.0

(15)

Some commands have calling sequences where one of the arguments is compared to the data; this is the case for the second argument of AbsoluteDeviation and for the origin parameter of Moment. In these cases, it typically does not make much sense to use the same value for each column, so Maple supports using a list or Vector of values instead. These commands do not yet work directly with DataFrame objects.

AbsoluteDeviation(HSD_Matrix, [3, 1000, 100000]);

0.6666666666666666157.4666666666666718333.333333333332

(16)

StandardError(Moment, HSD_Matrix, 1, origin=[3, 1000, 100000]);

0.207988603676401654.1815439398297665424.991278368138

(17)

 

See Also

examples/DataFrame/Statistics