diff --git a/.github/workflows/R-CMD-check-windows.yaml b/.github/workflows/R-CMD-check-windows.yaml new file mode 100644 index 0000000..1d68a31 --- /dev/null +++ b/.github/workflows/R-CMD-check-windows.yaml @@ -0,0 +1,29 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: R-CMD-check-Win + +jobs: + R-CMD-check: + runs-on: windows-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 diff --git a/NAMESPACE b/NAMESPACE index 3fef987..0158412 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -34,6 +34,7 @@ S3method(summary,semforest) S3method(summary,semtree) S3method(toLatex,semtree) export(biodiversity) +export(boruta) export(diversityMatrix) export(evaluateTree) export(fitSubmodels) @@ -65,6 +66,7 @@ export(semforest_score_control) export(semtree) export(semtree.constraints) export(semtree.control) +export(semtree_control) export(strip) export(subforest) export(subtree) diff --git a/R/boruta.R b/R/boruta.R index 80ffd06..f3cfcca 100644 --- a/R/boruta.R +++ b/R/boruta.R @@ -1,35 +1,107 @@ +#' BORUTA algorithm for SEM trees +#' +#' This is an experimental feature. Use cautiously. +#' +#' @aliases boruta +#' @param model A template model specification from \code{\link{OpenMx}} using +#' the \code{\link{mxModel}} function (or a \code{\link[lavaan]{lavaan}} model +#' using the \code{\link[lavaan]{lavaan}} function with option fit=FALSE). +#' Model must be syntactically correct within the framework chosen, and +#' converge to a solution. +#' @param data Data.frame used in the model creation using +#' \code{\link{mxModel}} or \code{\link[lavaan]{lavaan}} are input here. Order +#' of modeled variables and predictors is not important when providing a +#' dataset to \code{semtree}. +#' @param control \code{\link{semtree}} model specifications from +#' \code{\link{semtree.control}} are input here. Any changes from the default +#' setting can be specified here. +#' @param percentile_threshold Numeric. +#' @param rounds Numeric. Number of rounds of the BORUTA algorithm. +#' +#' @export +#' boruta <- function(model, data, control = NULL, predictors = NULL, + percentile_threshold = 1, + rounds = 1, ...) { - # TODO: make sure that no column names start with "shadow_" prefix + + # initial checks + stopifnot(percentile_threshold>=0) + stopifnot(percentile_threshold<=1) + stopifnot(is.numeric(rounds)) + stopifnot(rounds>0) + + preds_important <- c() + preds_unimportant <- c() + + cur_round = 1 + temp_vims <- list() + + while(cur_round <= rounds) { + vim_boruta <- .boruta(model=model, + data=data, + control=control, + predictors=predictors, + percentile_threshold = percentile_threshold, + ...) + browser() + # add predictors to list of unimportant variables + preds_unimportant <- c(preds_unimportant, names(vim_boruta$filter)[!vim_boruta$filter]) + # remove them from the dataset + data <- data[, -c(preds_unimportant)] + temp_vims[[cur_round]] <-vim_boruta + } + + result <- list( + preds_unimportant, + rounds = rounds + ) + + return(result) +} + +.boruta <- function(model, + data, + control = NULL, + predictors = NULL, + percentile_threshold = 1, + num_shadows = 1, + ...) { + + # make sure that no column names start with "shadow_" prefix + stopifnot(all(sapply(names(data), function(x) {!startsWith(x, "shadow_")}))) # detect model (warning: duplicated code) if (inherits(model, "MxModel") || inherits(model, "MxRAMModel")) { tmp <- getPredictorsOpenMx(mxmodel = model, dataset = data, covariates = predictors) - model.ids <- tmp[[1]] - covariate.ids <- tmp[[2]] - # } else if (inherits(model,"lavaan")){ - # } else if ((inherits(model,"ctsemFit")) || (inherits(model,"ctsemInit"))) { - # + } else if (inherits(model,"lavaan")){ + + tmp <- getPredictorsLavaan(model, data, predictors) } else { ui_stop("Unknown model type selected. Use OpenMx or lavaanified lavaan models!") } + model.ids <- tmp[[1]] + covariate.ids <- tmp[[2]] # stage 1 - create shadow features shadow.ids <- (ncol(data) + 1):(ncol(data) + length(covariate.ids)) for (cur_cov_id in covariate.ids) { + for (rep_id in 1:num_shadows) { # pick column and shuffle temp_column <- data[, cur_cov_id] temp_column <- sample(temp_column, length(temp_column), replace = FALSE) # add to dataset as shadow feature temp_colname <- paste0("shadow_", names(data)[cur_cov_id], collapse = "") + if (num_shadows>1) temp_colname <- paste0(temp_colname, rep_id, collapse = "") data[temp_colname] <- temp_column if (!is.null(predictors)) predictors <- c(predictors, temp_colname) + } } # run the forest @@ -41,7 +113,11 @@ boruta <- function(model, # get variable importance from shadow features shadow_names <- names(data)[shadow.ids] agvim <- aggregateVarimp(vim, aggregate = "mean") - max_shadow_importance <- max(agvim[names(agvim) %in% shadow_names]) + + vals <- agvim[names(agvim) %in% shadow_names] + #max_shadow_importance <- max(vals) + max_shadow_importance <- quantile(vals, percentile_threshold) + agvim_filtered <- agvim[!(names(agvim) %in% shadow_names)] df <- data.frame(importance = agvim_filtered, predictor = names(agvim_filtered)) @@ -49,6 +125,7 @@ boruta <- function(model, vim$filter <- agvim_filtered > max_shadow_importance vim$boruta <- TRUE vim$boruta_threshold <- max_shadow_importance + vim$percentile_threshold <- percentile_threshold return(vim) } diff --git a/R/checkControl.R b/R/checkControl.R index 4bcd8f1..59f9d5d 100644 --- a/R/checkControl.R +++ b/R/checkControl.R @@ -11,6 +11,12 @@ checkControl <- function(control, fail = TRUE) { check.semtree.control <- function(control, fail = TRUE) { attr <- attributes(control)$names def.attr <- attributes(semtree.control())$names + + # add NULL-defaults + null_def <- c("min.N","min.bucket","strucchange.to") + attr <- unique(c(attr, null_def)) + def.attr <- unique(c(def.attr, null_def)) + if ((length(intersect(attr, def.attr)) != length(attr))) { unknown <- setdiff(attr, def.attr) msg <- diff --git a/R/checkModel.R b/R/checkModel.R index bd2ded8..2c11479 100644 --- a/R/checkModel.R +++ b/R/checkModel.R @@ -24,6 +24,3 @@ checkModel <- function(model, control) return(TRUE); } - -#inherits(model1,"lavaan") -#model1@Fit@converged diff --git a/R/growTree.R b/R/growTree.R index e47c4a3..630426b 100644 --- a/R/growTree.R +++ b/R/growTree.R @@ -64,7 +64,40 @@ growTree <- function(model = NULL, mydata = NULL, ui_message("Subsampled predictors: ", paste(node$colnames[meta$covariate.ids])) } } + + # override forced split? + arguments <- list(...) + if ("forced_splits" %in% names(arguments) && !is.null(arguments$forced_splits)) { + forced_splits <- arguments$forced_splits + + # get names of model variables before forcing + model.names <- names(mydata)[meta$model.ids] + covariate.names <- names(mydata)[meta$covariate.ids] + + # select subset with model variables and single, forced predictor + forcedsplit.name <- forced_splits[1] + + if (control$verbose) { + cat("FORCED split: ",forcedsplit.name,"\n") + } + + mydata <- fulldata[, c(model.names, forcedsplit.name) ] + node$colnames <- colnames(mydata) + + # get new model ids after sampling by name + meta$model.ids <- sapply(model.names, function(x) { + which(x == names(mydata)) + }) + names(meta$model.ids) <- NULL + meta$covariate.ids <- unlist(lapply(covariate.names, function(x) { + which(x == names(mydata)) + })) + + } else { + forced_splits <- NULL + } + # determine whether split evaluation can be done on p values node$p.values.valid <- control$method != "cv" @@ -432,6 +465,31 @@ growTree <- function(model = NULL, mydata = NULL, mydata <- fulldata meta <- fullmeta } + + # restore mydata if forced split was true + # and (potentially) force continuation of splitting + if (!is.null(forced_splits)) { + + + # also need to remap col.max to original data! + if (!is.null(result$col.max) && !is.na(result$col.max)) { + col.max.name <- names(mydata)[result$col.max] + result$col.max <- which(names(fulldata) == col.max.name) + } else { + col.max.name <- NULL + } + + mydata <- fulldata + meta <- fullmeta + + # pop first element + forced_splits <- forced_splits[-1] + # set to NULL if no splits left + if (length(forced_splits)==0) forced_splits <- NULL + + # force continuation of splitting ? + cont.split <- TRUE + } if ((!is.null(cont.split)) && (!is.na(cont.split)) && (cont.split)) { if (control$report.level > 10) { @@ -563,8 +621,8 @@ growTree <- function(model = NULL, mydata = NULL, # recursively continue splitting # result1 - RHS; result2 - LHS - result2 <- growTree(node$model, sub2, control, invariance, meta, edgelabel = 0, depth = depth + 1, constraints) - result1 <- growTree(node$model, sub1, control, invariance, meta, edgelabel = 1, depth = depth + 1, constraints) + result2 <- growTree(node$model, sub2, control, invariance, meta, edgelabel = 0, depth = depth + 1, constraints, forced_splits = forced_splits) + result1 <- growTree(node$model, sub1, control, invariance, meta, edgelabel = 1, depth = depth + 1, constraints, forced_splits = forced_splits) # store results in recursive list structure node$left_child <- result2 diff --git a/R/semtree.R b/R/semtree.R index e0ad5d4..1bd434c 100644 --- a/R/semtree.R +++ b/R/semtree.R @@ -140,16 +140,41 @@ semtree <- function(model, data = NULL, control = NULL, constraints = NULL, } } + # here we decide between four cases depending + # on whether min.N is given and/or min.bucket is given # this is a really dumb heuristic # please can someone replace this with something more useful # this based on (Bentler & Chou, 1987; see also Bollen, 1989) + if (is.null(control$min.N)) { - control$min.N <- 5 * npar(model) + + if (is.null(control$min.bucket)) { + # both values were not specified + control$min.N <- max(20, 5 * npar(model)) + control$min.bucket <- max(10, control$min.N / 2) + } else { + # only min.bucket was given, min.N was not specified + control$min.N <- control$min.bucket * 2 + } + } else { + if (is.null(control$min.bucket)) { + # only min.N was given, min.bucket was not specified + control$min.bucket <- max(10, control$min.N / 2) + } else { + # do nothing, both values were specified + if (control$min.bucket > control$min.N) { + warning("Min.bucket parameter should probably be smaller than min.N!") + } + } + } + + if (is.null(control$min.N)) { + } # set min.bucket and min.N heuristically if (is.null(control$min.bucket)) { - control$min.bucket <- control$min.N / 2 + } if (control$method == "cv") { diff --git a/R/semtree.control.R b/R/semtree.control.R index 1053412..aac81c0 100644 --- a/R/semtree.control.R +++ b/R/semtree.control.R @@ -100,7 +100,7 @@ #' @export semtree.control <- function(method = c("naive","score","fair","fair3"), - min.N = 20, + min.N = NULL, max.depth = NA, alpha = .05, alpha.invariance = NA, @@ -119,7 +119,7 @@ semtree.control <- # ordinal = 'maxLMo', # and maxLM are available # metric = 'maxLM'), linear = TRUE, - min.bucket = 10, + min.bucket = NULL, naive.bonferroni.type = 0, missing = 'ignore', use.maxlm = FALSE, @@ -200,8 +200,6 @@ semtree.control <- return(options) } - - #' @export semtree_control <- function(...) { semtree.control(...) diff --git a/R/varimp.R b/R/varimp.R index 9e17be2..4d51ed0 100644 --- a/R/varimp.R +++ b/R/varimp.R @@ -115,11 +115,14 @@ varimp <- function(forest, colnames(result$importance.level1) <- var.names } + if (dim(result$importance)[1] == 1) { - #result$importance<-t(result$importance) + result$importance<-t(result$importance) + + # TODO: this is stupid, should be as.matrix?! or something else result$ll.baselines <- - t(t(result$ll.baselines)) # TODO: this is stupid, should be as.matrix?! - } + t(t(result$ll.baselines)) + } colnames(result$importance) <- var.names result$var.names <- var.names diff --git a/docs/404.html b/docs/404.html index b7b4f49..379ce99 100644 --- a/docs/404.html +++ b/docs/404.html @@ -112,7 +112,7 @@

