This function merges two forests.
The trees are combined and the variable importance is
calculated as a weighted average of the two forests.
If the forests are trained on the same data,
the predictions and oob_predictions are combined as well.
The out-of-environment predictions are combined if both forests have environments
and the observations have the same environments in both.
The merged forest then has env_seen, a logical matrix with one row per environment
and one column per tree, TRUE if the tree was trained on data of that environment.
Forests with environments that are trained on different data are merged as well.
The merged forest then has the data of both, and a tree is out of bag for
every observation of the other forest. The observations of the two forests are taken as distinct.
If the forests were fitted with different spectral transformations, the merged forest has
the transformation of the first forest, with a warning. For forests on different data
it is estimated on the joined data with the arguments of the first forest.
mergeForest(fit1, fit2)merged SDForest object
set.seed(1)
n <- 50
X <- matrix(rnorm(n * 5), nrow = n)
y <- sign(X[, 1]) * 3 + rnorm(n)
fit1 <- SDForest(x = X, y = y, Q_type = 'no_deconfounding', nTree = 5, cp = 0.5)
fit2 <- SDForest(x = X, y = y, nTree = 5, cp = 0.5)
mergeForest(fit1, fit2)