;+
; NAME:
; fourplot
;
;
; PURPOSE:
; create a fourplot for Exploratory Data Analysis
; http://www.itl.nist.gov/div898/handbook/eda/section3/4plot.htm
; The 4-plot is a collection of 4 specific EDA graphical techniques
; whose purpose is to test the assumptions that underlie most
; measurement processes. A 4-plot consists of a
;
; 1. run sequence plot;
; 2. lag plot;
; 3. histogram;
; 4. normal probability plot.
;
; If the 4 underlying assumptions of a typical measurement process
; hold, then the above 4 plots will have a characteristic appearance
; (see the normal random numbers case study below); if any of the
; underlying assumptions fail to hold, then it will be revealed by
; an anomalous appearance in one or more of the plots.
;
; references
; Chambers, John, William Cleveland, Beat Kleiner, and Paul Tukey,
; (1983), Graphical Methods for Data Analysis, Wadsworth.
;
;
; CATEGORY:
; Statistics
;
;
; INPUTS:
; y: y-values to use in the 4-plot
;
; OPTIONAL INPUTS:
; x: x-values to use in the 4-plot
;
;
; KEYWORD PARAMETERS:
; COLORNAME: Name of the color to plot with, see fsc_color()
; BACKNAME: Name of the background color, see fsc_color()
; _EXTRA: Extra keywords to plot, oplot, and histoplot
;
;
; OUTPUTS:
; The NIST 4-plot
;
;
; RESTRICTIONS:
; Residuals are calculated using regress()
;
;
; EXAMPLE:
; IDL> x=findgen(101)
; IDL> x=x[sort(randomu(seed, 101))]
; IDL> y=x+5 + randomn(seed, 101)*10
; IDL> fourplot, x, y
;
;
; MODIFICATION HISTORY:
;
; Mon Sep 8 15:17:11 2008, Brian Larsen
; made x an optional input and minor plot edits
; Wed Feb 13 15:12:38 2008, Brian Larsen
; written and tested
;
;-
PRO fourplot, x, y, $
COLORNAME = colorname, $
BACKNAME = backname, $
_EXTRA = _extra
IF n_elements(y) EQ 0 THEN BEGIN
y = x
x = findgen(n_elements(y))
ENDIF
IF n_elements(colorname) NE 0 THEN $
color = fsc_color(colorname, 0) ELSE $
colorname = 'white'
IF n_elements(backname) EQ 0 THEN $
backname = 'black' ELSE $
back = fsc_color(backname, 1)
pmulti = !p.multi
!p.multi = [0, 2, 2]
;;;;;;;;;;;;;; Run sequence plot ;;;;;;;;;;;;;
plot, y, $
xtitle = 'Run sequence plot', $
psym = 1, $
color = fsc_color(colorname), $
back = fsc_color(backname), $
/ynozero, $
_EXTRA = _extra
;;;;;;;;;;;;;; Lag Plot ;;;;;;;;;;;;;;;;;;
plot, y[1:*], y, $
xtitle = 'Lag plot Y!li', $
ytitle = 'Y!li-1', $
psym = 1, $
color = fsc_color(colorname), $
back = fsc_color(backname), $
/ynozero, $
_EXTRA = _extra
;;;;;;;;;;;;; Histogram ;;;;;;;;;;;;;;;;;;
histoplot, y, $
/fill, $
AXISCOLOR = colorname, $
DATACOLOR = colorname, $
BACKCOLOR = backname, $
_EXTRA = _extra
;;;;;;;;;;;;;; Normal probability plot ;;;
ans = regress(x, y, yfit = yfit)
res = y-yfit
normal_prob_plot, res, $
/blom, $
color = fsc_color(colorname), $
back = fsc_color(backname), $
_EXTRA = _extra
!p.multi = pmulti
END