Skip to content

Commit

Permalink
updated news
Browse files Browse the repository at this point in the history
fixed test
  • Loading branch information
brandmaier committed Sep 30, 2024
1 parent c14c555 commit a177c55
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 96 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# semtree 0.9.21 (2024)

- added merge functions for varimp objects
- fixed error in to.table() which convert everything to strings
- fixed issue in OpenMx models with unnamed parameters in matrices

# semtree 0.9.20 (2024)

- added an error handler for score-based tests when the vcov matrix cannot be computed (e.g., models with Heywood cases)
Expand Down
207 changes: 111 additions & 96 deletions tests/testthat/test-forest-focus.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,100 +2,115 @@
skip_on_cran()

if (require("future")) {

require("semtree")
data(lgcm)


future::plan(multisession, workers=5)

lgcm$agegroup <- ordered(lgcm$agegroup)
lgcm$training <- factor(lgcm$training)
lgcm$noise <- as.numeric(lgcm$noise)

# LOAD IN OPENMX MODEL.
# A SIMPLE LINEAR GROWTH MODEL WITH 5 TIME POINTS FROM SIMULATED DATA

manifests <- names(lgcm)[1:5]
lgcModel <- mxModel("Linear Growth Curve Model Path Specification",
type="RAM",
manifestVars=manifests,
latentVars=c("intercept","slope"),
# residual variances
mxPath(
from=manifests,
arrows=2,
free=TRUE,
values = c(1, 1, 1, 1, 1),
labels=c("residual1","residual2","residual3","residual4","residual5")
),
# latent variances and covariance
mxPath(
from=c("intercept","slope"),
connect="unique.pairs",
arrows=2,
free=TRUE,
values=c(1, 1, 1),
labels=c("vari", "cov", "vars")
),
# intercept loadings
mxPath(
from="intercept",
to=manifests,
arrows=1,
free=FALSE,
values=c(1, 1, 1, 1, 1)
),
# slope loadings
mxPath(
from="slope",
to=manifests,
arrows=1,
free=FALSE,
values=c(0, 1, 2, 3, 4)
),
# manifest means
mxPath(
from="one",
to=manifests,
arrows=1,
free=FALSE,
values=c(0, 0, 0, 0, 0)
),
# latent means
mxPath(
from="one",
to=c("intercept", "slope"),
arrows=1,
free=TRUE,
values=c(1, 1),
labels=c("meani", "means")
),
mxData(lgcm,type="raw")
)

#tree <- semtree(model=lgcModel, data=lgcm)

#lgcModel=mxRun(lgcModel)

# TREE CONTROL OPTIONS.
# TO OBTAIN BASIC/DEFAULT SMETREE OPTIONS, SIMPLY TPYE THE FOLLOWING:

ctrl <- semtree.control(method = "score", verbose = TRUE)

# RUN TREE.

forest <- semforest(model=lgcModel, data=lgcm, control =
semforest.control(num.trees = 30, control=semtree.control(alpha=1,method="score")),
constraints=semtree.constraints(focus.parameter="meani"))

vim_naive <- varimp(forest)

vim <- varimp(forest, method = "permutationFocus")

#plot(vim)
#plot(vim_naive)

aggregate()

require("semtree")
data(lgcm)


future::plan(multisession, workers = 5)

lgcm$agegroup <- ordered(lgcm$agegroup)
lgcm$training <- factor(lgcm$training)
lgcm$noise <- as.numeric(lgcm$noise)

# LOAD IN OPENMX MODEL.
# A SIMPLE LINEAR GROWTH MODEL WITH 5 TIME POINTS FROM SIMULATED DATA

manifests <- names(lgcm)[1:5]
lgcModel <- mxModel(
"Linear Growth Curve Model Path Specification",
type = "RAM",
manifestVars = manifests,
latentVars = c("intercept", "slope"),
# residual variances
mxPath(
from = manifests,
arrows = 2,
free = TRUE,
values = c(1, 1, 1, 1, 1),
labels = c(
"residual1",
"residual2",
"residual3",
"residual4",
"residual5"
)
),
# latent variances and covariance
mxPath(
from = c("intercept", "slope"),
connect = "unique.pairs",
arrows = 2,
free = TRUE,
values = c(1, 1, 1),
labels = c("vari", "cov", "vars")
),
# intercept loadings
mxPath(
from = "intercept",
to = manifests,
arrows = 1,
free = FALSE,
values = c(1, 1, 1, 1, 1)
),
# slope loadings
mxPath(
from = "slope",
to = manifests,
arrows = 1,
free = FALSE,
values = c(0, 1, 2, 3, 4)
),
# manifest means
mxPath(
from = "one",
to = manifests,
arrows = 1,
free = FALSE,
values = c(0, 0, 0, 0, 0)
),
# latent means
mxPath(
from = "one",
to = c("intercept", "slope"),
arrows = 1,
free = TRUE,
values = c(1, 1),
labels = c("meani", "means")
),
mxData(lgcm, type = "raw")
)

#tree <- semtree(model=lgcModel, data=lgcm)

#lgcModel=mxRun(lgcModel)

# TREE CONTROL OPTIONS.
# TO OBTAIN BASIC/DEFAULT SMETREE OPTIONS, SIMPLY TPYE THE FOLLOWING:

ctrl <- semtree.control(method = "score", verbose = TRUE)

# RUN TREE.

forest <- semforest(
model = lgcModel,
data = lgcm,
control =
semforest.control(
num.trees = 30,
control = semtree.control(alpha =
1, method = "score")
),
constraints = semtree.constraints(focus.parameter =
"meani")
)

vim_naive <- varimp(forest)

vim <- varimp(forest, method = "permutationFocus")

#plot(vim)
#plot(vim_naive)



}

0 comments on commit a177c55

Please sign in to comment.