Page not found (404)

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/CONTRIBUTE.html b/docs/CONTRIBUTE.html index 9a53c55..bd16911 100644 --- a/docs/CONTRIBUTE.html +++ b/docs/CONTRIBUTE.html @@ -100,7 +100,7 @@

Some notes -

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/CONTRIBUTORS.html b/docs/CONTRIBUTORS.html index b5acfac..4fdcdb5 100644 --- a/docs/CONTRIBUTORS.html +++ b/docs/CONTRIBUTORS.html @@ -88,7 +88,7 @@

NA

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/LICENSE.html b/docs/LICENSE.html index 23b5d15..8de4495 100644 --- a/docs/LICENSE.html +++ b/docs/LICENSE.html @@ -280,7 +280,7 @@

How to Apply These Terms
-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/articles/constraints.html b/docs/articles/constraints.html index c7fe343..7fa85f9 100644 --- a/docs/articles/constraints.html +++ b/docs/articles/constraints.html @@ -94,7 +94,7 @@

Constraints in semtree

Andreas M. Brandmaier

-

2024-03-25

+

2024-04-15

Source: vignettes/constraints.Rmd @@ -200,68 +200,61 @@

Global Invariance
tree.gc <- semtree(model.cfa, data=cfa.sim, constraints=
                    semtree.constraints(global.invariance = 
                                          c("F__x1","F__x2","F__x3","F__x4")))
-#> > Model was not run. Estimating parameters now.
+#> ❯ Model was not run. Estimating parameters now.
 #> 
 Beginning initial fit attempt
-Fit attempt 0, fit=1259.86964139476, new current best! (was 23573.1076511312)
+Fit attempt 0, fit=1245.04605304561, new current best! (was 23512.9380282892)
                                                                              
-> Global Constraints:
+❯ Global Constraints:
 #> F__x1 F__x2 F__x3 F__x4
-#> > Freely Estimated Parameters:
+#> ❯ Freely Estimated Parameters:
 #> VAR_x1 VAR_x2 VAR_x3 VAR_x4 const__x2 const__x3 const__x4 const__F
 #> 
 Beginning initial fit attempt
