Skip to content

Commit

Permalink
Merge pull request #11 from brandmaier/master
Browse files Browse the repository at this point in the history
Syncing
  • Loading branch information
manuelarnold authored Apr 27, 2021
2 parents 4603780 + 5acdf40 commit ab9796b
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 49 deletions.
41 changes: 41 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,44 @@

language: R
cache: packages
dist: focal
r:
- release
- devel
r_binary_packages:
- bitops
- sets
- digest
- rpart
- rpart.plot
- plotrix
- cluster
- stringr
- lavaan
- expm
- lavaan
- tidyr
- viridis
- ggplot2
- strucchange
- sandwich
- zoo
- crayon
- testthat
- Rcpp
- RcppEigen
- MASS
- Matrix
- StanHeaders
- mvtnorm
- xfun
- mime
- RcppParallel
- rmarkdown
- htmltools
- knitr
- rpf
- BH
- OpenMx


4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ License: GPL-3
Encoding: UTF-8
LazyLoad: yes
Version: 0.9.15
Date: 2020-10-24
RoxygenNote: 7.1.0
Date: 2021-04-26
RoxygenNote: 7.1.1
VignetteBuilder: knitr
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ readme:

build:
cd ..;\
R CMD build --with-keep.source $(PKGSRC)
R CMD build $(PKGSRC)

buildfast:
cd ..;\
Expand All @@ -29,6 +29,9 @@ install:
check: build
cd ..;\
R CMD check --as-cran $(PKGNAME)_$(PKGVERS).tar.gz

dockercheck:
docker run r-devel-local `R CMD check --as-cran ../$(PKGNAME)_$(PKGVERS).tar.gz`

clean:
cd ..;\
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export(toTable)
export(varimp)
export(varimpConvergencePlot)
import(OpenMx)
import(bitops)
import(rpart)
importFrom(bitops,bitAnd)
importFrom(grDevices,heat.colors)
importFrom(graphics,barplot)
importFrom(graphics,hist)
Expand Down
18 changes: 13 additions & 5 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
# semtree 0.9.14
# semtree 0.9.15 (2021)

- roll-out of score-based tests - use method "score" to enable
- use of method "cross-validation" is now deprecated and discouraged
- added variable importance for focus parameters
- added new vignettes
- fixed compatibility with new OpenMx version

# semtree 0.9.14 (2020)

- added requirement rpart.plot > 3.0.6 to avoid error w.r.t. to missing round.int
- Manuel Arnold joined the team to work on a score-test implementation
- fixed behavior of min.N in semtree.control()
- semtree captions uses signif for truncating decision thresholds to three significant digits
- fixed class type checks to be compatible with upcoming R 4.0.0

# semtree 0.9.13
# semtree 0.9.13 (2018)

- bugfix in invariance testing
- fix to remove warning from rpart plot (version 3.0.0 and above)

# semtree 0.9.12
# semtree 0.9.12 (2018)

- bugfix in split evaluation procedure for cases where variables are named 'c', which crashed semtree
- bugfix in varimpConvergencePlot: na.omit command logic was inverted

# semtree 0.9.11
# semtree 0.9.11 (2017)

- semforests support for lavaan models including variable importance and partial dependence
- crossvalidated likelihood supported with lavaan
- plots of semtrees show correct #df when using focus parameters
- added diversity functions

# semtree 0.9.10
# semtree 0.9.10 (2017)

- added NEWS.md file
- bugfix to partial dependence on variables of type factor
Expand Down
28 changes: 16 additions & 12 deletions R/computePval_maxLR.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
#' Wrapper function for computing the maxLR corrected p value
#' from strucchange
#'
#' @param maxLR: maximum of the LR test statistics
#' @param q: number of free SEM parameters / degrees of freedom
#' @param covariate: covariate under evaluation. This is important to get the level of
# measurement from the covariate and the bin size for ordinal and
# categorical covariates.
#' @param from, to: numeric from interval (0, 1) specifying start and end of trimmed
# sample period. By default, to is 1 - from, i.e., with the default
# from = 0.15 the first and last 15 percent of observations are
# trimmed. This only needed for continuous covariates.
#' @param nrep: numeric. Number of replications used for simulating from the asymptotic
# distribution (passed to efpFunctional). Only needed for ordinal
# covariates.
#' @param maxLR maximum of the LR test statistics
#' @param q number of free SEM parameters / degrees of freedom
#' @param covariate covariate under evaluation. This is important to get the level of
#' measurement from the covariate and the bin size for ordinal and
#' categorical covariates.
#' @param from numeric from interval (0, 1) specifying start of trimmed
#' 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.
#' @param to numeric from interval (0, 1) specifying end of trimmed
#' sample period. By default, to is 1.
#' @param nrep numeric. Number of replications used for simulating from the asymptotic
#' distribution (passed to efpFunctional). Only needed for ordinal
#' covariates.
#'
#
#' @author Manuel Arnold
#' @return Numeric. p value for maximally selected LR statistic

