.ig >>
<STYLE TYPE="text/css">
<!--
        A:link{text-decoration:none}
        A:visited{text-decoration:none}
        A:active{text-decoration:none}
        OL,UL,P,BODY,TD,TR,TH,FORM { font-family: arial,helvetica,sans-serif;; font-size:small; color: #333333; }

        H1 { font-size: x-large; font-family: arial,helvetica,sans-serif; }
        H2 { font-size: large; font-family: arial,helvetica,sans-serif; }
        H3 { font-size: medium; font-family: arial,helvetica,sans-serif; }
        H4 { font-size: small; font-family: arial,helvetica,sans-serif; }
-->
</STYLE>
<title>ploticus: proc curvefit</title>
<body bgcolor=D0D0EE vlink=0000FF>
<br>
<br>
<center>
<table cellpadding=2 bgcolor=FFFFFF width=550><tr>
<td>
  <table cellpadding=2 width=550><tr>
  <td><br><h2>proc curvefit</h2></td>
  <td align=right>
  <small>
  <a href="../doc/welcome.html"><img src="../doc/ploticus.gif" border=0></a><br>
  Version 2.33 Jun'06
     </small><br><a href="../doc/scripthome.html">Scripts</a>
  <td></tr></table>
</td></tr>
<td>
<br>
<br>
.>>

.TH proc_curvefit PL "02-JUN-2006   PL ploticus.sourceforge.net"

.ig >>
<center>
<img src="../gallery/curvefit3.gif">
</center>
.>>

.LP
\fBproc curvefit\fR uses the
.ig >>
<a href="dataformat.html#currentds">
.>>
\0current data set
.ig >>
</a>
.>>
to compute a curve which it then renders in the 
.ig >>
<a href="areadef.html">
.>>
\0current plotting area.
.ig >>
</a>
.>>
Available curve types are: moving average, average, linear regression, bspline, and interpolated curves.
Typical uses are to clarify overall trends in the data, or for smoothing.
(If you just want to draw a line connecting your data points, without any smoothing, use
.ig >>
<a href="lineplot.html">
.>>
\0proc lineplot.)
.ig >>
</a>
.>>
The data do not have to be in X order.. they will be sorted on X as part of the process
(except with the interpolated curve type).  See also the 
.ig >>
<a href="../gallery/gall.curvefit.html">
.>>
\0gallery curvefit examples.
.ig >>
</a>
.>>
.LP
Limitations: 
The maximum number of input points for a bspline curve is 100.  
The default maxiumum number of input points for all other curve types
is 1000.. to raise this limit use the proc curvefit attribute \fCmaxinpoints\fR.
Generated curve points are placed into the plotting vector; its size can
be controlled using command line argument \fC-maxvect\fR.


.ig >>
<br><br><br>
.>>

.SH Attributes
The \fCyfield\fR attribute MUST be specified.

.LP
\fByfield\fR
.ig >>
&nbsp; &nbsp;
.>>
.ig >>
<a href="attributetypes.html#dfield">
.>>
\0dfield
.ig >>
</a>
.>>
.IP \0
Data field to use for Y values.  Example: \fCyfield: 1\fR

.ig >>
<br><br>
.>>

.LP
\fBxfield\fR
.ig >>
&nbsp; &nbsp;
.>>
.ig >>
<a href="attributetypes.html#dfield">
.>>
\0dfield
.ig >>
</a>
.>>
.IP \0
Data field to use for X values.
If not given, sequential unit locations in X will be used.
Example: \fCxfield: 4\fR

.ig >>
<br><br>
.>>

.LP
\fBcurvetype\fR 
.ig >>
&nbsp; &nbsp;
.>>
\fCmovingavg\fR | \fCregression\fR | \fCbspline\fR | \fCavg\fR | \fCinterpolated\fR
.IP \0
The type of curve fitting computation to perform.  
.IP \0
\fBmovingavg\fR - for each point, it takes the average of the current point and \fIn\fR-1 
points to the left (or as many points as are available).
\fIn\fR is controlled by the \fCorder\fR attribute.
Often used in finance.
.IP \0
\fBregression\fR - Computes the linear regression for the set of points.  The result will be a
straight line expressing the relationship between X and Y.  Often used with scatterplots.
The variables REGRESSION_LINE and CORRELATION will be set (see VARIABLES above).
.IP \0
\fBbspline\fR - draws a curve using the bspline algorithm.  The \fCorder\fR and \fCresolution\fR
attributes control the appearance of the result.  May be used to fit a curve to a histogram.
.IP \0
\fBavg\fR - similar to movingavg except that it also includes \fIn\fR-1 points to the right
of the current point (or as many points as are available) in the average.  
Thus, for a point that is far from either edge, 2\fIn\fR-1 points will be averaged.
.IP \0
\fBinterpolated\fR - a spline interpolation between the given data points, ie. the curve will pass through
all input data points (this type is new in version 2.20, code contibuted by Oliver Koch)
.IP \0
Example: \fCcurvetype: movingavg\fR

.ig >>
<br><br>
.>>

.LP
\fBmaxinpoints\fR
.ig >>
&nbsp; &nbsp;
.>>
n
.IP \0
Maximum number of input points for curve types other than bspline.  Default is 1000. (ver 2.30+)

.ig >>
<br><br><br>
.>>

.SH Details of curve appearance
.LP
\fBorder\fR 
.ig >>
&nbsp; &nbsp;
.>>
\fIn\fR
.IP \0
For bspline curves, this is a value between 2 and 20; a lower value
yields a more jagged curve, while a higher value gives a smoother curve.
The number of data points must be at least this value for a bspline curve
to be possible.
.IP \0
For movingavg curves, this defines the number of points
to include in each average computation.  For avg curves, 2\fIn\fR - 1
points will be considered, where \fIn\fR = the \fCorder\fR value.
.IP \0
This attribute has no effect with regression or interpolated curve.
.IP \0
Default order for either type of curve is 4.
.IP \0
Example: \fCorder: 8\fR

.ig >>
<br><br>
.>>
.LP
\fBresolution\fR 
.ig >>
&nbsp; &nbsp;
.>>
\fIn\fR
.IP \0
Only relevant for bspline curves.  
For every input point, \fIn\fR result points will be generated.
Default is 5.0.

.ig >>
<br><br>
.>>
.LP
\fBlinedetails\fR 
.ig >>
&nbsp; &nbsp;
.>>
.ig >>
<a href="linedetails.html">
.>>
\0linedetails
.ig >>
</a>
.>>
.IP \0
Appearance details for the curve.
Note that dash patterns may not be effective with generated curves (other than regression curves)
because of point density.
.br
Example: \fClinedetails: color=red width=2.0 \fR

.ig >>
<br><br>
.>>
.LP
\fBxsort\fR
.ig >>
&nbsp; &nbsp;
.>>
\fCyes | no\fR
.IP \0
Whether or not to sort the input data on \fCxfield\fR
before generating curves of the \fCinterpolated\fR type.
Default is \fCno\fR.


.ig >>
<br><br><br>
.>>

.SH Range control & selecting data rows

.LP
\fBselect\fR  
.ig >>
&nbsp; &nbsp;
.>>
.ig >>
<a href="select.html">
.>>
\0select expression
.ig >>
</a>
.>>
.IP \0
Allows selected data points to be included in curve computation.
.br
Example: \fCselect: @@3 > 0\fR

.ig >>
<br><br>
.>>

.LP
\fBcalcrange\fR 
.ig >>
&nbsp; &nbsp;
.>>
\fImin\fR 
.ig >>
&nbsp; &nbsp;
.>>
[\fImax\fR]
.IP \0
Data within this X range will be included in curve calculation.
If only one value is given, it will be taken as the range
minima and the maxima will be the plottable maxima.
If not specified all data rows will be included.

.ig >>
<br><br>
.>>
.LP
\fBlinerange\fR 
.ig >>
&nbsp; &nbsp;
.>>
\fImin\fR 
.ig >>
&nbsp; &nbsp;
.>>
[\fImax\fR]
.IP \0
Controls the X range (in scaled units) within which the curve will be rendered.
Data points falling outside this range will not be rendered.
If accumulation is being done, points outside the range will contribute
to the accumulated total.
If only one value is given, it will be taken as the range
minima and the maxima will be the plottable maxima.
If not specified all data rows will be plotted.
.IP \0
For regression curves, this attribute may be used to limit
the X range of the regression line, or to create a regression line that extends 
beyond the X range of the data.  
In this case, \fImin\fR and \fImax\fR should both be given.
.IP \0
Example: \fClinerange: 1\fR

.ig >>
<br><br>
.>>
.LP
\fBclip\fR
.ig >>
&nbsp; &nbsp;
.>>
\fCyes | no\fR
.IP \0
Default is \fCno\fR.  If set to \fCyes\fR, generated curve will be clipped to the
plotting area in Y.  (Regression curves are always clipped.)  (2.30+)

.ig >>
<br><br><br>
.>>

.SH Legend

.LP
\fBlegendlabel\fR  
.ig >>
&nbsp; &nbsp;
.>>
.ig >>
<a href="attributetypes.html#text">
.>>
\0text
.ig >>
</a>
.>>
.IP \0
A label to be associated with the curve in the legend.
\fBproc legend\fR must be executed later in order to
render the legend.
The \fC\\n\fR construct can be used to force a line break 
or the label can be wordwrapped using proc legend wraplen attribute (2.32+).
If
.ig >>
<a href="getdata.html">
.>>
\0proc getdata field names
.ig >>
</a>
.>>
are being used,
the special symbol \fC#usefname\fR causes the field name of \fCyfield\fR
to be automatically used as the legend label (2.04+).
.br
Example: \fClegendlabel: Northeast region\fR
.br
Example: \fClegendlabel: #usefname\fR


 
.ig >>
<br><br><br>
.>>

.SH Accessing the coordinates of the generated curve 
.LP
\fBshowresults\fR  
.ig >>
&nbsp; &nbsp;
.>>
\fCyes\fR | \fCno\fR
.IP \0
If \fCyes\fR, a listing of the points in the computed curve will
be written to the diagnostic stream (-diag).

.ig >>
<br><br>
.>>
.LP
\fBstatsonly\fR  
.ig >>
&nbsp; &nbsp;
.>>
\fCyes\fR | \fCno\fR
.IP \0
If \fCyes\fR, don't draw the result curve.  This is for situations where the user only wants
the computed curve values (\fCshowresults\fR) or the 
REGRESSION_LINE and CORRELATION variables to be set.


.ig >>
<br><br><br>
.>>

.SH Variables that are set by proc curvefit
.LP
\fBREGRESSION_LINE\fR
.IP \0
If curvetype is \fCregression\fR, this variable will be set to display
the formula for the regression line.
.LP
\fBCORRELATION\fR
.IP \0
If curvetype is \fCregression\fR, this variable will be set to display
the Pearson correlation coefficient (r), which ranges from -1.0 to 1.0, where
1.0 is a strong correlation (positive slope), -1.0 is a strong correlation
(negative slope), and 0 is no correlation.
.LP
\fBXFINAL\fR and \fBYFINAL\fR
.IP \0
are set to the final location (in scaled space) of the end of the drawn curve.

.ig >>
<br>
<br>
</td></tr>
<td align=right>
<a href="../doc/welcome.html">
<img src="../doc/ploticus.gif" border=0></a><br><small>data display engine &nbsp; <br>
<a href="../doc/Copyright.html">Copyright Steve Grubb</a>
<br>
<br>
<center>
<img src="../gallery/all.gif"> 
</center>
</td></tr>
</table>
<br>
<center>
Ploticus is hosted at http://ploticus.sourceforge.net <br>
<img src="http://sourceforge.net/sflogo.php?group_id=38453" width="88" height="31" border="0" alt="SourceForge Logo">
</center>
.>>
