R/summary.opt_importance_object.R

Defines functions summary.opt_importance_object

#' @export

summary.opt_importance_object = function(object, ...){

  # If the opt_importance function could give expectations for the RF_stability, summarise those
  if(!is.null(object$expected_RF_stability)){
    if(nrow(object$expected_RF_stability) == 4){
      cat("Recommended number of trees: ", object$recommendation, "\n",
          "Expected variable importance stability: ", object$expected_RF_stability[2], "\n",
          "Expected selection stability: ", object$expected_RF_stability[3], "\n",
          "Expected computation time (sec): ", object$expected_RF_stability[4], sep = "")
    }
    if(nrow(object$expected_RF_stability) == 3){
      if(row.names(object$expected_RF_stability)[2] =="Variable_importance_stability"){
        cat("Recommended number of trees: ", object$recommendation, "\n",
            "Expected variable importance stability: ", object$expected_RF_stability[2], "\n",
            "Expected computation time (sec): ", object$expected_RF_stability[3], sep = "")
      }
      if(row.names(object$expected_RF_stability)[2] =="Selection_stability"){
        cat("Recommended number of trees: ", object$recommendation, "\n",
            "Expected selection stability: ", object$expected_RF_stability[2], "\n",
            "Expected computation time (sec): ", object$expected_RF_stability[3], sep = "")
      }
    }
  }


  # if the opt_importance function could not give expectations for the RF_stability, summarise the result table
  else{
    if(!is.null(object$result.table)){
      cat("Result of the opt_importance function: \n")
      return(object$result.table)
    }

    # If neither the expectations nor the result table exist, give an error message
    else{
      stop("Result of the opt_importance function cannot be summarised.\n Did an error occur while running opt_importance? \n")
    }
  }
}

Try the optRF package in your browser

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

optRF documentation built on June 8, 2025, 10:24 a.m.