######### here's an itty-bitty example
######### simulate itty-bitty data
tau <- 21 #### number of time points
d.alpha <- 2
R.scale <- 1
sigma2 <- 0.01
F <- 1
Q <- 0
n.all <- 14 ##### number of spacial locations
set.seed(9999)
library(SSsimple)
locs.all <- cbind(runif(n.all, -1, 1), runif(n.all, -1, 1)) #### random location of sensors
D.mx <- distance(locs.all, locs.all, FALSE) #### distance matrix
#### create measurement variance using distance and covariogram
R.all <- exp(-d.alpha*D.mx) + diag(sigma2, n.all)
Hs.all <- matrix(1, n.all, 1) #### constant mean function
##### use SSsimple to simulate system
xsssim <- SS.sim(F=F, H=Hs.all, Q=Q, R=R.all, length.out=tau, beta0=0)
Z.all <- xsssim$Z ###### system observation matrix
######## suppose use the global mean as a prediction
z.mean <- mean(Z.all)
Z.delta <- Z.all - z.mean
z.lags.vec <- rep(0, n.all)
geodesic <- FALSE
alpha <- 5
flatten <- 1
## emmulate cross-validation, i.e.,
## don't use observed site values to predict themselves (zero-based)
self.refs <- 0
lags <- 0
locs1 <- cbind(locs.all, rep(0, n.all))
locs2 <- cbind(locs.all, rep(0, n.all))
Z.adj <- crispify(locs1, locs2, Z.delta, z.lags.vec, geodesic, alpha,
flatten, self.refs, lags, stnd.d = FALSE, log10cutoff = -16)
Z.adj
Z.hat <- z.mean + Z.adj
sqrt( mean( (Z.all - Z.hat)^2 ) )
######### set flatten to zero -- this means no crispification
Z.adj <- crispify(locs1, locs2, Z.delta, z.lags.vec, geodesic, alpha,
flatten=0, self.refs, lags, stnd.d = FALSE, log10cutoff = -16)
Z.adj
Z.hat <- z.mean + Z.adj
sqrt( mean( (Z.all - Z.hat)^2 ) )
Run the code above in your browser using DataLab