Setting up Your Data
The Problem
In the UK we retain a strange attachment to the ‘old’ units and although we buy our fuel in litres we check the performance of our cars in Miles per Gallon. In order to plot this vital statistic from the raw data, we will need to:
- convert from litres to gallons
- work out the miles run between each fill by subtracting successive odometer readings
- divide the miles run by the gallons used at each fill-up
The first thing to do is to set up a simple data-sheet, so choose Insert,Data sheet from the main menu and fill in the column properties:
The number of rows does not really matter here – GraPL creates new rows automatically if you cursor down from the bottom cell in the sheet. Here is the sheet with a few rows filled in – you will probably want to use your own data here, but you could always import my data from samples\rover.csv as a new data sheet.
Now to tackle some ‘hard sums’, which is what computers are supposed to be good at. We need to multiply the litres by 0.22 to fill in the gallons column, so switch to the ‘Calc’ tab and show the ‘Calculations’ pane in the right-hand window. In this case we just need a simple arithmetic expression, so drag an ‘Arith’ calculation into the spare space at the bottom of the sheet, to give something like this:
You can enter most reasonable arithmetic expressions here, but please refer to the reference help file before you try anything too adventurous! In this case we want to use as input the litres column multiplied by 0.22, and we want to put the output into the gallons column. What you might like to try is filling in ‘fuel*0.22’ in the Arith field, leaving the ‘Assign to’ field blank and pressing Enter – the status line will show ‘No target column – see View,Messages for output’ and if you bring up the Messages window you will see the result of the calculation in the window. If the numbers look reasonable, fill in ‘Gallons’ into the ‘Assign to’ field so that the result of the calculation is posted here. Your sheet should look like:
... and if you flip back to the data tab, you will see that the gallons have been worked out for you. Now for the tricky one – de-cumulating the odometer reading! If you check the help reference, one of the listed functions is called ‘Delta’ which does the opposite of function ‘Cum’ so we might try adding another calculation like this:
Press Enter and check the data-sheet to see the effect. You will notice that there is a slight oddity about the first row as we have travelled 11061 miles on no fuel! Fortunately GraPL takes a lenient attitude to division by zero (zeros are assumed to mean ‘no data’ so any operation involving zero gives a zero result) and we can add the final calculation to work out the miles travelled per gallon of fuel:
Make a final check on the data-sheet and if the numbers look reasonable we can carry on to plot some simple graphs. A good thing to try here is to use the right-mouse menu on the datasheet to bring up a full-screen view of the data as an independent window. The shortcut key for this is F11.
We can leave this window on screen while we work on a simple timeseries plot, then we will look at some of the more complex calculations dealing with averaging and smoothing the data. For reference, here is a summary of the basic arithmetic functions you can use – please see the reference manual for a complete list.
Summary of Arithmetic Functions
GraPL uses the basic arithmetic symbols +,-,*,/ much as you expect, but is tolerant of division by zero. Wherever you can put a number, you can put a numeric column. You can also use the symbols:
- ^ will raise any value to a power, so 3^2 is 9, col1^3 is the cube of every value in col1
- $ will take the absolute value, so $1 -2 3 is 1 2 3
- ? will generate random values from 1 up to the value on the right. so ?4 of 12 could be 6 5 4 10
- ! will generate factorials, or binomial probabilities if used with numbers on both sides (commonly written nCr)
- ; (semi-colon) will chain any pair of lists together as a single list (e.g. col1;col2;col3)
There are also lots of basic maths functions available as words, for example:
- log and ln take logs to base 10 and base-e respectively. You can actually use ln with a number on the left to take logs to any base you like, so 2 ln 3 4 5 is 1.58496 2 2.32193
- Sin, Cos and Tan do what you would expect with values in degrees
- Cum and Delta will cumulate and decumulate a numeric column
- Count will tell you the number of elements in a column and Sum will add it up
- Of will generate a simple series for you e.g. 12 of 1;2 will fill a column with 1 2 1 2 .... up to 12 elements
- To will make an arithmetic progression, so 5 to 14 is the numbers 5,6 ... 14
You can combine these functions to generate all sorts of complex formulae – just remember that GraPL behaves like a simple calculator and does not make any attempt to put * before + or ^ before * and so on. So to make the series 2 4 6 8 just put in a calculation like 2*1 to 4 (read it as 2 times 1 to 4) or use lots of parentheses to make the order clear.
Continue to: Plotting the Raw Timeseries
|