R/semforest.control.R

Defines functions semforest_score_control semforest.control

Documented in semforest.control semforest_score_control

#' SEM Forest Control Object
#'
#' A SEM Forest control object to tune parameters of the forest learning
#' algorithm.
#'
#'
#' @aliases semforest.control print.semforest.control semforest_score_control
#' @param num.trees Number of trees.
#' @param sampling Sampling procedure. Can be subsample or bootstrap.
#' @param control A SEM Tree control object. Will be generated by default.
#' @param mtry Number of subsampled covariates at each node.
#' @param remove_dead_trees Remove trees from forest that had runtime errors
#' @author Andreas M. Brandmaier, John J. Prindle
#' @references Brandmaier, A.M., Oertzen, T. v., McArdle, J.J., & Lindenberger,
#' U. (2013). Structural equation model trees. \emph{Psychological Methods},
#' 18(1), 71-86.
#'
#' @export
semforest.control <-
  function(num.trees = 5,
           sampling = "subsample",
           control = NA,
           mtry = 2,
           remove_dead_trees = TRUE)
  {
    
    options <- list()
    options$num.trees <- num.trees
    options$sampling <- sampling
    options$premtry <- 0
    options$mtry <- mtry
    if (all(is.na(control))) {
      options$semtree.control <- semtree.control()
      options$semtree.control$method <- "fair"
      options$semtree.control$alpha <- 1
      options$semtree.control$exclude.heywood <- FALSE
    } else {
      # 1.9.2022: switch refit to TRUE
      if (isFALSE(control$refit)) {
        warning("refit = FALSE detected. Models in root nodes require estimation for forests. Set refit to TRUE")
        control$refit <- TRUE
      }
      options$semtree.control <- control
    }
    options$remove_dead_trees <- remove_dead_trees
    class(options) <- "semforest.control"
    return(options)
  }

#' @export
semforest_score_control <- function(...)
{
  ctrl <- semforest.control(...)
  ctrl$semtree.control$method <- "score"
  
  return(ctrl)
}

Try the semtree package in your browser

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

semtree documentation built on Nov. 26, 2023, 5:07 p.m.