Running ‘invariance.R’ [22s/38s]
  Running ‘lavaan.R’ [45s/54s]
  Running ‘tree.R’ [12s/17s]
  Running ‘vim.R’ [232s/312s]
Running the tests in ‘tests/tree.R’ failed.
Complete output:
  > set.seed(789)
  > require("semtree")
  Loading required package: semtree
  Loading required package: OpenMx
  To take full advantage of multiple cores, use:
    mxOption(NULL, 'Number of Threads', parallel::detectCores()) #now
    Sys.setenv(OMP_NUM_THREADS=parallel::detectCores()) #before library(OpenMx)
  > data(lgcm)
  > 
  > lgcm$agegroup <- as.ordered(lgcm$agegroup)
  > lgcm$training <- as.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 CONTROL OPTIONS.
  > # TO OBTAIN BASIC/DEFAULT SMETREE OPTIONS, SIMPLY TPYE THE FOLLOWING:
  > 
  > controlOptions <- semtree.control(method = "naive")
  > controlOptions$alpha <- 0.05
  > 
  > # RUN TREE.
  > 
  > tree <- semtree(model=lgcModel, data=lgcm, control = controlOptions)
  [x] Tree construction finished!
  > 
  > # RERUN TREE WITH MODEL CONSTRAINTS.
  > # MODEL CONSTRAINTS CAN BE ADDED BY IDENTIFYING THE PARAMETERS TO BE
  > # CONSTRAINED IN EVERY NODE. ONLY UNCONSTRAINED PARAMETERS ARE THEN
  > # TESTED AT EACH NODE FOR GROUP DIFFERENCES. IN THIS EXAMPLE THE MODEL 
  > # RESIDUALS ARE CONSTRAINED OVER THE NODES.
  > 
  > constraints <- semtree.constraints(global.invariance = names(omxGetParameters(lgcModel))[1:5])
  > 
  > treeConstrained <- semtree(model=lgcModel, data=lgcm, control = controlOptions,
  +                            constraints=constraints)
  Global Constraints:
  residual1 residual2 residual3 residual4 residual5
  Freely Estimated Parameters:
  vari cov vars meani means
  [x] Tree construction finished!
  > 
  > # SEE PLOT.
  > # THE PLOT FUNCTION WILL SHOW ALL FREE PARAMETERS AT EACH TERMINAL NODE.
  > # THIS CAN CREATE UNREADABLE FIGURES FOR MODELS WITH MANY FREE PARAMETERS.
  > 
  > plot(tree)
  > 
  > summary(tree)
  SEMtree Summary
  Template model:  
  Total Sample Size:  400 
  Number of nodes:  3 
  Number of leaf nodes:  2 
  Free Parameters:  10  ( residual1 residual2 residual3 residual4 residual5 vari cov vars meani means )
  > 
  > summary(treeConstrained)
  SEMtree Summary
  Template model:  
  Total Sample Size:  400 
  Number of nodes:  3 
  Number of leaf nodes:  2 
  Free Parameters:  5  ( vari cov vars meani means )
  > 
  > print(tree)
  SEMtree with numbered nodes
   |-[1] agegroup >= 0.5 [N=400 LR=280.93, df=10]
   |   |-[2] TERMINAL [N=200]
   |   |-[3] TERMINAL [N=200]
  > 
  > parameters(tree)
                  2      3
  residual1   0.068  0.045
  residual2   0.049  0.059
  residual3   0.043  0.053
  residual4   0.055  0.051
  residual5   0.038  0.029
  vari        3.838  0.142
  cov        42.988  1.456
  vars      492.781 47.950
  meani       5.061  1.989
  means       0.360 -0.305
  > 
  > parameters(tree, leafs.only=FALSE)
                 1       2      3
  residual1  0.050   0.068  0.045
  residual2  0.059   0.049  0.059
  residual3  0.047   0.043  0.053
  residual4  0.052   0.055  0.051
  residual5  0.037   0.038  0.029
  vari      82.964   3.838  0.142
  cov       35.514  42.988  1.456
  vars      16.216 492.781 47.950
  meani      3.926   5.061  1.989
  means     -0.279   0.360 -0.305
  > 
  > treeSub <- subtree(tree, startNode=3)
  > 
  > if (!is.null(treeSub))
  + 	plot(treeSub)
  > 
  > toTable(tree)
  Error in apply(str.matrix, 2, function(x) { : 
    dim(X) must have a positive length
  Calls: toTable -> apply
  Execution halted