Home

Staff
     
Consulting
               
Mathematica Tools

Customer Quotes
        
Contact

Older Mathematica Items

 

 

 

 

 

Scientific Arts

From Simple Tabular Formatting to Automatic Report Generation


Formatting a Simple Table

Let us say that we want produce a tabular report on the analysis of several sets of data contained in columnar format in an external file. The data are in the file file.dat. We first import the data. (If file.dat is not placed in a directory that is contained in Mathematica's $Path variable, you can make it available by executing the function [Graphics:Images/formatting_gr_1.gif] where path is the path to the needed directory.)

[Graphics:Images/formatting_gr_2.gif]

Since the data are in columns and the ReadList function returns a list of rows we can access the data by transposing the matrix of data.

[Graphics:Images/formatting_gr_3.gif]

Load in the standard package Statistics`DescriptiveStatistics`.

[Graphics:Images/formatting_gr_4.gif]

This package contains functions that give various statistical properties of a data set. Here we want to compute the first four moments of the data: the mean, variance, and skewness. To do this efficiently we write a small function that does it all at once.

[Graphics:Images/formatting_gr_5.gif]

The following then gives us a list of the desired statistics for each of the data sets. The function Map effectively applies the DataStatistics function to each of the data sublists.

[Graphics:Images/formatting_gr_6.gif]
[Graphics:Images/formatting_gr_7.gif]

These results can be presented as a table using the formatting command TableForm.

[Graphics:Images/formatting_gr_8.gif]

Out[6]=

[Graphics:Images/formatting_gr_9.gif]

Considerably more control can be exercised by using a GridBox. There are many approaches to this, here is an example. First we wrap GridBox around stats and format it by using DisplayForm.

[Graphics:Images/formatting_gr_10.gif]

Out[7]=

[Graphics:Images/formatting_gr_11.gif]

By using options we can modify this to add a frame and column lines.

[Graphics:Images/formatting_gr_12.gif]

Out[8]=

[Graphics:Images/formatting_gr_13.gif]

In the following we reduce the number of digits in the displayed numbers and add color to the column headings.

[Graphics:Images/formatting_gr_14.gif]
[Graphics:Images/formatting_gr_15.gif]
Out[12]=

[Graphics:Images/formatting_gr_16.gif]

The following prints a formatted cell. The visual result is the same as above, but note that the cell that is returned does not have a cell label.

[Graphics:Images/formatting_gr_17.gif]

[Graphics:Images/formatting_gr_18.gif]

Here we use CellPrint to print three cells in sequence (the individual cells are contained as the elements of the list that is the argument of CellPrint). The three cells that follow this command are the result of executing it. Thus we are essentially writing a small report.

[Graphics:Images/formatting_gr_19.gif]

[Graphics:Images/formatting_gr_20.gif]

[Graphics:Images/formatting_gr_21.gif]

[Graphics:Images/formatting_gr_22.gif]


 

A Simple Prototype of an Automatically Generated Report

The following, when executed, creates a new notebook that has a heading cell followed by a cell with explanatory text and then a cell with the above table. This is therefore a simple example of automatic report generation. (NotebookPut creates the notebook that is defined by the Notebook object which itself contains a list of Cells.)

[Graphics:Images/formatting_gr_23.gif]
[Graphics:Images/formatting_gr_24.gif]

We are surpressing the display of the generated notbook here, it is displayed (as the output of the function DataReport defined below) at the bottom of this page.

In fact, we can combine the steps that we used above to create a function that automatically generates a report from a data file. The function requires both the function DataStatistics that we defined above as well as the standard package Statistics`DescriptiveStatistics`.

[Graphics:Images/formatting_gr_25.gif]

Here is the report.

[Graphics:Images/formatting_gr_26.gif]
[Graphics:Images/formatting_gr_27.gif]


For further information on our services send email to info@scientificarts.com .
Contents of this web site Copyright © 1999-2011, Scientific Arts, LLC.

s