linearSplineIntegration: Linear Spline Integration

Description Usage Arguments Details Value See Also Examples

Description

lintegrate gives the values resulting from integrating a linear spline, while ilspline returns linear splines that integrate to given values.

Usage

1
2
lintegrate(x, y, xint, stepfun = F, rule = 0)
ilspline(xint, w)

Arguments

x

x coordinates of the linear spline F defined by (x, y)

y

y coordinates of the linear spline F defined by (x, y)

xint

x intervals, i.e. [x[1], x[2]] is the first interval, [x[2], x[3]] is the second interval, and so on.

stepfun

if TRUE, F is a left-continuous step function. The default (FALSE) says F is continuous.

rule

one of {0, 1, NA} to specify the behavior of F outside the range of x. Use zero if F is zero outside the range of x, NA if F is NA outside the range of x, and one if F is to be linearly extended outside the range of x.

w

values the linear spline must integrate to

Details

lintegrate integrates the linear spline F defined by (x,y) over the xint intervals. The value of F outside the range of x is specified by the rule argument:

1
2
3
    rule == 0  --> F(z) = 0 for z outside the range of x
    rule == NA --> F(z) = NA for z outside the range of x
    rule == 1  --> F(z) extended for z outside the range of x

If stepfun is TRUE, F(z) is assumed to be a left-continuous step function and the last value of y is never accessed.

(x[i], y[i]) pairs with NA values in either x[i] or y[i] NA are ignored in constructing F.

ilspline finds linear splines that integrate over the N intervals specified by the monotonically increasing N+1 vector xint to the N values given in w. The function finds N-vectors x and y such that:

1
2
3
4
5
6
7
  (i)  x[j] = (xint[j-1] + xint[j])/2, i.e., the values of x are the
       midpoints of the intervals specified by xint, and

  (ii) the linear spline that passes through the (x[i], y[i]) pairs (and
       is extended to xint[1] and xint[N+1] by linear
       extrapolation) integrates over each interval [xint[j],xint[j+1]]
       to w[j]. 

In fact, w can actually be an M by N matrix, in which case the y found by the function is also an M by N matrix, with each column of y giving the y coordinates of a linear spline that integrates to the corresponding column of w.

Value

lintegrate returns a vector of length length(xint) - 1.

ilspline returns a list with components named 'x' and 'y'.

See Also

spline, approx

Examples

1
2
3
4
w <- 10 + cumsum(rnorm(10))
blah <- ilspline(1:11, w)
ww <- lintegrate(blah$x, blah$y, 1:11, rule = 1)
w - ww  ## should be all zeroes (or very close to zero)

tis documentation built on Sept. 29, 2021, 1:06 a.m.