Created: Mon Mar 16 09:35:50 EST 1998

Chapter 14. Plots from the C version

Section 14.1. The Plot Formats

LOCFIT plots are produced using the plotdata and plotfit commands. By default, plots are produced in a Locfit plot window. If the fmt=post argument is given, a postscript file, lfplot.ps is generated:

locfit> locfit NOx~E data=ethanol
locfit> # plot the fit on the screen. This may be redundant, see below.
locfit> plotfit
locfit> # generate a postscript file
locfit> plotfit fmt=post

Two more advanced plot commands are setplot and track. setplot is used to automatically generate a plot when a model is fitted. For example,

locfit> setplot 0 plotfit
will automatically plot the fit using the plotfit command every time a fit is generated. In fact, this command is included in the default LFInit.cmd file.

track is used to accumulate a set of points - for example, a goodness of fit statistic - over successive calls of the locfit command.

Mostly for historical reasons (or if my windows don't work!) plots can be generated in formats of a number of other packages:

locfit> plotfit fmt=gnu              Gnuplot
locfit> plotfit fmt=maple            Maple
locfit> plotfit fmt=math             Mathematica
Generally, locfit sends graphical commands to a lfplot file; this can then be read by the other package (Under unix, Gnuplot and Mathematica can be accessed through pipes, rather than files). These formats support the basic plot types (lines, points, contours, wireframes), but generally won't recognize locfit options such as colors.

Section 14.2. The plotdata command

The plotdata command produces scatter plots of the data; for example

locfit> readdata ethanol
locfit> plotdata E NOx
locfit> plotdata x=E y=C z=NOx
The first plotdata produces an x-y scatter plot of the E and NOx variables. The second plotdata (supported only in Locfit plot windows) is a three dimensional scatterplot.

An optional type= argument controls the style of the plot:

locfit> plotdata E NOx type=p          points; the default.
locfit> plotdata E NOx type=l          lines.
locfit> plotdata E NOx type=b          points and lines.
locfit> plotdata E z=NOx type=q        points, color-coded according to
                                       level of the z variable.

The plotdata command also accepts a second set of points, specified by the x2, y2 and z2 arguments. For example:

locfit> locfit NOx~E data=ethanol
locfit> fit=fitted
locfit> plotdata E NOx x2=E y2=fit
plots the E,NOx data as points, and draws segments connecting the E,fit points to the E,NOx points. This corresponds to type=ps (points and segments). Specifying e.g. type=pl would use points for the first set of points; lines for the second. Don't try to use type=s!

Note that under X windows, a plot will be damaged when you move or resize graphics windows. Pressing return should result in a redraw. If it doesn't, force a redraw with the replot command:

locfit> replot win=0

replot can also change some graphical parameters: Colours, types, viewpoint for 3-d plots etc.

Section 14.3. The plotfit command

The plotfit command evaluates the fit over a grid, and plots it. For example:

locfit> locfit NOx~E data=ethanol alpha=0.5
locfit> plotfit
locfit> plotfit se.fit=T data=T
The first plotfit just shows the fit; the second also shows confidence intervals and the data.

The type= argument is again used to control the plot type. The default is lines for the fit and confidence bands; points for the data. To get the confidence intervals displayed as error bars (rather than bands):

locfit> plotfit se.fit=T data=T type=lnsp
That's lines for the fit, none for the lower confidence limits and segments for the upper confidence limits, joined to the lower limits, and points for the data. Figure 14.1 shows the result.

Figure 14.1. Plotting a fit, with data and error bars.

Important: Fits are plotted on the x-z axis, rather than the x-y axis. Thus, if you try to add data to the plot separately,

locfit> plotfit
locfit> plotdata E NOx add=T color=blue
the result won't be what you want. Instead, use
locfit> plotfit
locfit> plotdata E z=NOx add=T color=blue

For fits with two predictor variables, the default plot type is a contour plot. Plot types supported for two dimensional predictors are

locfit> plotfit type=c         Contour Plot
locfit> plotfit type=w         Wire Frame
locfit> plotfit type=i         Colored level plot
For example,
locfit> locfit ~x0+x1 alpha=0.35 data=trimod
locfit> plotfit type=i view=45,45
The view argument specifies a view point for three dimensional plots.

Figure 14.2. C version plot of a two dimensional density

Confidence bands can be added to the two predictor plots, but the result is likely to be a mess. Try type=wns on a low resolution plot;

locfit> plotfit se.fit=T type=wns m=20
Generally, when confidence intervals are required it's better to produce one dimensional cross sections.

Fit surfaces with three or more predictors can't be directly plotted, but one or two dimensional cross sections can be. For example,

locfit> design n=100 x1=runif() x2=runif() x3=runif()
locfit> locfit ~x1+x2+x3
locfit> plotfit x2=0
produces a contour plot of the fit in x1 and x3, with x2 fixed at 0.

Section 14.4. Other plot options

A number of other options for controlling labels, colors e.t.c are available; these can be given as arguments to plotfit, plotdata or replot commands.

win=3 Locfit supports up to five graphics windows, numbered 0, 1, 2, 3 and 4. The win= argument controls which window is used.

add=T causes the plot to be added to an existing plot.

view=45,45 specifies a viewpoint for three dimensional plot. The first component is the longitude, and the second the latitude. When the latitude is 0, the z axis points directly from the screen, so an x-y plot results.

split=3,4,5 For contour plots, the split argument is used to specify contour levels. For image plots type=i and coloured point plots, type=q specifies the levels of the z variable at which colours change.

xlim, ylim and zlim specify ranges for the axis. Note, when using plotfit these do not affect the domain over which the plot is computed. Thus

locfit> locfit NOx~E data=ethanol
locfit> plotfit E=0.75,1
would be more desirable than
locfit> plotfit xlim=0.75,1

xlab, ylab, zlab and main give labels for the x, y and z axis, and a main title. Note spaces cannot be used in these arguments, but underscores (_) will be converted to spaces.

color=-red,blue,green,yellow specifies colors. The (optional) color preceded by '-' (i.e. red) is the background; the next color (blue) is the main plot color; other colors in the list are used where needed; e.g. for wireframe plots.

Colors available in LOCFIT are white, black, red, green, blue, magenta, yellow and cyan. There is also a `greyscale' used in image plots; the colors used in the greyscale can be set using e.g.

> greyscale red blue
to set the `greyscale' running from red to blue.

For Xwindows users, default window size and fonts can be specified in your .Xdefaults file, using the resources

locfit*geometry:
locfit*regfont:
locfit*bigfont:
The bigfont is used for plot titles; regfont is used for all other text.

To produce the plot on the home page:

locfit> locfit NOx~E+C data=ethanol
locfit> plotfit type=w color=-black,red,blue main=LOCFIT_in_Action
locfit> fit=fitted
locfit> plotdata E C NOx z2=fit add=T color=green

I thank Curtin University for their online courses on X programming.

Section 14.5. Other Plot Formats

As noted earlier, locfit can produce plot files for a number of other packages. This section gives display instructions.

Gnuplot

In unix, gnuplot's are displayed automatically through pipes. In manual mode (selected by fmt=gnu,m), the commands are written to the lfplot file, and the data to the lfplot.dat file. The graph is diplayed by

% gnuplot
gnuplot> load "lfplot"

Gnuplot is free software, available on the internet from

http://www.cs.dartmouth.edu/gnuplot_info.html.

Maple/Xmaple

A Maple (or preferably xmaple) session to display an lfplot file is

% xmaple
> read lfplot;
> quit;
Maple is particularly useful for perspective plots; the user can interactively rotate the plot; change the color scheme etc.

Mathematica

Mathematica plots are by default displayed automatically when fmt=math.

In manual mode (selected by fmt=math,m), the lfplot file is displayed by

% locfit
locfit> readdata ethanol
locfit> locfit NOx~E alpha=0.5
locfit> plotfit fmt=math,m
locfit> exit
% math
In[1]:= Read["lfplot"]
In[2]:= Close["lfplot"]
In[3]:= Quit
The Close["lfplot"] is necessary to display the lfplot file more than once in the same Mathematica session. I've found Mathematica very slow at displaying perspective and contour plots with the default 50 by 50 grid of points. For experimenting, the size of the grid can be reduced using (e.g.)
locfit> plotfit m=20 fmt=math
for a 20 by 20 grid.


Copyright © 1996,1997 Lucent Technologies, Bell Laboratories
Clive Loader, clive@bell-labs.com

[LOCFIT home page]