R/predict.r

Defines functions predict_probabiltiy predict_abundance

#' Title
#'
#' @param m
#' @param X_new
#' @param effort_new
#' @param se.fit
#' @param prediction_type
#'
#' @return
#' @export
#'
#' @examples
predict.brve <- function (object,
                          newdata = NULL, 
                          offset = log(effort),
                          type = c("abundance", "probability"),
                          se.fit = TRUE,
                          ...) {
    
    type <- match.arg(type)
    
    # Make predictions to new data
    predict_function <- switch(type, 
                               abundance = predict_abundance,
                               probability = predict_probability)
    
    p <- predict_function(object, newdata, se.fit)
    
    # return the prediction
    p
    
}

#' @noRd
predict_abundance <- function(object, newdata, se.fit) {
    
    if(se.fit == TRUE) {
        stop("Cannot fit standard errors in abundance prediction in brve")
    }
            
    p <- predict.glm(object,
                     type = "link",
                     se.fit = se.fit,
                     newdata = newdata)
    exp(p)
}

#' @noRd
predict_probabiltiy <- function(object, newdata, se.fit) {
    
    predict.glm(object,
                type = "response",
                se.fit = se.fit,
                newdata = newdata)
    
}
eunices/brve documentation built on June 22, 2020, 12:07 a.m.