R/stat-interpolate-methods.R

Defines functions predictdf2d.locfit predictdf2d.loess predictdf2d.glm predictdf2d.default predictdf2d

Documented in predictdf2d

#' Prediction data frame
#' 
#' Get predictions with standard errors into data frame
#' 
#' @param model the model to predict
#' @param xseq,yseq the x and y values
predictdf2d <- function(model, xseq, yseq) UseMethod("predictdf2d")

#' @export
predictdf2d.default <- function(model, xseq, yseq ) {
  newdata = expand.grid(x=xseq,y=yseq)
  pred    = stats::predict(model, newdata = newdata, se.fit = FALSE, interval = "none")
  data.frame(newdata, z = as.vector(pred))
}

#' @export
predictdf2d.glm <- function(model, xseq, yseq) {
  newdata = expand.grid(x=xseq,y=yseq)
  pred    = stats::predict(model, newdata = newdata, se.fit = FALSE, type = "link")
  data.frame(newdata, z = model$family$linkinv(as.vector(pred)))
}

#' @export
predictdf2d.loess <- function(model, xseq, yseq ) {
  newdata = expand.grid(x=xseq,y=yseq)
  pred    = stats::predict(model,newdata, se = FALSE)
  data.frame(newdata, z = as.vector(pred))
}

#' @export
predictdf2d.locfit <- function(model, xseq, yseq ) {
  newdata = expand.grid(x=xseq,y=yseq)
  pred    = stats::predict(model, newdata = newdata, se.fit = FALSE)
  data.frame(newdata, z = as.vector(pred))
}

Try the ggtern package in your browser

Any scripts or data that you put into this service are public.

ggtern documentation built on June 22, 2024, 11:01 a.m.