-                             
-
-Beginning initial fit attempt
-Fit attempt 0, fit=626.987092715913, new current best! (was 868.957879718916)
-                                                                             
-
-Beginning initial fit attempt
-Fit attempt 0, fit=21.8133858849526, new current best! (was 297.189240590628)
-Beginning fit attempt 1 of at maximum 10 extra tries                         
-Fit attempt 1, fit=21.8133858848553, new current best! (was 21.8133858849526)
-Beginning fit attempt 2 of at maximum 10 extra tries                         
-Beginning fit attempt 3 of at maximum 10 extra tries
-Beginning fit attempt 4 of at maximum 10 extra tries
-Beginning fit attempt 5 of at maximum 10 extra tries
-Beginning fit attempt 6 of at maximum 10 extra tries
-Beginning fit attempt 7 of at maximum 10 extra tries
-Beginning fit attempt 8 of at maximum 10 extra tries
-Beginning fit attempt 9 of at maximum 10 extra tries
-Beginning fit attempt 10 of at maximum 10 extra tries
-                                                     
-
-Beginning initial fit attempt
-Fit attempt 0, fit=20.4870677058905, new current best! (was 329.797852125334)
-Beginning fit attempt 1 of at maximum 10 extra tries                         
-Beginning fit attempt 2 of at maximum 10 extra tries
-Beginning fit attempt 3 of at maximum 10 extra tries
-Beginning fit attempt 4 of at maximum 10 extra tries
-Beginning fit attempt 5 of at maximum 10 extra tries
-Beginning fit attempt 6 of at maximum 10 extra tries
-Beginning fit attempt 7 of at maximum 10 extra tries
-Beginning fit attempt 8 of at maximum 10 extra tries
-Beginning fit attempt 9 of at maximum 10 extra tries
-Beginning fit attempt 10 of at maximum 10 extra tries
-                                                     
-
-Beginning initial fit attempt
-Fit attempt 0, fit=140.391476915093, new current best! (was 390.911761675748)
-Beginning fit attempt 1 of at maximum 10 extra tries                         
-Fit attempt 1, fit=140.391476914989, new current best! (was 140.391476915093)
-Beginning fit attempt 2 of at maximum 10 extra tries                         
-Fit attempt 2, fit=140.391476914986, new current best! (was 140.391476914989)
-Beginning fit attempt 3 of at maximum 10 extra tries                         
-Beginning fit attempt 4 of at maximum 10 extra tries
-Beginning fit attempt 5 of at maximum 10 extra tries
-Beginning fit attempt 6 of at maximum 10 extra tries
-Beginning fit attempt 7 of at maximum 10 extra tries
-Beginning fit attempt 8 of at maximum 10 extra tries
-Beginning fit attempt 9 of at maximum 10 extra tries
-Beginning fit attempt 10 of at maximum 10 extra tries
-                                                     
-
[32m✔
[39m Tree construction finished [took 6s].
+Fit attempt 0, fit=1245.0460530455, new current best! (was 1245.04605304558) + + +Beginning initial fit attempt +Fit attempt 0, fit=700.981679486895, new current best! (was 935.197549062569) + + +Beginning initial fit attempt +Fit attempt 0, fit=82.3725219274684, new current best! (was 404.027616923408) +Beginning fit attempt 1 of at maximum 10 extra tries +Fit attempt 1, fit=82.3725219274052, new current best! (was 82.3725219274684) + + +Beginning initial fit attempt +Fit attempt 0, fit=-12.8178155443534, new current best! (was 296.954062563265) +Beginning fit attempt 1 of at maximum 10 extra tries +Fit attempt 1, fit=-12.8178155443725, new current best! (was -12.8178155443534) +Beginning fit attempt 2 of at maximum 10 extra tries +Beginning fit attempt 3 of at maximum 10 extra tries +Beginning fit attempt 4 of at maximum 10 extra tries +Beginning fit attempt 5 of at maximum 10 extra tries +Beginning fit attempt 6 of at maximum 10 extra tries +Beginning fit attempt 7 of at maximum 10 extra tries +Beginning fit attempt 8 of at maximum 10 extra tries +Beginning fit attempt 9 of at maximum 10 extra tries +Beginning fit attempt 10 of at maximum 10 extra tries + + +Beginning initial fit attempt +Fit attempt 0, fit=41.8996556241436, new current best! (was 309.848503983403) +Beginning fit attempt 1 of at maximum 10 extra tries +Fit attempt 1, fit=41.8996556240704, new current best! (was 41.8996556241436) +Beginning fit attempt 2 of at maximum 10 extra tries +Fit attempt 2, fit=41.8996556240695, new current best! (was 41.8996556240704) +Beginning fit attempt 3 of at maximum 10 extra tries +Beginning fit attempt 4 of at maximum 10 extra tries +Beginning fit attempt 5 of at maximum 10 extra tries +Beginning fit attempt 6 of at maximum 10 extra tries +Beginning fit attempt 7 of at maximum 10 extra tries +Beginning fit attempt 8 of at maximum 10 extra tries +Beginning fit attempt 9 of at maximum 10 extra tries +Beginning fit attempt 10 of at maximum 10 extra tries + +
[32m✔
[39m Tree construction finished [took less than a second].
 plot(tree.gc)

@@ -289,35 +282,36 @@

Local Invariance
tree.lc <- semtree(model.cfa, data=cfa.sim, constraints=
                    semtree.constraints(
                      local.invariance= c("F__x1","F__x2","F__x3","F__x4")))
-#> > Model was not run. Estimating parameters now.
+#> ❯ Model was not run. Estimating parameters now.
 #> 
 Beginning initial fit attempt
-Fit attempt 0, fit=1259.86964139476, new current best! (was 23573.1076511312)
+Fit attempt 0, fit=1245.04605304561, new current best! (was 23512.9380282892)
                                                                              
-> No Invariance alpha selected. alpha.invariance set to:0.05
+❯ No Invariance alpha selected. alpha.invariance set to:0.05
 #> 
 Beginning initial fit attempt
-                             
-
-Beginning initial fit attempt
-Fit attempt 0, fit=594.224449688255, new current best! (was 868.957879718916)
-                                                                             
-
-Beginning initial fit attempt
-Fit attempt 0, fit=118.828548931502, new current best! (was 390.911761675748)
-Beginning fit attempt 1 of at maximum 10 extra tries                         
-Fit attempt 1, fit=118.828548931421, new current best! (was 118.828548931502)
-Beginning fit attempt 2 of at maximum 10 extra tries                         
-Beginning fit attempt 3 of at maximum 10 extra tries
-Beginning fit attempt 4 of at maximum 10 extra tries
-Beginning fit attempt 5 of at maximum 10 extra tries
-Beginning fit attempt 6 of at maximum 10 extra tries
-Beginning fit attempt 7 of at maximum 10 extra tries
-Beginning fit attempt 8 of at maximum 10 extra tries
-Beginning fit attempt 9 of at maximum 10 extra tries
-Beginning fit attempt 10 of at maximum 10 extra tries
-                                                     
-
[32m✔
[39m Tree construction finished [took 5s].
+Fit attempt 0, fit=1245.04605304549, new current best! (was 1245.04605304561) + + +Beginning initial fit attempt +Fit attempt 0, fit=674.376601044165, new current best! (was 935.197546229974) + + +Beginning initial fit attempt +Fit attempt 0, fit=14.8502289550343, new current best! (was 309.84850681597) +Beginning fit attempt 1 of at maximum 10 extra tries +Fit attempt 1, fit=14.8502289550283, new current best! (was 14.8502289550343) +Beginning fit attempt 2 of at maximum 10 extra tries +Beginning fit attempt 3 of at maximum 10 extra tries +Beginning fit attempt 4 of at maximum 10 extra tries +Beginning fit attempt 5 of at maximum 10 extra tries +Beginning fit attempt 6 of at maximum 10 extra tries +Beginning fit attempt 7 of at maximum 10 extra tries +Beginning fit attempt 8 of at maximum 10 extra tries +Beginning fit attempt 9 of at maximum 10 extra tries +Beginning fit attempt 10 of at maximum 10 extra tries + +
[32m✔
[39m Tree construction finished [took 1s].

Now we find p1 as the only predictor that yields subgroups that pass the measurement invariance test. Even though we have chosen the four factor loadings as local.invariance @@ -379,11 +373,11 @@

Focus Parameters#> #> free parameters: #> name matrix row col Estimate Std.Error A -#> 1 VAR_x1 S x1 x1 4.0283800 0.18015521 -#> 2 COV_x1_x2 S x1 x2 0.3039196 0.11444978 -#> 3 VAR_x2 S x2 x2 3.2282345 0.14437113 -#> 4 mu1 M 1 x1 1.4187341 0.06346967 -#> 5 mu2 M 1 x2 1.4628999 0.05681795 +#> 1 VAR_x1 S x1 x1 4.0283800 0.18015309 +#> 2 COV_x1_x2 S x1 x2 0.3039196 0.11443882 +#> 3 VAR_x2 S x2 x2 3.2282345 0.14437055 +#> 4 mu1 M 1 x1 1.4187341 0.06346921 +#> 5 mu2 M 1 x2 1.4628999 0.05681732 #> #> Model Statistics: #> | Parameters | Degrees of Freedom | Fit (-2lnL units) @@ -401,15 +395,15 @@

Focus Parameters#> RMSEA: 0 [95% CI (NA, NA)] #> Prob(RMSEA <= 0.05): NA #> To get additional fit indices, see help(mxRefModels) -#> timestamp: 2024-03-25 12:03:04 -#> Wall clock time: 0.04624796 secs +#> timestamp: 2024-04-15 22:32:57 +#> Wall clock time: 0.009307146 secs #> optimizer: SLSQP #> OpenMx version number: 2.21.1 #> Need help? See help(mxSummary)

Now, we grow a tree without constraints:


 tree.biv <- semtree(model.biv, data=df.biv)
-#> > Model was not run. Estimating parameters now.
+#> ❯ Model was not run. Estimating parameters now.
 #> 
 Beginning initial fit attempt
 Fit attempt 0, fit=8233.92582585158, new current best! (was 14528.4141425595)
@@ -420,29 +414,29 @@ 

Focus Parameters Beginning initial fit attempt -Fit attempt 0, fit=3454.12434636158, new current best! (was 4066.88531949563) +Fit attempt 0, fit=3454.12434636158, new current best! (was 4066.88531930229) Beginning initial fit attempt -Fit attempt 0, fit=1555.54412300078, new current best! (was 1720.05414322814) +Fit attempt 0, fit=1555.54412300078, new current best! (was 1720.05414323192) Beginning initial fit attempt -Fit attempt 0, fit=1569.26472590267, new current best! (was 1734.07020313343) +Fit attempt 0, fit=1569.26472590267, new current best! (was 1734.07020312965) Beginning initial fit attempt -Fit attempt 0, fit=3566.5692080098, new current best! (was 4167.0405063558) - +Fit attempt 0, fit=3566.5692080098, new current best! (was 4167.04050654914) + Beginning initial fit attempt -Fit attempt 0, fit=1593.91684303245, new current best! (was 1780.60715330577) +Fit attempt 0, fit=1593.91684303245, new current best! (was 1780.60715331027) Beginning initial fit attempt -Fit attempt 0, fit=1576.27862642528, new current best! (was 1785.96205470403) +Fit attempt 0, fit=1576.27862642528, new current best! (was 1785.96205469953) -
[32m✔
[39m Tree construction finished [took 3s].

+
[32m✔
[39m Tree construction finished [took less than a second].

As expected, we obtain a tree structure that has both p1 and p2 (here we use the viridis colors to give each leaf node a different frame color, which we’ll use later again):

@@ -482,7 +476,7 @@

Focus Parameters

 tree.biv2 <- semtree(model.biv, df.biv, constraints=
                       semtree.constraints(focus.parameters = "mu1"))
-#> > Model was not run. Estimating parameters now.
+#> ❯ Model was not run. Estimating parameters now.
 #> 
 Beginning initial fit attempt
 Fit attempt 0, fit=8233.92582585158, new current best! (was 14528.4141425595)
@@ -493,13 +487,13 @@ 

Focus Parameters Beginning initial fit attempt -Fit attempt 0, fit=3740.92185296731, new current best! (was 4086.36288876948) +Fit attempt 0, fit=3740.92185296731, new current best! (was 4086.36288893237) Beginning initial fit attempt -Fit attempt 0, fit=3795.16307144921, new current best! (was 4147.56293708195) +Fit attempt 0, fit=3795.16307144921, new current best! (was 4147.56293691906) -
[32m✔
[39m Tree construction finished [took 2s].

+
[32m✔
[39m Tree construction finished [took less than a second].
 plot(tree.biv2)

@@ -511,7 +505,7 @@

Focus Parameters

 tree.biv3 <- semtree(model.biv, df.biv, constraints=
                       semtree.constraints(focus.parameters = "mu2"))
-#> > Model was not run. Estimating parameters now.
+#> ❯ Model was not run. Estimating parameters now.
 #> 
 Beginning initial fit attempt
 Fit attempt 0, fit=8233.92582585158, new current best! (was 14528.4141425595)
@@ -522,13 +516,13 @@ 

Focus Parameters Beginning initial fit attempt -Fit attempt 0, fit=3454.12434636158, new current best! (was 4066.88531949563) +Fit attempt 0, fit=3454.12434636158, new current best! (was 4066.88531930229) Beginning initial fit attempt -Fit attempt 0, fit=3566.5692080098, new current best! (was 4167.0405063558) - -
[32m✔
[39m Tree construction finished [took 2s].

+Fit attempt 0, fit=3566.5692080098, new current best! (was 4167.04050654914) + +
[32m✔
[39m Tree construction finished [took less than a second].

And, indeed, we see only grp2 as predictor whereas grp1 was not selected this time.

@@ -541,7 +535,7 @@ 

Focus Parameters

 tree.biv4 <- semtree(model.biv, df.biv, constraints=
                       semtree.constraints(focus.parameters = "VAR_x2"))
-#> > Model was not run. Estimating parameters now.
+#> ❯ Model was not run. Estimating parameters now.
 #> 
 Beginning initial fit attempt
 Fit attempt 0, fit=8233.92582585158, new current best! (was 14528.4141425595)
@@ -550,7 +544,7 @@ 

Focus ParametersBeginning initial fit attempt Fit attempt 0, fit=8233.92582585143, new current best! (was 8233.92582585158) -
[32m✔
[39m Tree construction finished [took 1s]. +
[32m✔
[39m Tree construction finished [took less than a second]. plot(tree.biv4)

@@ -575,7 +569,7 @@

Focus Parameters

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/articles/constraints_files/figure-html/plbv2-1.png b/docs/articles/constraints_files/figure-html/plbv2-1.png index 9f97b31..2441608 100644 Binary files a/docs/articles/constraints_files/figure-html/plbv2-1.png and b/docs/articles/constraints_files/figure-html/plbv2-1.png differ diff --git a/docs/articles/constraints_files/figure-html/unnamed-chunk-10-1.png b/docs/articles/constraints_files/figure-html/unnamed-chunk-10-1.png index aaf7f14..ad1756f 100644 Binary files a/docs/articles/constraints_files/figure-html/unnamed-chunk-10-1.png and b/docs/articles/constraints_files/figure-html/unnamed-chunk-10-1.png differ diff --git a/docs/articles/constraints_files/figure-html/unnamed-chunk-11-1.png b/docs/articles/constraints_files/figure-html/unnamed-chunk-11-1.png index 9b4d438..e3d44d2 100644 Binary files a/docs/articles/constraints_files/figure-html/unnamed-chunk-11-1.png and b/docs/articles/constraints_files/figure-html/unnamed-chunk-11-1.png differ diff --git a/docs/articles/constraints_files/figure-html/unnamed-chunk-12-1.png b/docs/articles/constraints_files/figure-html/unnamed-chunk-12-1.png index 10cdbd1..7585b2c 100644 Binary files a/docs/articles/constraints_files/figure-html/unnamed-chunk-12-1.png and b/docs/articles/constraints_files/figure-html/unnamed-chunk-12-1.png differ diff --git a/docs/articles/constraints_files/figure-html/unnamed-chunk-14-1.png b/docs/articles/constraints_files/figure-html/unnamed-chunk-14-1.png index 26296be..88d33d5 100644 Binary files a/docs/articles/constraints_files/figure-html/unnamed-chunk-14-1.png and b/docs/articles/constraints_files/figure-html/unnamed-chunk-14-1.png differ diff --git a/docs/articles/constraints_files/figure-html/unnamed-chunk-15-1.png b/docs/articles/constraints_files/figure-html/unnamed-chunk-15-1.png index fea4170..41ba7dc 100644 Binary files a/docs/articles/constraints_files/figure-html/unnamed-chunk-15-1.png and b/docs/articles/constraints_files/figure-html/unnamed-chunk-15-1.png differ diff --git a/docs/articles/constraints_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/constraints_files/figure-html/unnamed-chunk-4-1.png index ecf3969..66505ec 100644 Binary files a/docs/articles/constraints_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/constraints_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/constraints_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/constraints_files/figure-html/unnamed-chunk-6-1.png index 3e1eb5f..2a78766 100644 Binary files a/docs/articles/constraints_files/figure-html/unnamed-chunk-6-1.png and b/docs/articles/constraints_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/forests.html b/docs/articles/forests.html index c698c65..a3063da 100644 --- a/docs/articles/forests.html +++ b/docs/articles/forests.html @@ -94,7 +94,7 @@

SEM Forests

Andreas Brandmaier

-

2024-03-25

+

2024-04-15

Source: vignettes/forests.Rmd @@ -359,8 +359,8 @@

Create simple model of state anxie #> RMSEA: 0 [95% CI (NA, NA)] #> Prob(RMSEA <= 0.05): NA #> To get additional fit indices, see help(mxRefModels) -#> timestamp: 2024-03-25 12:03:32 -#> Wall clock time: 0.114706 secs +#> timestamp: 2024-04-15 22:33:05 +#> Wall clock time: 0.02428603 secs #> optimizer: SLSQP #> OpenMx version number: 2.21.1 #> Need help? See help(mxSummary) @@ -374,7 +374,7 @@

Forest up computation time, consider score-based test for variable selection in the trees.

-control <- semforest.control(num.trees = 5)
+control <- semforest_control(num.trees = 5)
 print(control)
 #> SEM-Forest control:
 #> -----------------
@@ -413,8 +413,10 @@ 

Variable importancevim <- varimp(forest) print(vim, sort.values=TRUE) #> Variable Importance -#> Study PA2 Film NA2 state1 TA2 -#> 0.00000 28.06156 35.63105 38.45805 42.92733 45.01637 +#> Study PA2 state1 TA2 Film +#> -9.659311e-08 9.418006e+00 1.218599e+01 2.066494e+01 2.537268e+01 +#> NA2 +#> 3.658740e+01 plot(vim)

From this, we can learn that variables such as NA2 @@ -443,7 +445,7 @@

Variable importance

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/articles/forests_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/forests_files/figure-html/unnamed-chunk-6-1.png index 13f899b..8d75b91 100644 Binary files a/docs/articles/forests_files/figure-html/unnamed-chunk-6-1.png and b/docs/articles/forests_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/getting-started.html b/docs/articles/getting-started.html index 488ced1..b2b6bf1 100644 --- a/docs/articles/getting-started.html +++ b/docs/articles/getting-started.html @@ -108,6 +108,7 @@

Load the Package
 library(semtree)
 #> Loading required package: OpenMx
+#> OpenMx may run faster if it is compiled to take advantage of multiple cores.
 library(OpenMx)
@@ -201,7 +202,10 @@

Specify an OpenMx model # fit the model to the entire dataset growthCurveModel <- mxRun(growthCurveModel) -#> Running Linear Growth Curve Model Path Specification with 6 parameters

+#> Running Linear Growth Curve Model Path Specification with 6 parameters +#> Warning: In model 'Linear Growth Curve Model Path Specification' Optimizer +#> returned a non-zero status code 5. The Hessian at the solution does not appear +#> to be convex. See ?mxCheckIdentification for possible diagnosis (Mx status RED).

Run a tree @@ -241,7 +245,7 @@

Plotting

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/articles/getting-started_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/getting-started_files/figure-html/unnamed-chunk-4-1.png index 32d3cf2..f3cdf87 100644 Binary files a/docs/articles/getting-started_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/getting-started_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/index.html b/docs/articles/index.html index 5d10705..3d99133 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -92,7 +92,7 @@

All vignettes

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/articles/score-based-tests.html b/docs/articles/score-based-tests.html index 9489cf6..cc5b0ef 100644 --- a/docs/articles/score-based-tests.html +++ b/docs/articles/score-based-tests.html @@ -94,7 +94,7 @@

SEM Trees with score-based tests

Andreas M. Brandmaier

-

2024-03-25

+

2024-04-15

Source: vignettes/score-based-tests.Rmd @@ -220,6 +220,7 @@

Create simple model of state anxie variance of DeltaPA.

 library(OpenMx)
+#> OpenMx may run faster if it is compiled to take advantage of multiple cores.
 manifests<-c("DeltaPA")
 latents<-c()
 model <- mxModel("Simple Model", 
@@ -257,8 +258,8 @@ 

Create simple model of state anxie #> RMSEA: 0 [95% CI (NA, NA)] #> Prob(RMSEA <= 0.05): NA #> To get additional fit indices, see help(mxRefModels) -#> timestamp: 2024-03-25 12:06:18 -#> Wall clock time: 0.112819 secs +#> timestamp: 2024-04-15 22:33:34 +#> Wall clock time: 0.02639604 secs #> optimizer: SLSQP #> OpenMx version number: 2.21.1 #> Need help? See help(mxSummary)

@@ -330,7 +331,7 @@

Score-based Tests

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/articles/score-based-tests_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/score-based-tests_files/figure-html/unnamed-chunk-6-1.png index 2215fd0..467c4b7 100644 Binary files a/docs/articles/score-based-tests_files/figure-html/unnamed-chunk-6-1.png and b/docs/articles/score-based-tests_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/score-based-tests_files/figure-html/unnamed-chunk-7-1.png b/docs/articles/score-based-tests_files/figure-html/unnamed-chunk-7-1.png index 281ee5e..bdc024d 100644 Binary files a/docs/articles/score-based-tests_files/figure-html/unnamed-chunk-7-1.png and b/docs/articles/score-based-tests_files/figure-html/unnamed-chunk-7-1.png differ diff --git a/docs/articles/score-based-tests_files/figure-html/unnamed-chunk-8-1.png b/docs/articles/score-based-tests_files/figure-html/unnamed-chunk-8-1.png index e9f8fa0..1064335 100644 Binary files a/docs/articles/score-based-tests_files/figure-html/unnamed-chunk-8-1.png and b/docs/articles/score-based-tests_files/figure-html/unnamed-chunk-8-1.png differ diff --git a/docs/articles/semforest-focus.html b/docs/articles/semforest-focus.html index 9e2203a..3defd3c 100644 --- a/docs/articles/semforest-focus.html +++ b/docs/articles/semforest-focus.html @@ -94,7 +94,7 @@

Focus parameters in SEM forests

Andreas M. Brandmaier

-

2024-03-25

+

2024-04-15

Source: vignettes/semforest-focus.Rmd @@ -116,6 +116,7 @@

2024-03-25

library(semtree) #> Loading required package: OpenMx +#> OpenMx may run faster if it is compiled to take advantage of multiple cores. set.seed(123) N <- 1000 grp1 <- factor(sample(x = c(0,1), size=N, replace=TRUE)) @@ -154,11 +155,11 @@

2024-03-25

#> #> free parameters: #> name matrix row col Estimate Std.Error A -#> 1 VAR_x1 S x1 x1 4.0583666 0.18149512 -#> 2 COV_x1_x2 S x1 x2 0.1970528 0.11385399 -#> 3 VAR_x2 S x2 x2 3.1848900 0.14243121 -#> 4 mu1 M 1 x1 1.4858354 0.06370452 -#> 5 mu2 M 1 x2 1.4551364 0.05643442 +#> 1 VAR_x1 S x1 x1 4.0583666 0.18149573 +#> 2 COV_x1_x2 S x1 x2 0.1970528 0.11384948 +#> 3 VAR_x2 S x2 x2 3.1848900 0.14243161 +#> 4 mu1 M 1 x1 1.4858354 0.06370544 +#> 5 mu2 M 1 x2 1.4551364 0.05643474 #> #> Model Statistics: #> | Parameters | Degrees of Freedom | Fit (-2lnL units) @@ -176,8 +177,8 @@

2024-03-25

#> RMSEA: 0 [95% CI (NA, NA)] #> Prob(RMSEA <= 0.05): NA #> To get additional fit indices, see help(mxRefModels) -#> timestamp: 2024-03-25 12:06:44 -#> Wall clock time: 0.123879 secs +#> timestamp: 2024-04-15 22:33:42 +#> Wall clock time: 0.02595901 secs #> optimizer: SLSQP #> OpenMx version number: 2.21.1 #> Need help? See help(mxSummary)
@@ -240,7 +241,7 @@

2024-03-25

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/articles/semforest-focus_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/semforest-focus_files/figure-html/unnamed-chunk-4-1.png index 7a40f4d..f27d790 100644 Binary files a/docs/articles/semforest-focus_files/figure-html/unnamed-chunk-4-1.png and b/docs/articles/semforest-focus_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/semforest-focus_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/semforest-focus_files/figure-html/unnamed-chunk-6-1.png index ad01d51..ed33957 100644 Binary files a/docs/articles/semforest-focus_files/figure-html/unnamed-chunk-6-1.png and b/docs/articles/semforest-focus_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/semforest-focus_files/figure-html/unnamed-chunk-8-1.png b/docs/articles/semforest-focus_files/figure-html/unnamed-chunk-8-1.png index 5fbbedb..d34bf06 100644 Binary files a/docs/articles/semforest-focus_files/figure-html/unnamed-chunk-8-1.png and b/docs/articles/semforest-focus_files/figure-html/unnamed-chunk-8-1.png differ diff --git a/docs/articles/semforest-focus_files/figure-html/unnamed-chunk-9-1.png b/docs/articles/semforest-focus_files/figure-html/unnamed-chunk-9-1.png index c8631b4..13643a9 100644 Binary files a/docs/articles/semforest-focus_files/figure-html/unnamed-chunk-9-1.png and b/docs/articles/semforest-focus_files/figure-html/unnamed-chunk-9-1.png differ diff --git a/docs/authors.html b/docs/authors.html index 2fcfd84..7f21068 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -118,7 +118,7 @@

Citation

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/index.html b/docs/index.html index 81f3909..ba3d0a9 100644 --- a/docs/index.html +++ b/docs/index.html @@ -115,7 +115,7 @@

Install
install.packages("semtree")

To install the latest semtree package directly from GitHub, copy the following line into R:

library(devtools)
-devtools::install_github("semtree/brandmaier")
+devtools::install_github("brandmaier/semtree")
 
 # even better: install with package vignette (extra documentation)
 devtools::install_github("brandmaier/semtree",force=TRUE, build_opts = c())
@@ -124,7 +124,6 @@

InstallUsage

Package documentation and use-cases with runnable R code can be found on our github pages: https://brandmaier.github.io/semtree/.

-

You may also want to visit the semtree website: https://brandmaier.de/semtree

Package vignettes (shipped with the package) contain documentation on how to use the package. Simply type this in R once you have loaded the package:

browseVignettes("semtree")
@@ -208,7 +207,7 @@

Dev status

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/news/index.html b/docs/news/index.html index a5a0ac0..602ef20 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -70,14 +70,18 @@

Changelog

- +
-
-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 3c5f762..b068673 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -1,5 +1,5 @@ pandoc: 3.1.1 -pkgdown: 2.0.7 +pkgdown: 2.0.6 pkgdown_sha: ~ articles: constraints: constraints.html @@ -7,5 +7,5 @@ articles: getting-started: getting-started.html score-based-tests: score-based-tests.html semforest-focus: semforest-focus.html -last_built: 2024-03-25T11:02Z +last_built: 2024-04-15T20:32Z diff --git a/docs/reference/biodiversity.html b/docs/reference/biodiversity.html index dc342e2..11f811e 100644 --- a/docs/reference/biodiversity.html +++ b/docs/reference/biodiversity.html @@ -106,7 +106,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/boruta.html b/docs/reference/boruta.html new file mode 100644 index 0000000..49aaa97 --- /dev/null +++ b/docs/reference/boruta.html @@ -0,0 +1,144 @@ + +BORUTA algorithm for SEM trees — boruta • semtree + + +
+
+ + + +
+
+ + +
+

BORUTA algorithm for SEM trees

+
+ +
+
boruta(
+  model,
+  data,
+  control = NULL,
+  predictors = NULL,
+  percentile_threshold = 100,
+  rounds = 1,
+  ...
+)
+
+ +
+

Arguments

+
model
+

A template model specification from OpenMx using +the mxModel function (or a lavaan model +using the lavaan function with option fit=FALSE). +Model must be syntactically correct within the framework chosen, and +converge to a solution.

+ + +
data
+

Data.frame used in the model creation using +mxModel or lavaan are input here. Order +of modeled variables and predictors is not important when providing a +dataset to semtree.

+ + +
control
+

semtree model specifications from +semtree.control are input here. Any changes from the default +setting can be specified here.

+ + +
percentile_threshold
+

Numeric.

+ + +
rounds
+

Numeric. Number of rounds of the BORUTA algorithm.

+ +
+ +
+ +
+ + +
+ + + + + + + + diff --git a/docs/reference/coef.semtree.html b/docs/reference/coef.semtree.html index 932c9f3..23fa2ba 100644 --- a/docs/reference/coef.semtree.html +++ b/docs/reference/coef.semtree.html @@ -103,7 +103,7 @@

Arguments

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/computePval_maxLR.html b/docs/reference/computePval_maxLR.html index 98e1109..a287623 100644 --- a/docs/reference/computePval_maxLR.html +++ b/docs/reference/computePval_maxLR.html @@ -101,7 +101,7 @@

Arguments

from

numeric from interval (0, 1) specifying start of trimmed -sample period. With the default +sample period. With the default from = 0.15 the first and last 15 percent of observations are trimmed. This is only needed for continuous covariates.

@@ -112,7 +112,7 @@

Arguments

nrep
-

numeric. Number of replications used for simulating from the asymptotic +

numeric. Number of replications used for simulating from the asymptotic distribution (passed to efpFunctional). Only needed for ordinal covariates.

@@ -140,7 +140,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/diversityMatrix.html b/docs/reference/diversityMatrix.html index 87d80ae..5b6a210 100644 --- a/docs/reference/diversityMatrix.html +++ b/docs/reference/diversityMatrix.html @@ -105,7 +105,7 @@

Arguments

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/evaluate.html b/docs/reference/evaluate.html index bfb8cca..9f24fa1 100644 --- a/docs/reference/evaluate.html +++ b/docs/reference/evaluate.html @@ -126,7 +126,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/evaluateDataLikelihood.html b/docs/reference/evaluateDataLikelihood.html index b4acd2c..12dc6fa 100644 --- a/docs/reference/evaluateDataLikelihood.html +++ b/docs/reference/evaluateDataLikelihood.html @@ -130,7 +130,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/evaluateTree.html b/docs/reference/evaluateTree.html index 6ff1b93..e161d5f 100644 --- a/docs/reference/evaluateTree.html +++ b/docs/reference/evaluateTree.html @@ -147,7 +147,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/findOtherSplits.html b/docs/reference/findOtherSplits.html index 23de1d1..0a96e01 100644 --- a/docs/reference/findOtherSplits.html +++ b/docs/reference/findOtherSplits.html @@ -127,7 +127,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/fitSubmodels.html b/docs/reference/fitSubmodels.html index 2a45b5f..baa33df 100644 --- a/docs/reference/fitSubmodels.html +++ b/docs/reference/fitSubmodels.html @@ -125,7 +125,7 @@

Arguments

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/getDepth.html b/docs/reference/getDepth.html index 1e8fd34..d8f49f1 100644 --- a/docs/reference/getDepth.html +++ b/docs/reference/getDepth.html @@ -107,7 +107,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/getHeight.html b/docs/reference/getHeight.html index 4e4abd2..4164647 100644 --- a/docs/reference/getHeight.html +++ b/docs/reference/getHeight.html @@ -109,7 +109,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/getLeafs.html b/docs/reference/getLeafs.html index 3d86539..05ffd09 100644 --- a/docs/reference/getLeafs.html +++ b/docs/reference/getLeafs.html @@ -117,7 +117,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/getNodeById.html b/docs/reference/getNodeById.html index 6a659fb..9fc062e 100644 --- a/docs/reference/getNodeById.html +++ b/docs/reference/getNodeById.html @@ -111,7 +111,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/getNumNodes.html b/docs/reference/getNumNodes.html index 6e406d6..2caa285 100644 --- a/docs/reference/getNumNodes.html +++ b/docs/reference/getNumNodes.html @@ -107,7 +107,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/getParDiffForest.html b/docs/reference/getParDiffForest.html index 8275196..6c46131 100644 --- a/docs/reference/getParDiffForest.html +++ b/docs/reference/getParDiffForest.html @@ -127,7 +127,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/getParDiffTree.html b/docs/reference/getParDiffTree.html index daebfc3..2554209 100644 --- a/docs/reference/getParDiffTree.html +++ b/docs/reference/getParDiffTree.html @@ -126,7 +126,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/getTerminalNodes.html b/docs/reference/getTerminalNodes.html index 48e9230..826922e 100644 --- a/docs/reference/getTerminalNodes.html +++ b/docs/reference/getTerminalNodes.html @@ -107,7 +107,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/index.html b/docs/reference/index.html index 8abc0c4..f4d6953 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -76,6 +76,10 @@

All functions biodiversity()

Quantify bio diversity of a SEM Forest

+ +

boruta()

+ +

BORUTA algorithm for SEM trees

coef(<semtree>)

@@ -209,18 +213,22 @@

All functions se()

SEMtrees Parameter Estimates Standard Error Table

- -

semforest.control()

- -

SEM Forest Control Object

semforest()

Create a SEM Forest

+ +

semforest.control()

+ +

SEM Forest Control Object

.SCALE_METRIC

SEM Tree Package

+ +

semtree()

+ +

SEM Tree: Recursive Partitioning for Structural Equation Models

semtree.constraints()

@@ -229,10 +237,6 @@

All functions semtree.control()

SEM Tree Control Object

- -

semtree()

- -

SEM Tree: Recursive Partitioning for Structural Equation Models

strip()

@@ -266,7 +270,7 @@

All functions
-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/isLeaf.html b/docs/reference/isLeaf.html index 69d0642..1704863 100644 --- a/docs/reference/isLeaf.html +++ b/docs/reference/isLeaf.html @@ -107,7 +107,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/kl.html b/docs/reference/kl.html index 963587f..ec87c7b 100644 --- a/docs/reference/kl.html +++ b/docs/reference/kl.html @@ -111,7 +111,7 @@

Arguments

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/lgcm.html b/docs/reference/lgcm.html index 1b75505..582e91f 100644 --- a/docs/reference/lgcm.html +++ b/docs/reference/lgcm.html @@ -98,7 +98,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/merge.semforest.html b/docs/reference/merge.semforest.html index f982d72..c0b76d5 100644 --- a/docs/reference/merge.semforest.html +++ b/docs/reference/merge.semforest.html @@ -120,7 +120,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/modelEstimates.html b/docs/reference/modelEstimates.html index 1aeded2..22c378e 100644 --- a/docs/reference/modelEstimates.html +++ b/docs/reference/modelEstimates.html @@ -111,7 +111,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/outliers.html b/docs/reference/outliers.html index ea6b549..7b203e5 100644 --- a/docs/reference/outliers.html +++ b/docs/reference/outliers.html @@ -111,7 +111,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/parameters.html b/docs/reference/parameters.html index a55d011..351eac2 100644 --- a/docs/reference/parameters.html +++ b/docs/reference/parameters.html @@ -133,7 +133,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/partialDependence.html b/docs/reference/partialDependence.html index 55a7b14..0c6c4de 100644 --- a/docs/reference/partialDependence.html +++ b/docs/reference/partialDependence.html @@ -121,7 +121,7 @@

Arguments

mc

Integer. If mc is not NULL, the function will sample -mc number of rows from data with replacement, to estimate +mc number of rows from data with replacement, to estimate marginal dependency using Monte Carlo integration. This is less computationally expensive.

@@ -152,7 +152,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/partialDependence_data.html b/docs/reference/partialDependence_data.html index f334dcd..84b24b0 100644 --- a/docs/reference/partialDependence_data.html +++ b/docs/reference/partialDependence_data.html @@ -143,7 +143,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/partialDependence_growth.html b/docs/reference/partialDependence_growth.html index 13e2c2b..2ff2602 100644 --- a/docs/reference/partialDependence_growth.html +++ b/docs/reference/partialDependence_growth.html @@ -123,7 +123,7 @@

Arguments

mc

Integer. If mc is not NULL, the function will sample -mc number of rows from data with replacement, to estimate +mc number of rows from data with replacement, to estimate marginal dependency using Monte Carlo integration. This is less computationally expensive.

@@ -166,7 +166,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/plotParDiffForest.html b/docs/reference/plotParDiffForest.html index 85c0191..bfeda12 100644 --- a/docs/reference/plotParDiffForest.html +++ b/docs/reference/plotParDiffForest.html @@ -137,7 +137,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/plotParDiffTree.html b/docs/reference/plotParDiffTree.html index 5485373..ad13d74 100644 --- a/docs/reference/plotParDiffTree.html +++ b/docs/reference/plotParDiffTree.html @@ -137,7 +137,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/plotTreeStructure.html b/docs/reference/plotTreeStructure.html index c4b7ba6..e567f38 100644 --- a/docs/reference/plotTreeStructure.html +++ b/docs/reference/plotTreeStructure.html @@ -118,7 +118,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/predict.semforest.html b/docs/reference/predict.semforest.html index 500da79..75bd082 100644 --- a/docs/reference/predict.semforest.html +++ b/docs/reference/predict.semforest.html @@ -121,7 +121,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/proximity.html b/docs/reference/proximity.html index 5bb7720..3ebf7a4 100644 --- a/docs/reference/proximity.html +++ b/docs/reference/proximity.html @@ -147,7 +147,7 @@

Examples

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/prune.html b/docs/reference/prune.html index 38efb56..b260d99 100644 --- a/docs/reference/prune.html +++ b/docs/reference/prune.html @@ -133,7 +133,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/se.html b/docs/reference/se.html index 3b8e3ad..f2bd3bb 100644 --- a/docs/reference/se.html +++ b/docs/reference/se.html @@ -133,7 +133,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/semforest.control.html b/docs/reference/semforest.control.html index 267bdb8..434c854 100644 --- a/docs/reference/semforest.control.html +++ b/docs/reference/semforest.control.html @@ -131,7 +131,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/semforest.html b/docs/reference/semforest.html index 7a3862f..d392d0a 100644 --- a/docs/reference/semforest.html +++ b/docs/reference/semforest.html @@ -149,7 +149,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/semtree-package.html b/docs/reference/semtree-package.html index 7e87eb4..76faa80 100644 --- a/docs/reference/semtree-package.html +++ b/docs/reference/semtree-package.html @@ -95,7 +95,7 @@

Format

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/semtree.constraints.html b/docs/reference/semtree.constraints.html index 5e47242..4a16649 100644 --- a/docs/reference/semtree.constraints.html +++ b/docs/reference/semtree.constraints.html @@ -138,7 +138,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/semtree.control.html b/docs/reference/semtree.control.html index c92a2d7..6df300c 100644 --- a/docs/reference/semtree.control.html +++ b/docs/reference/semtree.control.html @@ -104,7 +104,7 @@

SEM Tree Control Object

semtree.control(
-  method = "naive",
+  method = c("naive", "score", "fair", "fair3"),
   min.N = 20,
   max.depth = NA,
   alpha = 0.05,
@@ -334,7 +334,7 @@ 

Examples

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/semtree.html b/docs/reference/semtree.html index 2c8ba28..d773752 100644 --- a/docs/reference/semtree.html +++ b/docs/reference/semtree.html @@ -206,7 +206,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/strip.html b/docs/reference/strip.html index 636d241..3fdd227 100644 --- a/docs/reference/strip.html +++ b/docs/reference/strip.html @@ -133,7 +133,7 @@

Examples

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/subforest.html b/docs/reference/subforest.html index 40b6021..1a56b3c 100644 --- a/docs/reference/subforest.html +++ b/docs/reference/subforest.html @@ -124,7 +124,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/subtree.html b/docs/reference/subtree.html index 93e7052..a7c7a16 100644 --- a/docs/reference/subtree.html +++ b/docs/reference/subtree.html @@ -139,7 +139,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/toTable.html b/docs/reference/toTable.html index 5623eb2..12f3f0a 100644 --- a/docs/reference/toTable.html +++ b/docs/reference/toTable.html @@ -118,7 +118,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/reference/varimp.html b/docs/reference/varimp.html index b9aeb1d..55095aa 100644 --- a/docs/reference/varimp.html +++ b/docs/reference/varimp.html @@ -145,7 +145,7 @@

Author

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.6.

diff --git a/docs/sitemap.xml b/docs/sitemap.xml index f67421c..56460eb 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -3,6 +3,15 @@ /404.html + + /CONTRIBUTE.html + + + /CONTRIBUTORS.html + + + /LICENSE.html + /articles/constraints.html @@ -24,27 +33,21 @@ /authors.html - - /CONTRIBUTE.html - - - /CONTRIBUTORS.html - /cran_comments.html /index.html - - /LICENSE.html - /news/index.html /reference/biodiversity.html + + /reference/boruta.html + /reference/coef.semtree.html diff --git a/man/boruta.Rd b/man/boruta.Rd new file mode 100644 index 0000000..f0e8b85 --- /dev/null +++ b/man/boruta.Rd @@ -0,0 +1,39 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/boruta.R +\name{boruta} +\alias{boruta} +\title{BORUTA algorithm for SEM trees} +\usage{ +boruta( + model, + data, + control = NULL, + predictors = NULL, + percentile_threshold = 100, + rounds = 1, + ... +) +} +\arguments{ +\item{model}{A template model specification from \code{\link{OpenMx}} using +the \code{\link{mxModel}} function (or a \code{\link[lavaan]{lavaan}} model +using the \code{\link[lavaan]{lavaan}} function with option fit=FALSE). +Model must be syntactically correct within the framework chosen, and +converge to a solution.} + +\item{data}{Data.frame used in the model creation using +\code{\link{mxModel}} or \code{\link[lavaan]{lavaan}} are input here. Order +of modeled variables and predictors is not important when providing a +dataset to \code{semtree}.} + +\item{control}{\code{\link{semtree}} model specifications from +\code{\link{semtree.control}} are input here. Any changes from the default +setting can be specified here.} + +\item{percentile_threshold}{Numeric.} + +\item{rounds}{Numeric. Number of rounds of the BORUTA algorithm.} +} +\description{ +BORUTA algorithm for SEM trees +} diff --git a/man/semtree.control.Rd b/man/semtree.control.Rd index b908002..7ce8847 100644 --- a/man/semtree.control.Rd +++ b/man/semtree.control.Rd @@ -3,6 +3,7 @@ \name{semtree.control} \alias{semtree.control} \alias{print.semtree.control} +\alias{semtree_control} \title{SEM Tree Control Object} \usage{ semtree.control( diff --git a/tests/control.R b/tests/control.R index a247aa7..d7b4465 100644 --- a/tests/control.R +++ b/tests/control.R @@ -80,4 +80,15 @@ controlOptions <- semtree.control(method = "naive",max.depth = 0,min.N=NULL, tree <- semtree(model=lgcModel, data=lgcm, control = controlOptions) stopifnot(tree$control$min.N==50) -stopifnot(tree$control$min.bucket==25) \ No newline at end of file +stopifnot(tree$control$min.bucket==25) + + + +x<-semtree_control() +semtree:::check.semtree.control(x) + +x<-semtree_control(min.N=100) +semtree:::check.semtree.control(x) + +x<-semtree_control(min.N=100, min.bucket=10) +semtree:::check.semtree.control(x) diff --git a/tests/testthat/forced_splitl.R b/tests/testthat/forced_splitl.R new file mode 100644 index 0000000..b8cbdf7 --- /dev/null +++ b/tests/testthat/forced_splitl.R @@ -0,0 +1,28 @@ +library(lavaan) +library(semtree) +set.seed(1238) + +N <- 500 + +# simulate data +da <- data.frame(y = c(rnorm(N/2, mean = -1), rnorm(N/2, mean = 1)), + z = factor(rep(c(0,1),each=N/2)),k=rnorm(N),m=rnorm(N) ) + +m_lav <- ' +y ~~ y +y ~ 1 +' + +fit_lav <- lavaan(model = m_lav, data = da) + + +tree = semtree(model=fit_lav, data=da, + control = semtree_control(method="score"), + forced_splits=NULL) + + + +tree_forced_m = semtree(model=fit_lav, data=da, + control = semtree_control(method="score"), + forced_splits=c("m")) + diff --git a/tests/testthat/test-single-predictor.R b/tests/testthat/test-single-predictor.R new file mode 100644 index 0000000..788ae84 --- /dev/null +++ b/tests/testthat/test-single-predictor.R @@ -0,0 +1,41 @@ +library(lavaan) +library(semtree) +set.seed(1238) + +N <- 500 + +# simulate data with Cohen's d = 2 +da <- data.frame(y = c(rnorm(N/2, mean = -1), rnorm(N/2, mean = 1)), + z = rep(c(0,1),each=N/2) ) + +m_lav <- ' +y ~~ y +y ~ 1 +' + +m_lav_constrained <- ' +y ~~ y +y ~ c(a,a)*1 +' + +####Testing semtree with lavaan models #### +fit_lav <- lavaan(model = m_lav, data = Data) + +forest <- semforest(model=fit_lav, data=da, + control = semforest.control( + num.trees = 50, control=semtree_control(method="score"))) + +vim <- varimp(forest) + +plot(vim) + +zimp <- semtree:::aggregateVarimp(vim) + +fit_lav_multigroup <- lavaan(model = m_lav, data = da,group = "z") +fit_lav_multigroup2 <- lavaan(model = m_lav_constrained, data = da,group = "z") +lrt <- anova(fit_lav_multigroup,fit_lav_multigroup2) +chi2 <- lrt$`Chisq diff`[2] + + +cat("Importance: ", zimp,"\n") +cat("MG Chi^2: ",chi2,"\n") diff --git a/tests/testthat/test_boruta.R b/tests/testthat/test_boruta.R index 9fe9f3e..9e5d981 100644 --- a/tests/testthat/test_boruta.R +++ b/tests/testthat/test_boruta.R @@ -1,6 +1,6 @@ # skip long running tests on CRAN -skip_on_cran() +testthat::skip_on_cran() library("semtree") @@ -75,7 +75,7 @@ model <- lgcModel data <- lgcm control <- semforest_score_control() -vim_boruta <- boruta(lgcModel, lgcm) +vim_boruta <- boruta(lgcModel, lgcm,percentile_threshold = 1) print(vim_boruta)