EVOLUTION-MANAGER
Edit File: stepfun.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Step Functions - Creation and Class</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for stepfun {stats}"><tr><td>stepfun {stats}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Step Functions - Creation and Class</h2> <h3>Description</h3> <p>Given the vectors <i>(x[1], …, x[n])</i> and <i>(y[0], y[1], …, y[n])</i> (one value more!), <code>stepfun(x, y, ...)</code> returns an interpolating ‘step’ function, say <code>fn</code>. I.e., <i>fn(t) = c</i><i>[i]</i> (constant) for <i>t in ( x[i], x[i+1])</i> and at the abscissa values, if (by default) <code>right = FALSE</code>, <i>fn(x[i]) = y[i]</i> and for <code>right = TRUE</code>, <i>fn(x[i]) = y[i-1]</i>, for <i>i=1, …, n</i>. </p> <p>The value of the constant <i>c[i]</i> above depends on the ‘continuity’ parameter <code>f</code>. For the default, <code>right = FALSE, f = 0</code>, <code>fn</code> is a <em>cadlag</em> function, i.e., continuous from the right, limits from the left, so that the function is piecewise constant on intervals that include their <em>left</em> endpoint. In general, <i>c[i]</i> is interpolated in between the neighbouring <i>y</i> values, <i>c[i] = (1-f)*y[i] + f*y[i+1]</i>. Therefore, for non-0 values of <code>f</code>, <code>fn</code> may no longer be a proper step function, since it can be discontinuous from both sides, unless <code>right = TRUE, f = 1</code> which is left-continuous (i.e., constant pieces contain their right endpoint). </p> <h3>Usage</h3> <pre> stepfun(x, y, f = as.numeric(right), ties = "ordered", right = FALSE) is.stepfun(x) knots(Fn, ...) as.stepfun(x, ...) ## S3 method for class 'stepfun' print(x, digits = getOption("digits") - 2, ...) ## S3 method for class 'stepfun' summary(object, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>numeric vector giving the knots or jump locations of the step function for <code>stepfun()</code>. For the other functions, <code>x</code> is as <code>object</code> below.</p> </td></tr> <tr valign="top"><td><code>y</code></td> <td> <p>numeric vector one longer than <code>x</code>, giving the heights of the function values <em>between</em> the x values.</p> </td></tr> <tr valign="top"><td><code>f</code></td> <td> <p>a number between 0 and 1, indicating how interpolation outside the given x values should happen. See <code><a href="approxfun.html">approxfun</a></code>.</p> </td></tr> <tr valign="top"><td><code>ties</code></td> <td> <p>Handling of tied <code>x</code> values. Either a function or the string <code>"ordered"</code>. See <code><a href="approxfun.html">approxfun</a></code>.</p> </td></tr> <tr valign="top"><td><code>right</code></td> <td> <p>logical, indicating if the intervals should be closed on the right (and open on the left) or vice versa.</p> </td></tr> <tr valign="top"><td><code>Fn, object</code></td> <td> <p>an <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> object inheriting from <code>"stepfun"</code>.</p> </td></tr> <tr valign="top"><td><code>digits</code></td> <td> <p>number of significant digits to use, see <code><a href="../../base/html/print.html">print</a></code>.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>potentially further arguments (required by the generic).</p> </td></tr> </table> <h3>Value</h3> <p>A function of class <code>"stepfun"</code>, say <code>fn</code>. </p> <p>There are methods available for summarizing (<code>"summary(.)"</code>), representing (<code>"print(.)"</code>) and plotting (<code>"plot(.)"</code>, see <code><a href="plot.stepfun.html">plot.stepfun</a></code>) <code>"stepfun"</code> objects. </p> <p>The <code><a href="../../base/html/environment.html">environment</a></code> of <code>fn</code> contains all the information needed; </p> <table summary="R valueblock"> <tr valign="top"><td><code>"x","y"</code></td> <td> <p>the original arguments</p> </td></tr> <tr valign="top"><td><code>"n"</code></td> <td> <p>number of knots (x values)</p> </td></tr> <tr valign="top"><td><code>"f"</code></td> <td> <p>continuity parameter</p> </td></tr> <tr valign="top"><td><code>"yleft", "yright"</code></td> <td> <p>the function values <em>outside</em> the knots</p> </td></tr> <tr valign="top"><td><code>"method"</code></td> <td> <p>(always <code>== "constant"</code>, from <code><a href="approxfun.html">approxfun</a>(.)</code>).</p> </td></tr> </table> <p>The knots are also available via <code><a href="stepfun.html">knots</a>(fn)</code>. </p> <h3>Note</h3> <p>The objects of class <code>"stepfun"</code> are not intended to be used for permanent storage and may change structure between versions of <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> (and did at <span style="font-family: Courier New, Courier; color: #666666;"><b>R</b></span> 3.0.0). They can usually be re-created by </p> <pre> eval(attr(old_obj, "call"), environment(old_obj))</pre> <p>since the data used is stored as part of the object's environment. </p> <h3>Author(s)</h3> <p>Martin Maechler, <a href="mailto:maechler@stat.math.ethz.ch">maechler@stat.math.ethz.ch</a> with some basic code from Thomas Lumley. </p> <h3>See Also</h3> <p><code><a href="ecdf.html">ecdf</a></code> for empirical distribution functions as special step functions and <code><a href="plot.stepfun.html">plot.stepfun</a></code> for <em>plotting</em> step functions. </p> <p><code><a href="approxfun.html">approxfun</a></code> and <code><a href="splinefun.html">splinefun</a></code>. </p> <h3>Examples</h3> <pre> y0 <- c(1., 2., 4., 3.) sfun0 <- stepfun(1:3, y0, f = 0) sfun.2 <- stepfun(1:3, y0, f = 0.2) sfun1 <- stepfun(1:3, y0, f = 1) sfun1c <- stepfun(1:3, y0, right = TRUE) # hence f=1 sfun0 summary(sfun0) summary(sfun.2) ## look at the internal structure: unclass(sfun0) ls(envir = environment(sfun0)) x0 <- seq(0.5, 3.5, by = 0.25) rbind(x = x0, f.f0 = sfun0(x0), f.f02 = sfun.2(x0), f.f1 = sfun1(x0), f.f1c = sfun1c(x0)) ## Identities : stopifnot(identical(y0[-1], sfun0 (1:3)), # right = FALSE identical(y0[-4], sfun1c(1:3))) # right = TRUE </pre> <hr /><div style="text-align: center;">[Package <em>stats</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>