# A Simple DATAPLOT Example

Data and Problem Description Suppose the analyst has the following five observations on the variables X and Y:
```      X    Y
1    1
2    3
3    15
4    18
5    30
```
Enter a DATAPLOT program to carry out the following four operations:
1. Compute the mean of the Y data;
2. Plot Y versus X with titles and labels;
3. Carry out a least squares fit of Y on X with a linear model;
4. Generate a plot with the fitted values from the linear fit on top of the raw data.
Invoke Dataplot and Enter the Following Commands To do so, one first invokes DATAPLOT (by whatever is the appropriate command on your local computer). Upon invoking DATAPLOT, a DATAPLOT banner and a few lines of messages will appear on the screen.

One is now ready to enter the DATAPLOT program. A proqram to carry out the above 4 operations is as follows--

ECHO ON
DEVICE 1 X11
DEVICE 2 POSTSCRIPT
. STEP 0--READ IN THE DATA
.
1 1
2 3
3 15
4 18
5 30
END OF DATA
.
. STEP 1--COMPUTE THE MEAN
.
LET M = MEAN Y
.
. STEP 2 -PLOT THE DATA
.
TITLE CALIBRATION ANALYSIS
Y1LABEL RESPONSE
XLABEL FORCE
CHARACTERS X BLANK
PLOT Y X
.
. STEP 3--FIT THE DATA
.
FIT Y X
.
. STEP 4--GENERATE A SUPERIMPOSED PLOT AFTER THE
.
CHARACTERS X BLANK
LINES BLANK SOLID
PLOT Y PRED VERSUS X
EXIT
Description of Commands The DEVICE commands set the screen device to an X11 terminal and also save the plots to a Postscript file (which is saved in the file dppl1f.dat). A user running the Windows command line version would typically replace DEVICE 1 X11 with DEVICE 1 QWIN.

The initial ECHO command echos entered commands with a box of asterisks around it. This is normally not done when typing commands in interactively, but it can be helpful when running commands stored in a file. All lines beginninq with a period (".") are non-executing comment lines, included here for clarity, and will be ignored. Ignore them or enter them at your discretion. Comment lines are more common in DATAPLOT macros (programs saved in files to be run later) than in a DATAPLOT programs that are run interactively.

The READ statement reads data into variables X and Y. The read is format-free and so spacing between data values on a line is unimportant (but at least one space between data values must exist--3 15 cou1d not be written as 315). Since there are only five data pairs, they are entered directly from the terminal (as opposed to reading the data from a file). The read terminates when an END OF DATA line is entered.

LET M = MEAN Y computes the mean of the data in the variable Y, prints out the value, and stores this value in the internal DATAPLOT parameter M. DATAPLOT has over 50 summary statistics (MEAN, MEDIAN, STANDARD DEVIATION, CORRELATION, etc.) which can be similarly invoked via the LET command.

TITLE CALIBRATION ANALYSIS defines the title to appear above subsequent plots; Y1LABEL RESPONSE defines the left vertical axis label to appear on subsequent plots; XLABEL FORCE defines the horizontal axis label to appear on subsequent plots. PLOT Y X actually generates the plot with Y plotted vertically and X horizontally. The plot will have a solid 1ine (the default) connecting the data points. The pre-defined titles and labels will be automatical1y written out an the plot. The plot limits will be automatic and neat.

FIT Y X carries out a least squares linear fit of Y on X. The coefficients and other results from the fit are printed out. Predicted (= fitted) values from the fit are automatically placed in a variable PRED, and residuals from the fit are automatically placed in the variable RES. The above model (linear) is simple. In addition to single variable linear fits, DATAPLOT can perform least squares fits for polynomial and multi-linear models and for general non-linear models.

CHARACTERS X BLANK specifies that the first trace on subsequent plots should have X's as the plot character and the second trace should have blank (= no) plot character. LINES BLANK SOLID specifies that the first trace on subsequent plots should have a blank (= no) connecting line, and the second trace should have a solid connecting line. PLOT Y PRED VERSUS X generates the superimposed plot of the raw data Y and predicted values PRED as a function of X. Due to the prior CHARACTERS and LINES commands, the first trace (Y versus X) has X's as characters and no connecting line; the second trace (PRED VERSUS X) has no plot characters but a solid connectinq line.

