CrossStempCens: Cross-Validation in spatio-temporal model with...

Description Usage Arguments Value Author(s) See Also Examples

View source: R/CrossStempCens.R

Description

This function performs cross-validation in spatio-temporal model with censored/missing responses, which measure the performance of the predictive model on new test dataset. The cross-validation method for assessing the model performance is validation set approach (or data split).

Usage

1
CrossStempCens(Pred.StempCens, yObs.pre)

Arguments

Pred.StempCens

an object of class Pred.StempCens given as output by the PredStempCens function.

yObs.pre

a vector of the observed responses, the test data.

Value

Bias

bias prediction error.

Mspe

mean squared prediction error.

Rmspe

root mean squared prediction error.

Mae

mean absolute error.

Author(s)

Katherine L. Valeriano, Victor H. Lachos and Larissa A. Matos

See Also

EstStempCens, PredStempCens

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
## Not run: 
# Initial parameter values
beta <- c(-1,1.50)
phi <- 5;     rho <- 0.6
tau2 <- 0.80; sigma2 <- 2
# Simulating data
n1 <- 7    # Number of spatial locations
n2 <- 5    # Number of temporal index
set.seed(400)
x.co <- round(runif(n1,0,10),9)    # X coordinate
y.co <- round(runif(n1,0,10),9)    # Y coordinate
coord <- cbind(x.co,y.co)          # Cartesian coordinates without repetitions
coord2 <- cbind(rep(x.co,each=n2),rep(y.co,each=n2)) # Cartesian coordinates with repetitions
time <- as.matrix(seq(1,n2))       # Time index without repetitions
time2 <- as.matrix(rep(time,n1))   # Time index with repetitions
x1 <- rexp(n1*n2,2)
x2 <- rnorm(n1*n2,2,1)
x  <- cbind(x1,x2)
media <- x%*%beta
# Covariance matrix
Ms <- as.matrix(dist(coord))   # Spatial distances
Mt <- as.matrix(dist(time))    # Temporal distances
Cov <- CovarianceM(phi,rho,tau2,sigma2,Ms,Mt,0,"gaussian")
# Data
require(mvtnorm)
y <- as.vector(rmvnorm(1,mean=as.vector(media),sigma=Cov))
data <- data.frame(coord2,time2,y,x)
names(data) <- c("x.coord","y.coord","time","yObs","x1","x2")
# Splitting the dataset
local.est  <- coord[c(1,2,4,5,6),]
data.est   <- data[data$x.coord%in%local.est[,1] & data$y.coord%in%local.est[,2],]
data.valid <- data[data$x.coord%in%coord[c(3,7),1] & data$y.coord%in%coord[c(3,7),2],]
# Censored
perc <- 0.20
y  <- data.est$yObs
aa <- sort(y);  bb <- aa[1:(perc*nrow(data.est))]
cutof <- bb[perc*nrow(data.est)]
cc <- matrix(1,nrow(data.est),1)*(y<=cutof)
y[cc==1] <- cutof
data.est <- data.frame(data.est[,-c(4,5,6)],y,cc,data.est[,c(5,6)])
names(data.est) <- c("x.coord","y.coord","time","yObs","censored","x1","x2")

# Estimation
y  <- data.est$yObs
x  <- cbind(data.est$x1,data.est$x2)
cc <- data.est$censored
time2  <- as.data.frame(data.est$time)
coord2 <- data.est[,1:2]
LI <- y; LI[cc==1] <- -Inf     # Left-censored
LS <- y
est_teste <- EstStempCens(y, x, cc, time2, coord2, LI, LS, init.phi=3.5, init.rho=0.5,
                 init.tau2=1,type.Data="balanced", method="nlminb", kappa=0,
                 type.S="gaussian", IMatrix=FALSE, M=20, perc=0.25, MaxIter=300,
                 pc=0.20)
# Prediction
locPre <- data.valid[,1:2]
timePre <- as.data.frame(data.valid$time)
xPre <- cbind(data.valid$x1,data.valid$x2)
pre_teste <- PredStempCens(est_teste, locPre, timePre, xPre)
class(pre_teste)

# Cross-validation
cross_teste <- CrossStempCens(pre_teste,data.valid$yObs)
cross_teste$Mspe # MSPE
## End(Not run)

StempCens documentation built on Oct. 23, 2020, 7:28 p.m.