This function evaluates a predefined spline basis at (new) given values.

# S3 method for bSpline2
predict(object, newx, ...)

# S3 method for ibs
predict(object, newx, ...)

# S3 method for dbs
predict(object, newx, ...)

# S3 method for mSpline
predict(object, newx, ...)

# S3 method for iSpline
predict(object, newx, ...)

# S3 method for cSpline
predict(object, newx, ...)

Arguments

object

Objects of class bSpline2, ibs, mSpline, iSpline, or cSpline having attributes describing knots, degree, etc.

newx

The x values at which evaluations are required.

...

Optional argument for future usage.

Value

An object just like the object input, except evaluated at the new values of x.

Details

These are methods for the generic function predict for objects inheriting from class bSpline2, ibs, mSpline, iSpline, or cSpline. If newx is not given, the function returns the input object. For object returned by function cSpline, the mSpline and iSpline objects shipped in attributes should not be evaluated by this function if rescale is TRUE. See cSpline for details.

See also

bSpline for B-splines; ibs for integral of B-splines; dbs for derivative of B-splines; mSpline for M-splines; iSpline for I-splines; cSpline for C-splines.

Examples

library(splines2) x <- seq.int(0, 1, 0.2) knots <- c(0.3, 0.5, 0.6) newX <- seq.int(0.1, 0.9, 0.2) ## for B-splines bsMat <- bSpline(x, knots = knots, degree = 2) predict(bsMat, newX)
#> 1 2 3 4 5 #> [1,] 0.4888889 0.06666667 0.000000e+00 0.0000 0.0000 #> [2,] 0.4000000 0.60000000 5.135813e-32 0.0000 0.0000 #> [3,] 0.0000000 0.33333333 6.666667e-01 0.0000 0.0000 #> [4,] 0.0000000 0.00000000 4.500000e-01 0.4875 0.0625 #> [5,] 0.0000000 0.00000000 5.000000e-02 0.3875 0.5625
## for integral of B-splines ibsMat <- ibs(x, knots = knots, degree = 2) predict(ibsMat, newX)
#> 1 2 3 4 5 #> [1,] 0.02740741 0.002222222 0.000000e+00 0.00000000 0.000000000 #> [2,] 0.14000000 0.060000000 9.503163e-49 0.00000000 0.000000000 #> [3,] 0.16666667 0.188888889 4.444444e-02 0.00000000 0.000000000 #> [4,] 0.16666667 0.200000000 1.883333e-01 0.04291667 0.002083333 #> [5,] 0.16666667 0.200000000 2.316667e-01 0.14541667 0.056250000
## for derivative of B-splines dbsMat <- dbs(x, knots = knots, degree = 2) predict(dbsMat, newX)
#> 1 2 3 4 5 #> [1,] 3.111111 1.333333 0.000000e+00 0.00 0.00 #> [2,] -4.000000 4.000000 1.850372e-15 0.00 0.00 #> [3,] 0.000000 -6.666667 6.666667e+00 0.00 0.00 #> [4,] 0.000000 0.000000 -3.000000e+00 1.75 1.25 #> [5,] 0.000000 0.000000 -1.000000e+00 -2.75 3.75
## for M-spline msMat <- mSpline(x, knots = knots, degree = 2) predict(msMat, newX)
#> 1 2 3 4 5 #> [1,] 2.933333 0.3333333 0.000000e+00 0.000 0.00000 #> [2,] 2.400000 3.0000000 2.201063e-31 0.000 0.00000 #> [3,] 0.000000 1.6666667 2.857143e+00 0.000 0.00000 #> [4,] 0.000000 0.0000000 1.928571e+00 2.925 0.46875 #> [5,] 0.000000 0.0000000 2.142857e-01 2.325 4.21875
## for I-spline isMat <- iSpline(x, knots = knots, degree = 2) predict(isMat, newX)
#> 1 2 3 4 5 #> [1,] 0.1644444 0.01111111 0.000000e+00 0.0000 0.000000 #> [2,] 0.8400000 0.30000000 4.072784e-48 0.0000 0.000000 #> [3,] 1.0000000 0.94444444 1.904762e-01 0.0000 0.000000 #> [4,] 1.0000000 1.00000000 8.071429e-01 0.2575 0.015625 #> [5,] 1.0000000 1.00000000 9.928571e-01 0.8725 0.421875
## for C-spline csMat <- cSpline(x, knots = knots, degree = 2) predict(csMat, newX)
#> 1 2 3 4 5 #> [1,] 0.007222222 0.0004273504 0.000000e+00 0.00000000 0.00000000 #> [2,] 0.135000000 0.0346153846 1.413031e-64 0.00000000 0.00000000 #> [3,] 0.375000000 0.2329059829 2.380952e-02 0.00000000 0.00000000 #> [4,] 0.625000000 0.5384615385 2.861607e-01 0.06416667 0.00390625 #> [5,] 0.875000000 0.8461538462 7.504464e-01 0.57527778 0.31640625