This help topic is for R version 1.5.0. For the current version of R, try https://stat.ethz.ch/R-manual/R-patched/library/stepfun/html/stepfun.html
stepfun {stepfun}R Documentation

Step Functions

Description

Given the vectors (x_1,\ldots, x_n) and (y_0,y_1,\ldots, y_n) (one value more!), stepfun(x,y,...) returns an interpolating “step” function, say fn. I.e., fn(t) = c_i (constant) for t \in (x_i, x_{i+1}) and fn(x_i) = y_i for i=1,\ldots,n.

The value of the constant c_i above depends on the “continuity” parameter f. For the default, f = 0, fn is a “cadlag” function, i.e. continuous at right, limit (“the point”) at left. In general, c_i is interpolated in between the neighbouring y values, c_i= (1-f) y_i + f\cdot y_{i+1}. Therefore, for non-0 values of f, fn may no longer be a proper step function, since it can be discontinuous from both sides.

Usage

stepfun(x, y, f = 0, ties = "ordered")

is.stepfun(x)
knots(Fn, ...)

## S3 method for class 'stepfun'
print(x, digits= getOption("digits") - 2, ...)
## S3 method for class 'stepfun'
summary(object, ...)

Arguments

x

numeric vector giving the knots or jump locations of the step function for stepfun(). For the other functions, x is as object below.

y

numeric vector one longer than x, giving the heights of the function values between the x values.

f

a number between 0 and 1, indicating how interpolation outside the given x values should happen. See approxfun.

ties

Handling of tied x values. Either a function or the string "ordered". See approxfun.

Fn, object

an R object inheriting from "stepfun".

digits

number of significant digits to use, see print.

...

potentially further arguments (require by the generic).

Value

A function of class "stepfun", say fn. There are methods available for summarizing ("summary(.)"), representing ("print(.)") and plotting ("plot(.)", see plot.stepfun) "stepfun" objects.

The environment of fn contains all the information needed;

The knots are also available by knots(fn).

Author(s)

Martin Maechler, maechler@stat.math.ethz.ch with some basic code from Thomas Lumley.

See Also

ecdf for empirical distribution functions as special step functions and plot.stepfun for plotting step functions.

approxfun and splinefun.

Examples

y0 <- c(1,2,4,3)
sfun0  <- stepfun(1:3, y0, f = 0)
sfun.2 <- stepfun(1:3, y0, f = .2)
sfun1  <- stepfun(1:3, y0, f = 1)
sfun0
summary(sfun0)
summary(sfun.2)

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))