R/fitMedianLonLat.R

Defines functions predMedianLonLat fitMedianLonLat

fitMedianLonLat <- function(TD, par0, TDout = NULL){

  cat("Estimating median for arbritary squares with > 100 instances.....")

  dtmp <- TD[, .(square_n = length(logerror), square_median = median(logerror)),
            by = .(square = paste0(round(longitude/1e5), round(latitude/1e5)))][square_n>100]


  out <- list( dtmp = dtmp, predf = predMedianLonLat, par0 = par0 )
  cat("DONE\n")

  out
}


predMedianLonLat <- function(l, newX, ...) {

  cat("Predicting based arbritary squares..... \n")
  lipsis <- list(...)

  if(is.null(lipsis$base_pred)){
    base_pred <- 0
  }else{
    base_pred <- lipsis$base_pred
  }


  dtpred <- merge(newX[, .(ord = 1:.N, square = paste0(round(longitude/1e5), round(latitude/1e5)))], l$dtmp[, .(square, square_median)], all.x = TRUE)

  pred0 <- dtpred[order(ord), square_median]

  ifelse(is.na(pred0), base_pred, pred0)
}
steinarv/k1 documentation built on Oct. 19, 2017, 4:41 a.m.