File: loess.demo.Rd

package info (click to toggle)
r-cran-teachingdemos 2.13-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,168 kB
  • sloc: makefile: 2
file content (89 lines) | stat: -rw-r--r-- 3,219 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
\name{loess.demo}
\alias{loess.demo}

\title{ Demonstrate the internals of loess curve fits }
\description{
  Creates a scatterplot with a loess fit, then interactively shows the
  window and case weights used to create the curve at the selected value
  of \code{x}.
}
\usage{
loess.demo(x, y, span = 2/3, degree = 1, nearest = FALSE,
  xlim = numeric(0), ylim = numeric(0), verbose = FALSE)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
  \item{x}{ The \code{x} coordinates to be plotted. }
  \item{y}{ The \code{y} coordinates to be plotted. }
  \item{span}{ The relative width of the window, passed on to \code{loess}. }
  \item{degree}{ Degree of polynomial to use (0, 1, or 2), passed on to \code{loess}. }
  \item{nearest}{ Logical, should predictions be made at the point where
  you clicked (FALSE), or at the nearest x value of the data to where
  you clicked (TRUE).}
  \item{xlim}{ Limits of the Horizonal axis. }
  \item{ylim}{ Limits of the Vertical axis. }
  \item{verbose}{ If true then print the x coordinate being predicted. }
}
\details{
  This function demonstrates the underlying calculations of loess
  curves.

  Given \code{x} and \code{y} vectors it will create a scatterplot and
  add 2 loess fit lines (one using straight loess smooth with linear
  interpolation and one that does a spline interpolation of the loess
  fit).

  The function then waits for the user to click on the plot.  The
  function then shows the window of points (centered at the \code{x}
  value clicked on) used in the weighting for predicting that point and
  shows a circle around each point in the window where the area of the
  circle is proportional to the weight of that point in the linear fit.
  The function also shows the linear (or quadratic) fit used to predict
  at the selected point.

  The basic steps of the loess algorithm (as demonstrated by the
  function)  is that to predict the y-value for a given x-value the
  computer:

  1. Find all the points within a window around the x-value (the width
     of the window is based on the parameter \code{span}).
  2. Weight the points in the window with points nearest the x-value
     having the highest weight.
  3. Fit a weighted linear (quadratic) line to the points in the
     window.
  4. Use the y-value of the fitted line (curve) at the x-value to give
     loess prediction at that x-value.

     Clicking on another point in the graph will replot with the new
     situation.

     Right click and select 'stop' to end the demonstration.
}
\value{
  This function does not return anything, it is run purely for its side
  effects.
}

\author{ Greg Snow \email{538280@gmail.com}}




\seealso{ \code{\link{loess}}, \code{\link{locator}} }
\examples{

if(interactive()){
data(ethanol, package='lattice')
attach(ethanol)
loess.demo(E, NOx)
# now click a few places, right click to end
loess.demo(E, NOx, span=1.5)
loess.demo(E, NOx, span=0.25)
loess.demo(E, NOx, degree=0)
loess.demo(E, NOx, degree=2)
detach()
}
}
\keyword{ hplot }% at least one, from doc/KEYWORDS
\keyword{ dynamic }% __ONLY ONE__ keyword per line
\keyword{ iplot }