Learn R Programming

SCE (version 1.0.0)

SCA_tree_predict: Make Predictions Using a Single SCA Tree

Description

This function makes predictions using a single Stepwise Cluster Analysis (SCA) tree. It traverses the tree structure based on the predictor values in the test data and returns the predicted values for the predictants. The function includes comprehensive input validation for data types, missing values, and predictor matching.

For making predictions using an entire SCE ensemble, use Model_simulation instead.

Usage

SCA_tree_predict(Testing_data, model)

Value

A list containing:

  • A data.frame containing predictions for the test data

Arguments

Testing_data

A data.frame or matrix containing the test data. Must include all predictors used in model training. Must not contain missing values.

model

A trained SCA model object returned by the SCA function.

Author

Kailong Li <lkl98509509@gmail.com>

Details

The prediction process involves the following steps:

  1. Input validation:

    • Data type and structure checks (data.frame or matrix)

    • Missing value checks

    • Predictor matching with training data

    • Numeric data validation

  2. Data preparation:

    • Conversion to matrix format

    • Initialization of prediction matrix

  3. Tree traversal and prediction:

    • Processing each test sample through the tree

    • Generating predictions using leaf node mappings

References

Li, Kailong, Guohe Huang, and Brian Baetz. "Development of a Wilks feature importance method with improved variable rankings for supporting hydrological inference and modelling." Hydrology and Earth System Sciences 25.9 (2021): 4947-4966.

Examples

Run this code
## Load SCE package
library(SCE)

## Load training and testing data
data("Streamflow_training_10var")
data("Streamflow_testing_10var")

## Define independent (x) and dependent (y) variables
Predictors <- c("Prcp","SRad","Tmax","Tmin","VP","smlt","swvl1","swvl2","swvl3","swvl4")
Predictants <- c("Flow")

## Build the SCA model
Model <- SCA(
	Training_data = Streamflow_training_10var,
	X = Predictors,
	Y = Predictants,
	Nmin = 5,
	alpha = 0.05,
	resolution = 1000
)

## Make predictions
Predictions <- SCA_tree_predict(
	Testing_data = Streamflow_testing_10var,
	model = Model
)

Run the code above in your browser using DataLab