Examples:
 

 

Example - Wheather Analysis

* The "\" symbol has been used at the end of lines to indicate that the line was too long for the display and has been
wrapped to the line below in order to fit within the width of the web page. These lines would need to be joined in the normal
program editor.


I. Introduction

This program performs a very simple statistical analysis of some meteorological data, with a view to constructing a formula that could be used to estimate the daily temperature considered as a function of time of year.



II. Mathematics Involved

The most basic approximation in this example is that of the arithmetic mean, calculated in the normal way,

where n is the number of data points. The further two approximations use an approach which is essentially that of finding terms in a finite Fourier series. That is achieved by scaling the days in the year into a range of 0 to 2π, so that each data point xi relates to some time value ti in that range. The coefficients in the series can then be calculated using the formula:

where it is assumed that the value of a0 is . Once a series of coefficients has been calculated it is then possible to calculate an estimate of a value from the population from which the xi values were drawn. The approximation yi is given by the formula:

The final stage is to compare the approximations with the real data. This is done by calculating the mean square of the difference between the approximation and real values, i.e.:



III. How the Program Works

The program uses data that has been read from a database file and is stored in two arrays, t% and d%.

   OPEN FILE "WEATHER"
   
   n%% = RECCOUNT ( FILE ):' number of data points
   DIM d%(n%%):'             dates 
   DIM t%(n%%):'             temperatures
     
   SET FORM USING 2
   SET FORM FG 1,1
   Superbase.StatusText = "Loading data..."
   
   i%% = 0
   SELECT FIRST 
   WHILE NOT EOF ( FILE )
     d%(i%%) = Date.WEATHER
     t%(i%%) = TempAtNoon.WEATHER
     i%% = i%% + 1
     SELECT NEXT 
   WEND 

Then as it goes through the stages of the analysis the program informs the user of its progress. The formulae above are all based on summing values over a range. This is simplified by using the Superbase.Summation() method, which sums the value of some expression over a specified range of values for some input variable.

   a0% = Summation("t%(i%%)","i%%",0,n%% - 1) / n%%

.
.
.

   a1% = Summation("(t%(i%%)-a0%) * cos (2 * pi * ((d%(i%%)-days(s$+str$\
   (year(d%(i%%)),f$)))/366))","i%%",0,n%% - 1) / (n%% / 2)

.
.
.

   a2% = Summation("(t%(i%%)-a0%) * cos (4 * pi * ((d%(i%%)-days(s$+str$\
(year(d%(i%%)),f$)))/366))","i%%",0,
n%% - 1) / (n%% /