Learn R Programming

cSFM (version 1.1)

predict.kpbb: Evaluate a predefined Kronecker product B-spline basis at provided values

Description

Evaluate a predefined Kronecker product B-spline basis at provided values.

Usage

"predict"(object, tp.valid, cp.valid = NULL, ...)

Arguments

object
the result returned by kpbb with corresponding attributes

tp.valid
the new time points at which the evaluations are requested; mainly for validation purpose

cp.valid
the new covariate points at which the evaluations are requested; mainly for validation purpose

...
other arguments passed to the generic function

Value

An object just like the inputed object, except evaluated at the new values of tp.valid and cp.valid.

Details

When cp.valid is allowed to be null, when only an univariate basis is considerred at object.

See Also

predict.kpbb, data.simulation

Examples

Run this code
data(data.simulation) # load benchmark data 
y <- DST$obs # matrix of observation
y.valid <- DSV$obs # matrix of training data; include missing values
# generate bivariate basis using 3 knots for each direction
basis <- kpbb(DST$tp, DST$cp, nknots.tp = 3, nknots.cp = 3)
# linear regression
lm.fit <- lm(as.vector(y) ~ basis - 1)
# prediction 
new.basis <- predict(basis, tp.valid = DSV$tp, cp.valid = DSV$cp)
y.predict <- matrix(crossprod(t(new.basis),coef(lm.fit)), nrow = length(DSV$cp))

# visualize the data and predicted surface
par(mfrow = c(1,2))
persp(DSV$cp, DSV$tp, y.valid, theta=60, phi=15,
      ticktype = "detailed", col="lightblue", 
      xlab = "covariate", ylab = "time",
      zlab="data", main="data surface (partically observed)")

persp(DSV$cp, DSV$tp, y.predict, theta=60, phi=15,
      ticktype = "detailed", col="lightblue", 
      xlab = "covariate", ylab = "time",
      zlab="data", main="predicted surface via lm")

# predication error
mean(((y.predict - DSV$obs.full)[!is.na(DSV$obs)])^2)

Run the code above in your browser using DataLab