dnychka / fieldsRPackage

GNU General Public License v2.0
14 stars 1 forks source link

`Krig.check.xY` may return Z as a vector instead of a matrix #4

Open shy86 opened 1 year ago

shy86 commented 1 year ago

In the function Krig.check.xY:

if (na.rm) {
    ind <- is.na(Y)
    if(all(ind)){
     stop("Oops! All Y values are missing!")
    }
    if (any(ind)) {
        Y <- Y[!ind]
        x <- as.matrix(x[!ind, ])
        if (!is.null(Z)) {
            Z <- Z[!ind, ]     <-----------------
        }
        weights <- weights[!ind]
    }
}

In the function Krig.replicates:

else {
  rep.info.aov <- fast.1way(rep.info, out$y, out$weights)
  tauHat.pure.error <- sqrt(rep.info.aov$MSE)
  tauHat.rep <- tauHat.pure.error
  yM <- as.matrix(rep.info.aov$means)
  weightsM <- rep.info.aov$w.means
  xM <- as.matrix(out$x[uniquerows, ])
  if (!is.null(out$Z)) {
    ZM <- as.matrix(out$Z[uniquerows, ])      <-----------------
  }
  else {
    ZM <- NULL
  }
  pure.ss <- rep.info.aov$SSE
  if (verbose) 
    print(rep.info.aov)
}

Krig.check.xY may return Z as a vector, which will trigger error of Krig.replicates, because Z is not a matrix.

A simple solution is Z[!ind, , drop = FALSE]