Expand Down
3 changes: 2 additions & 1 deletion R/fitSubmodels.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#' @param subset1 Dataset for the first group model
#' @param subset2 Dataset for the second group model
#' @param control a \code{semtree.control} object
#
#' @param invariance fit models with invariant parameters if given. NULL otherwise (default).
#' @param return.models boolean. Return the fitted models
#' returns NA if fit fails
#'
#' @export
Expand Down
2 changes: 1 addition & 1 deletion R/semtree-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' @importFrom stats as.dist cmdscale coef cor cov logLik median pchisq qnorm runif var dist rnorm
#' @importFrom graphics barplot legend lines pairs par plot strwidth text hist
#' @import OpenMx
#' @import bitops
#' @importFrom bitops bitAnd
#' @import rpart
NULL

Expand Down
3 changes: 2 additions & 1 deletion R/vcov_lavaan.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
setMethod(f = "vcov", signature = signature(object = "lavaan"),
definition = function(object, ...) {
N <- NA # this is to skip CRANs check error
if (object@Model@eq.constraints) {
K <- eval(parse(text = "lavaan:::lav_constraints_R2K(object@Model)"))
res <- solve(t(K) %*% lavInspect(object, what = "information.expected") %*% K * N)
res <- solve(t(K) %*% lavaan::lavInspect(object, what = "information.expected") %*% K * N)
} else {
res <- object@vcov$vcov
}
Expand Down
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ knitr::opts_chunk$set(

[![DOI](http://zenodo.org/badge/76649538.svg)](https://zenodo.org/badge/latestdoi/76649538)
[![cran version](http://www.r-pkg.org/badges/version/semtree)](https://cran.r-project.org/package=semtree)
[![rstudio mirror downloads](http://cranlogs.r-pkg.org/badges/semtree)](https://github.com/metacran/cranlogs.app)
[![rstudio mirror downloads](http://cranlogs.r-pkg.org/badges/semtree)](https://github.com/r-hub/cranlogs.app)
[![Build Status](https://travis-ci.com/brandmaier/semtree.svg?branch=master)](https://travis-ci.com/brandmaier/semtree)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

Expand Down Expand Up @@ -39,7 +39,7 @@ devtools::install_github("brandmaier/semtree",force=TRUE, build_opts = c())

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

You may also want to visit the semtree website: http://brandmaier.de/semtree
You may also want to visit the semtree website: [https://brandmaier.de/semtree](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:

Expand Down
20 changes: 15 additions & 5 deletions man/computePval_maxLR.Rd

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

6 changes: 5 additions & 1 deletion man/fitSubmodels.Rd

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

2 changes: 1 addition & 1 deletion tests/vim.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ lgcModel <- mxModel("Linear Growth Curve Model Path Specification",
)


fr <- semforest(lgcModel, lgcm,control = semforest.control(num.trees = 10))
fr <- semforest(lgcModel, lgcm,control = semforest.control(num.trees = 3))


vimp <- varimp(fr)
Expand Down
2 changes: 1 addition & 1 deletion vignettes/constraints.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ author: "Andreas M. Brandmaier"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{constraints}
%\VignetteIndexEntry{Constraints in semtree}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand Down
4 changes: 2 additions & 2 deletions vignettes/forests.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ summary(result)

## Forest

Create a forest control object that stores all tuning parameters of the forest
Create a forest control object that stores all tuning parameters of the forest. Note that we use only 5 trees for demo purposes. Please increase the number in real applications.

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

Expand Down
2 changes: 1 addition & 1 deletion vignettes/getting-started.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Getting Started with the semtree package"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{getting-started}
%\VignetteIndexEntry{Getting Started with the semtree package}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand Down
13 changes: 10 additions & 3 deletions vignettes/score-based-tests.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ author: "Andreas M. Brandmaier"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{score-based-tests}
%\VignetteIndexEntry{Score-based Tests}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand Down Expand Up @@ -63,8 +63,15 @@ Use score-based tests to create the tree. Use Bonferroni-correction to adjust fo

```{r}
library(semtree)
ctrl = semtree.control(method="score", bonferroni = TRUE)
tree = semtree(model=result, data=tree.data, control=ctrl)
ctrl = semtree.control(
method="score",
bonferroni = TRUE)
```

```{r}
tree = semtree( model = result,
data = tree.data,
control=ctrl)
```

Now let us plot the tree.
Expand Down
13 changes: 4 additions & 9 deletions vignettes/semforest-focus.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ author: "Andreas M. Brandmaier"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{semtree-focus}
%\VignetteIndexEntry{Focus parameters in SEM forests}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
Expand Down Expand Up @@ -87,7 +87,7 @@ Now, we are repeating the same analysis in a forest.
forest <- semforest(model.biv, data=df.biv,
constraints = list(focus.parameters=fp),
control=semforest.control(num.trees=5))
control=semforest.control(num.trees=5, control=semtree.control(method="score")))
```

By default, we see that individual trees are fully grown (without a p-value threshold). The first split is according to `grp2` because it best explains the group differences. Subsequent splits are according to `grp1` even though the chi2 values are close to zero. They only appear because there is no p-value-based stopping criterion.
Expand All @@ -96,16 +96,11 @@ By default, we see that individual trees are fully grown (without a p-value thre
plot(forest$forest[[1]])
```

Now, let us compare the new permutation scheme
Now, let us investigate the permutation-based variable importance:

```{r}
vim <- varimp(forest, method="permutationFocus")
vim.old <- varimp(forest, method="permutation")
plot(vim.old, main = "Standard")
plot(vim, main="Focus correction")
plot(vim, main="Variable Importance")
```

0 comments on commit ab9796b

Please sign in to comment.