Locate Previous Contents

Three-Dimensional Charts

Rain comes with some very impressive three-dimensional capabilities. They are just as easy to use. The function ch.Cloud can be used instead of ch.Plot to produce scatterplots or line plots in three-dimensions. The function ch.Tower similarly replaces ch.Box and an extra function ch.Resp produces surfaces. For starters, try:

      ch.Cloud ?10 3½50
      View PG„ch.Close

or

      ch.Tower ?10 3½50
      View PG„ch.Close

To enhance the chart you might like to consider creating ‘walls’ for a backcloth, with grids if required. The use of markers 14 and 15 (‘spheres’) is entirely appropriate too:

      ch.Set 'style' 'walls,grid,nolines,mark'
      ch.Set 'mark' 14
      ch.Cloud ?10 3½50
      View PG„ch.Close

To help place the x-y co-ordinates of the cloud, add ‘risers’ to the style statement.

So, to finish this sample of Rain, we return to the problem of predicting house prices given their size, but add another variable – the number of bedrooms.

      asl.Yvar 'price'
      asl.Fit 'gm+area+beds'
      asl.parest
32.76 0.05268 ¯0.524

Curiously, the sign of the coefficient of beds is negative – however, it is not actually significantly different from zero – so strictly speaking, we do not need the number of bedrooms in this model as it is. However we continue as though it were necessary.

We already know how to produce a plot of the points used in the regression model. We now wish to display the equivalent of the regression line – which is now a regression plane.

Assuming x-values and y-values given by:

      x
300 400 500 600 700 800 900 1000 1100 1200 1300 1400 1500 1600 1700 1800
      y
1 2 3 4 5

corresponding to area and beds, we require the equivalent predicted z=price-values. These are given by:

      z„asl.parest[1]+(asl.parest[2]×x)°.+asl.parest[3]×y

These x,y,z values may be used as the right argument to ch.Resp to draw the regression plane.

      ch.Set('style' 'lines,walls,grid,tiled')('nib' 0.5)('mark' 15)
      ch.Set('xcap' 'Area')('ycap' 'Beds')('zcap' 'Price')
      ch.Set'Head' 'ASL House Price Data'
      ch.Resp x y z
      ch.Set('style' 'nolines,mark')('line' 'solid')
      ch.Cloud area,beds,[1.5]price

You may like to play around using different viewpoints for the three-dimensions. This can be achieved by specifying the roll, pitch and yaw using a three-element vector for ‘viewpoint’. For example try adding the line ch.Set 'Viewpoint' 10 1 89 as the third line.

Finally, adding straws to the balls helps you to see where the points are in relation to the regression plane. This can be done by adding 'risers' to the style for ch.Cloud and adding a fourth column which specifies where the risers start from (default is 0):-

      ch.Set('style' 'lines,walls,grid,nomark')('nib' 0.5)
      ch.Set('xcap' 'Area')('ycap' 'Beds')('zcap' 'Price')
      ch.Set'Head' 'ASL House Price Data'
      ch.Set'view' 10 1 89
      ch.Resp x y z
      ch.Set('style' 'nolines,mark,risers')('line' 'solid')('mark' 15)
      ch.Cloud area,beds,price,[1.5](1,area,[1.5]beds)+.×asl.parest



© Copyright Alan Sykes and Adrian Smith 1999