#' @title Predict method for plm models
#' @description Obtains predictions from a plm object.
#' @param object a fitted object of class inheriting from "plm".
#' @param newdata optionally, a data frame in which to look for variables with which to predict. If omitted, the fitted linear predictors are used.
#' @param ... other arguments.
#' @export
predict.plm <- function(object, newdata, ...){
nn <- names(newdata)
lapply(1:nrow(newdata), FUN = function(i){
r <- newdata[i, ]
r <- as.data.frame(r, stringsAsFactors = FALSE) %>%
purrr::set_names(nn)
r_ <- as.list(r)
which_model <- do.call(object[["condition"]], r_)
mod <- object[["models"]][which_model]
sapply(mod, predict, newdata = r)
})
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.