EXIT terminates the DATAPLOT run.

 Dataplot Output from the above Program The output from the above Dataplot program is as follows: ``` THE ECHO SWITCH HAS JUST BEEN SET TO ON ******************** ** DEVICE 1 X11 ** ******************** DEVICE -- 1 I/O UNIT -- 6 MANUFACTURER --X11 MODEL -- POWER --ON CONTINUITY --ON COLOR --ON HORIZONTAL PIXELS-- 550 VERTICAL PIXELS-- 425 *************************** ** DEVICE 2 POSTSCRIPT ** *************************** DEVICE -- 2 I/O UNIT -- 43 MANUFACTURER --POST MODEL -- POWER --ON CONTINUITY --ON COLOR --OFF HORIZONTAL PIXELS-- 3130 VERTICAL PIXELS-- 2380 FILE NAME (LOCAL)--dppl1f.dat ********************************** ** . STEP 0--READ IN THE DATA ** ********************************** ********* ** . ** ********* **************** ** READ X Y ** **************** INPUT DATA FILE SUMMARY INFORMATION-- INPUT UNIT DEVICE NUMBER = 5 INPUT FILE COLUMN LIMITS = 1 80 INPUT FILE ROW LIMITS = 1 INFINITY NUMBER OF HEADER LINES SKIPPED = 0 NUMBER OF DATA LINES READ = 5 NUMBER OF VARIABLES READ = 2 THE SCANNED REGION OF THE FIRST DATA LINE READ = 1 1 THE SCANNED REGION OF THE LAST DATA LINE READ = 5 30 VARIABLE COLUMN OBS/VARIABLE X 1 5 Y 2 5 ********* ** . ** ********* *********************************** ** . STEP 1--COMPUTE THE MEAN ** *********************************** ********* ** . ** ********* ********************** ** LET M = MEAN Y ** ********************** THE MEAN OF THE 5 OBSERVATIONS = 0.1140000E+02 THE COMPUTED VALUE OF THE CONSTANT M = 0.11400000E+02 ********* ** . ** ********* ******************************* ** . STEP 2 -PLOT THE DATA ** ******************************* ********* ** . ** ********* ********************************** ** TITLE CALIBRATION ANALYSIS ** ********************************** THE TITLE HAS JUST BEEN SET TO CALIBRATION ANALYSIS ************************ ** Y1LABEL RESPONSE ** ************************ THE LEFT VERTICAL AXIS LABEL HAS JUST BEEN SET TO RESPONSE ******************** ** XLABEL FORCE ** ******************** THE FIRST HORIZONTAL AXIS LABEL HAS JUST BEEN SET TO FORCE ************************** ** CHARACTERS X BLANK ** ************************** CHARACTER 1 HAS JUST BEEN SET TO X CHARACTER 2 HAS JUST BEEN SET TO BLAN **************** ** PLOT Y X ** **************** ``` ``` ********* ** . ** ********* ******************************* ** . STEP 3 FIT THE DATA ** ******************************* ********* ** . ** ********* *************** ** FIT Y X ** *************** LEAST SQUARES MULTILINEAR FIT SAMPLE SIZE N = 5 NUMBER OF VARIABLES = 1 NO REPLICATION CASE PARAMETER ESTIMATES (APPROX. ST. DEV.) T VALUE 1 A0 -10.5000 ( 5.289 ) -2.0 2 A1 X 7.30000 ( 1.595 ) 4.6 RESIDUAL STANDARD DEVIATION = 5.0431470871 RESIDUAL DEGREES OF FREEDOM = 3 COEF AND SD(COEF) WRITTEN OUT TO FILE DPST1F.DAT SD(PRED),95LOWER,95UPPER,99LOWER,99UPPER WRITTEN OUT TO FILE DPST2F.DAT REGRESSION DIAGNOSTICS WRITTEN OUT TO FILE DPST3F.DAT PARAMETER VARIANCE-COVARIANCE MATRIX AND INVERSE OF X-TRANSPOSE X MATRIX WRITTEN OUT TO FILE DPST4F.DAT ********* ** . ** ********* ********************************************************* ** . STEP 4 GENERATE A SUPERIMPOSED PLOT AFTER THE ** ********************************************************* ********* ** . ** ********* ************************** ** CHARACTERS X BLANK ** ************************** CHARACTER 1 HAS JUST BEEN SET TO X CHARACTER 2 HAS JUST BEEN SET TO BLAN ************************* ** LINES BLANK SOLID ** ************************* LINE 1 HAS JUST BEEN SET TO BLAN LINE 2 HAS JUST BEEN SET TO SOLI **************************** ** PLOT Y PRED VERSUS X ** **************************** ``` ``` ************ ** EXIT ** ************ ----------------------------------------------- NOTE--DEVICE 2 (A FILE CONTAINING PLOT IMAGES) HAS JUST BEEN CLOSED. FILE NUMBER = 43 FILE NAME = dppl1f.dat NOTE--TO EXAMINE THE FILE, USE ANY EDITOR, AND SIMPLY PRINT THE FILE CONTENTS. ----------------------------------------------- ----------------------------------------------- NOTE--DEVICE 3 (A FILE CONTAINING PLOT IMAGES) HAS JUST BEEN CLOSED. FILE NUMBER = 44 FILE NAME = dppl2f.dat NOTE--TO EXAMINE THE FILE, USE ANY EDITOR, AND SIMPLY PRINT THE FILE CONTENTS. ----------------------------------------------- THIS IS AN EXIT FROM DATAPLOT. ``` NIST is an agency of the U.S. Commerce Department. Date created: 06/05/2001 Last updated: 09/28/2016 Please email comments on this WWW page to alan.heckert@nist.gov.