krigeSimCE function doesn't return the simulated value when newdata has no "data" attribute
Opened this issue · 2 comments
addAttrToGeom doesn't change the newdata. I think it should be newdata = addAttrToGeom(newdata, as.data.frame(sims))
krigeSimCE = function (formula, data, newdata, model, n = 1, ext = 2)
{
stopifnot(is(model, "variogramModel"))
stopifnot(gridded(newdata))
if (!missing(data))
stopifnot(identical(data@proj4string@projargs, newdata@proj4string@projargs))
varName <- all.vars(formula[[2]])
condSim <- TRUE
if (missing(data)) {
condSim <- FALSE
message("[No data provided: performing unconditional simulation.]")
}
else {
message("[Performing conditional simulation.]")
}
covMat <- ceWrapOnTorusCalcCovRow1(newdata, model, ext = ext)
sims <- ceSim(covMat, n, newdata@grid@cells.dim, newdata@grid.index)
colnames(sims) <- paste0(varName, ".sim", 1:n)
if (!condSim) {
if ("data" %in% slotNames(newdata))
newdata@data <- cbind(newdata@data, sims)
else newdata = addAttrToGeom(newdata, as.data.frame(sims))
return(newdata)
}
obsMeanField <- krige(formula, data, newdata, model)
simMeanObsLoc <- krigeMultiple(as.formula(paste0("var1.pred ",", formula[[3]])), data, newdata, model, simMeanObsLoc)
formula[[3]])), obsMeanField, data, model, sims)
simMeanFields <- krigeMultiple(as.formula(paste0(varName,
"
sims <- obsMeanField@data$var1.pred + sims - simMeanFields
if ("data" %in% slotNames(newdata)) {
newdata@data <- cbind(newdata@data, sims)
return(newdata)
}
newdata = addAttrToGeom(newdata, as.data.frame(sims))
}
I mean the "newdata = " part is missing in the original code.