Regression Analysis Using Maple

 

Overview:

 

we will use Maple here for several purposes:

 

1)  to graph data and to graph curves

2)  to perform computations generating "least squares fits"

3)  to gain an understanding of what a least squares fit is

 

 

Part One   Plotting Data with Maple

 

By "data"  we mean isolated points as opposed to continuous curves.  For example, we wish to plot the following data:

 

{ (0,1), (1,2), (2,5), (3,10), (5,26)  }

 

We will be working with this data for awhile so first we will break it up into two parts, the x values and the y values:

 

>x_val:=[0 , 1, 2, 3, 5 ];                note the use of [        ]  s

>y_val:=[1 , 2, 5, 10, 26];

 

to plot them, we will build a two dimensional array C as follows:

 

>> n:=5;

>> for i from 1 to n do C[i]:=[x_val[i],y_val[i]];od;

 

We next generate a plot but do not yet display it on the screen. We store this plot in a structure which we call  our_data_plot   as follows:

 

> our_data_plot:=plot([seq(C[i],i=1..n)],style=point):

 

Note the colon, :, at the end, as opposed to a semicolon. This suppresses output.

 

We can now easily see what this looks like on the screen by using the display function from Maple:

 

>display(our_data_plot);

 

You should see a parabolic looking set of points appear in red dots.

 

Next let’s plot a regular parabola for comparison, say, y = x2+2.  This is much easier because it’s a continuous graph, vs discrete in the earlier case.  For reasons that will be clear shortly, we will do this in two steps:

 

   >parab_graph:=plot(x^2 + 2, x=0..5,color=green,thickness=2 ):    note colon again

  > display(parab_graph);

 

You should see a nice, smooth parabola drawn in green, fairly thick.

 

Finally, lets superimpose the two graphs:

 

> display(  {  parab_graph,  our_data_plot  }  );    note the  curly braces   {      }  which are needed anytime you plot more than one thing at once .