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

Description Usage Arguments Details Value See Also Examples

View source: R/Package_HAC_RAC_SHAC.r

Description

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

Usage

1
2
## S3 method for class 'kpbb'
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

Details

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

Value

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

See Also

predict.kpbb, data.simulation

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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)

cSFM documentation built on May 29, 2017, 6:10 p.m.

Related to predict.kpbb in cSFM...