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