meanEst {stfit}R Documentation

STFIT Mean Estimation

Description

The function is used for pixel-wise mean estimation.

Usage

meanEst(
  doy,
  mat,
  doyeval = seq(min(doy), max(doy)),
  msk = rep(FALSE, ncol(mat)),
  outlier.tol = 0.5,
  minimum.num.obs = 4,
  cluster = NULL,
  redo = TRUE,
  clipRange = c(-Inf, Inf),
  clipMethod = c("truncate", "nnr"),
  img.nrow = NULL,
  img.ncol = NULL
)

Arguments

doy

vector of day of year (DOY) index

mat

data matrix. Each row contains a row stacked image pixel values.

doyeval

a vector of DOY on which to get the mean imputation

msk

an optional logistic vector. TRUE represent the corresponding pixel is always missing.

outlier.tol

the tolerance value in defining an image as outlier. The percent of outlier pixels in an image exceed this value is regarded as outlier image which will not be used in temporal mean estimation.

minimum.num.obs

minimum number of observations needed for mean estimation. Too few observations may lead to big estimation error.

cluster

an optional vector defining clusters of pixels. If NULL, mean estimation is conducted on each pixel, otherwise all pixels from the same cluster are combined for mean estimation.

redo

whether to recalculate the mean estimation if there is an outlier (only redo once).

clipRange

vector of length 2, specifying the minimum and maximum values of the prediction value

clipMethod

"nnr" or "truncate". "nnr" uses average of nearest neighbor pixels to impute; "truncate use the clipRange value to truncate.

img.nrow

number of rows for an image, only used when 'clipMethod' is "nnr"

img.ncol

number of columns for an image, only used when 'clipMethod' is "nnr"

Details

There are several predefined methods for mean estimation: smooth_spline, llreg, lpreg and spreg. User can use opt$get() to check the current registered method and use opt$set() function to set the method. For exmaple, one can run opt$set(smooth_spline) first and then run the meanEst function to use smoothing spline regression for mean eatimation. User can also customize the methods for mean estimation. For example, mean estimation through fourier basis expansion:

.X = fda::eval.basis(1:365, fda::create.fourier.basis(rangeval=c(0,365), nbasis=11))
customfun <- function(x, y, x.eval=1:365, minimum.num.obs = 10){
  nonna.idx = !is.na(y)
  if(sum(nonna.idx) < minimum.num.obs)
    return(rep(NA, 365))
  ## lmfit = lm.fit(.X[unlist(lapply(x, function(x) which(x == x.eval))),], y[nonna.idx])
  lmfit = lm.fit(.X[x[nonna.idx],], y[nonna.idx])
  return(.X[x.eval,] 
}
stfit::opts_stfit$set(temporal_mean_est = customfun)

Value

a list containing the following entries:


[Package stfit version 0.99.9 Index]