Skip to content

Commit

Permalink
Merge pull request #4 from brandmaier/master
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
manuelarnold authored Apr 21, 2020
2 parents b4b936a + 24a5870 commit 2c74790
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ importFrom("strucchange", "catL2BB", "maxBB", "meanL2BB", "ordL2BB", "ordwmax",
importFrom("zoo", "zoo")
importFrom("utils","toLatex")
importFrom("lavaan", "lavScores", "nobs", "vcov")

importFrom("stats", "as.formula", "predict")

#
# S3 methods
Expand Down
14 changes: 14 additions & 0 deletions R/growTree.R
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,20 @@ growTree <- function(model=NULL, mydata=NULL,
}
##########################################################

# build a model for missing data
if (control$missing == "ctree") {
ui_warn("Missing data treatment with ctree is not yet implemented.")
#temp = mydata[!is.na(mydata[,result$name.max]),]
#node$missing.model = party::ctree(
# data = temp,
# formula = as.formula(paste0(result$name.max,"~.")))
} else if (control$missing == "rpart") {
temp = mydata[!is.na(mydata[,result$name.max]),]
node$missing.model = rpart::rpart(
data = temp,
formula = as.formula(paste0(result$name.max,"~.")))
}

# recursively continue splitting
# result1 - RHS; result2 - LHS
result2 <- growTree( model, sub2, control, invariance, meta, edgelabel=0, depth=depth+1, constraints)
Expand Down
4 changes: 3 additions & 1 deletion R/semtree.control.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function(method="naive", min.N = 20, max.depth=NA, alpha=.05, alpha.invariance=N
mtry=NA, report.level=0, exclude.code=NA,
score.tests = list(nominal = 'LMuo', ordinal = 'maxLMo', metric = 'CvM'),
information.matrix = "info", scaled_scores = TRUE, linear = TRUE,
min.bucket=10, naive.bonferroni.type=0)
min.bucket=10, naive.bonferroni.type=0, missing = 'ignore')
{
options <- list()
# verbose output during generation of SEMTree
Expand Down Expand Up @@ -58,6 +58,8 @@ function(method="naive", min.N = 20, max.depth=NA, alpha=.05, alpha.invariance=N
options$report.level <- report.level
# type of counting the number of tests (0=all splits, 1=# of variables)
options$naive.bonferroni.type <- naive.bonferroni.type
# missing data treatment
options$missing <- missing

class(options) <- "semtree.control"

Expand Down
13 changes: 12 additions & 1 deletion R/traverse.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ value <- tryCatch({
row[[tree$rule$name]]
},error=function(cond){ message("ERROR! Incomplete dataset!"); stop(); return(NA);})

if (is.na(value)) return(tree$node_id);
if (is.na(value)) {

if (is.null(tree$missing.model)) {
return(tree$node_id);
} else {
#browser()
value = predict(tree$missing.model, newdata=row)
}



}

log.val <- NA

Expand Down
4 changes: 3 additions & 1 deletion man/semtree.control.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
custom.stopping.rule=NA, mtry=NA, report.level=0, exclude.code=NA,
score.tests = list(nominal = "LMuo", ordinal = "maxLMo", metric = "CvM"),
information.matrix = "info", scaled_scores = TRUE, linear = TRUE,
min.bucket = 10, naive.bonferroni.type=0)
min.bucket = 10, naive.bonferroni.type=0, missing = 'ignore')
}
% print.semtree.control(x, ...)
%- maybe also 'usage' for other objects documented here.
Expand Down Expand Up @@ -83,6 +83,8 @@
\item{min.bucket}{Minimum bucket size to continue splitting
}
\item{naive.bonferroni.type}{Default: 0. When set to zero, bonferroni correction for the naive test counts the number of dichotomous tests. When set to one, bonferroni correction counts the number of variables tested. }

\item{missing}{Missing value treatment. Default is ignore}
}
\value{
A control object containing a list of the above parameters.
Expand Down
11 changes: 8 additions & 3 deletions vignettes/score-based-tests.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ Load affect dataset from the `psychTools` package. These are data from two studi
library(psychTools)
data(affect)
knitr::kable(head(affect))
affect$Film <- as.ordered(affect$Film)
tree.data <- affect[,c("state1","Film","neur","ext")]
knitr::kable(head(tree.data))
```

## Create simple model of state anxiety
Expand All @@ -41,7 +46,7 @@ manifestVars = manifests,
latentVars = latents,
mxPath(from="one",to=manifests, free=c(TRUE), value=c(1.0) , arrows=1, label=c("mu") ),
mxPath(from=manifests,to=manifests, free=c(TRUE), value=c(1.0) , arrows=2, label=c("sigma2") ),
mxData(affect, type = "raw")
mxData(tree.data, type = "raw")
);
result <- mxRun(model)
Expand All @@ -55,7 +60,7 @@ Use score-based tests to create the tree.
```{r}
library(semtree)
ctrl = semtree.control(method="score")
#tree = semtree(model=result, data=affect, control=ctrl)
#tree = semtree(model=result, data=tree.data, control=ctrl)
```

Plot the tree
Expand Down

0 comments on commit 2c74790

Please sign in to comment.