Locate Previous Next Contents

Using RAIN and ASLGREG

In this final section we illustrate the use of RAIN in conjunction with ASLGREG, the latter allowing us to fit regression models. ASLGREG comes with a simple set of data on the cost of houses and all its facilities exist in a namespace called asl.

      asl.Housedata
      price
60.5 47.5 46 110 148 65 79.95 54 120 85 65 55 70 82.5 78.5 49.95 46.95
      46.95 77 102 37.5 68 65 145 98 75 96.5 53.95 75
      area
1326 782 312 1460 1056 752 1120 904 1654 735 565 346 698 775 696 741 432
      517 747 914 603 1292 551 1383 1580 754 850 518 634
      beds
4 3 1 3 4 3 4 3 4 3 2 1 3 3 3 3 2 2 3 4 3 5 3 4 5 3 3 3 3

The prices are in thousands of poinds, area is in square feet and beds is the number of bedrooms.

Our first model simply regresses price on area – obviously we would expect an approximate straight line relationship with the slope indicating an approximate cost per square foot and the intercept a base cost.

Declare the y-variable:

       asl.Yvar 'price'
Regression Volume 1 Version 1.2
A.M.Sykes, May 1999
Copyright(C) British APL Association 1991
Y variable is price                  
Units set to 29                     

Now fit the linear regression model, specifying an intercept term (gm – for grand mean) and the price variable:

      asl.Fit 'gm+area'
ÚÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÌ
ÛSource              ss          df     ms    Û
ÃÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÝ
ÛDue to model        9.865E3      1     9865  Û
ÛResidual            1.258E4     27      465.8Û
ÃÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÝ
ÛTotal Corrected     2.244E4     28      801.5Û
Û                                             Û
ÛPercentage Variation Accounted for =  43.96  Û
ÛF-statistic =                         21.18  Û
Ûp-value=                               0.00  Û
ÀÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÎÙ

This tells us that using a linear regression model accounts for nearly 44% of the variation in the y-data.

To display the estimates, their standard errors:

      asl.Display 'es'
Var       Est          Std Err 
ÎÎÎ       ÎÎÎ          ÎÎÎ ÎÎÎ 
GM        32.07        10.35   
area       0.05157      0.01121

The second figure in the second column tells us that the cost per square foot is approximately 0.05157 thousand pounds, i.e. £51.57.

So to some graphics – it would be nice to display the data and the fitted line. We need to declare the style of the plot to be an xyplot, we need to plot the data and then the line of best fit.

      ch.Set 'style' 'xyplot'
      ch.Set('xcap' 'Area -sq ft')('ycap' 'Cost -£1000')
      ch.Set 'style' 'nolines,markers'
      ch.Set 'Mark' 14
      ch.Plot area price

The 14th marker in Rain is a nice, distinctive sphere with a 3-dimensional effect, intended for use in 3-dimensional plots.

Now we need to add the regression line. From the chart so far, or by inspection, the range of x-values is from 300 to 1700. The parameter estimates are contained in the system variable asl.parest, so we can work out two points to plot to get the regression line:

      x„300 1700
      y„asl.parest[1]+asl.parest[2]×x

Change the plot style to lines and not markers and plot these values:

      ch.Set'style' 'lines,nomarkers'
      ch.Plot x y

The chart may be completed by adding a heading and a key – the full program is :

      ch.Set 'head' 'Regression of Price on Area'
      ch.Set 'key' 'data,fitted line'
      ch.Set 'style' 'xyplot'
      ch.Set('xcap' 'Area -sq ft')('ycap' 'Cost -£1000')
      ch.Set 'style' 'nolines,markers'
      ch.Set 'Mark' 14
      ch.Plot area price
      x„300 1700
      y„asl.parest[1]+asl.parest[2]×x
      ch.Set'style' 'lines,nomarkers'
      ch.Plot x y
      View Pg„ch.Close



Continue to: Three-Dimensional Charts
© Copyright Alan Sykes and Adrian Smith 1999