Skip to content

Commit

Permalink
moving ctsem dependency to suggests
Browse files Browse the repository at this point in the history
adding heuristic to choose mtry in forests
added match.arg check in control
added semforest_control() alias
  • Loading branch information
brandmaier committed Mar 26, 2024
1 parent fe726ca commit 31c0348
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 12 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Depends:
Imports:
rpart,
rpart.plot (>= 3.0.6),
cluster,
lavaan,
cluster,
ggplot2,
tidyr,
methods,
Expand All @@ -25,7 +25,6 @@ Imports:
clisymbols,
future.apply,
data.table,
ctsemOMX,
expm,
gridBase
Suggests:
Expand All @@ -35,7 +34,8 @@ Suggests:
MASS,
psychTools,
testthat,
future
future,
ctsemOMX
Description: SEM Trees and SEM Forests -- an extension of model-based decision
trees and forests to Structural Equation Models (SEM). SEM trees hierarchically
split empirical data into homogeneous groups each sharing similar data patterns
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export(prune)
export(se)
export(semforest)
export(semforest.control)
export(semforest_control)
export(semforest_score_control)
export(semtree)
export(semtree.constraints)
Expand Down
4 changes: 0 additions & 4 deletions R/growTree.R
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,6 @@ growTree <- function(model = NULL, mydata = NULL,
return(NULL)
}
)
}
# 3. Traditional cross validation for covariate split selection
else if (control$method == "cv") {
stop("This split selection procedure is not supported anymore. Please see the new score-based tests for split selection.")
} else {
ui_fail("Error. Unknown split method selected")
stop()
Expand Down
7 changes: 7 additions & 0 deletions R/semforest.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ semforest <- function(model,

}

# set mtry heuristically if not set manually
if (is.null(semforest.control$mtry)) {
num_covariates <- length(covariate.ids)
mtry <- ceil(sqrt(num_covariates))
ui_message("Setting mtry = ",mtry," based on ",num_covariates," predictors.\n")
}

# pass mtry from forest to tree control
if (!is.na(semforest.control$semtree.control$mtry)) {
ui_stop(
Expand Down
8 changes: 7 additions & 1 deletion R/semforest.control.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' algorithm.
#'
#'
#' @aliases semforest.control print.semforest.control semforest_score_control
#' @aliases semforest.control 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.
Expand Down Expand Up @@ -55,3 +55,9 @@ semforest_score_control <- function(...)

return(ctrl)
}

#' @export
semforest_control <- function(...)
{
semforest.control(...)
}
4 changes: 2 additions & 2 deletions R/semtree.control.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
#'
#' @export
semtree.control <-
function(method = "naive",
function(method = c("naive","score","fair","fair3"),
min.N = 20,
max.depth = NA,
alpha = .05,
Expand Down Expand Up @@ -146,7 +146,7 @@ semtree.control <-
# minimum number of cases in leaf
options$min.bucket <- min.bucket
# method
options$method <- method
options$method <- match.arg(method)
# maximal depth of the tree , set to NA for unrestricted trees
options$max.depth <- max.depth
# test invariance of strong restrictions
Expand Down
1 change: 1 addition & 0 deletions man/semforest.control.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/semtree.control.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vignettes/forests.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ summary(result)
Create a forest control object that stores all tuning parameters of the forest. Note that we use only 5 trees for illustration. Please increase the number in real applications to several hundreds. To speed up computation time, consider score-based test for variable selection in the trees.

```{r}
control <- semforest.control(num.trees = 5)
control <- semforest_control(num.trees = 5)
print(control)
```

Expand Down

0 comments on commit 31c0348

Please sign in to comment.