predict.basis {basefun} | R Documentation |
Evaluate Basis Functions
Description
Evaluate basis functions and compute the function defined by the corresponding basis
Usage
## S3 method for class 'basis'
predict(object, newdata, coef, dim = !is.data.frame(newdata), ...)
## S3 method for class 'cbind_bases'
predict(object, newdata, coef, dim = !is.data.frame(newdata),
terms = names(object), ...)
## S3 method for class 'box_bases'
predict(object, newdata, coef, dim = !is.data.frame(newdata), ...)
Arguments
object |
a |
newdata |
a |
coef |
a vector of coefficients |
dim |
either a logical indicating that the dimensions shall be
obtained from the |
terms |
a character vector defining the elements of a |
... |
additional arguments |
Details
predict
evaluates the basis functions and multiplies them with coef
.
There is no need to expand multiple variables as predict
uses array models
(Currie et al, 2006) to compute the corresponding predictions efficiently.
References
Ian D. Currie, Maria Durban, Paul H. C. Eilers, P. H. C. (2006), Generalized Linear Array Models with Applications to Multidimensional Smoothing, Journal of the Royal Statistical Society, Series B: Methodology, 68(2), 259–280.
Examples
### set-up a Bernstein polynomial
xv <- numeric_var("x", support = c(1, pi))
bb <- Bernstein_basis(xv, order = 3, ui = "increasing")
## and treatment contrasts for a factor at three levels
fb <- as.basis(~ g, data = factor_var("g", levels = LETTERS[1:3]))
### join them: we get one intercept and two deviation _functions_
bfb <- b(bern = bb, f = fb)
### generate data + coefficients
x <- mkgrid(bfb, n = 10)
cf <- c(1, 2, 2.5, 2.6)
cf <- c(cf, cf + 1, cf + 2)
### evaluate predictions for all combinations in x (a list!)
predict(bfb, newdata = x, coef = cf)
## same but slower
matrix(predict(bfb, newdata = expand.grid(x), coef = cf), ncol = 3)