networktree (version 0.2.1)

networktree: networktree: Partitioning of network models

Description

Computes a tree model with networks at the end of branches. Can use model-based recursive partitioning or conditional inference.

Wraps the mob() and ctree() functions from the partykit package.

Note: this package is in its early stages and the interface may change for future versions.

Usage

networktree(...)

# S3 method for default networktree(nodevars, splitvars, type = c("cor", "pcor", "glasso"), method = c("mob", "ctree"), model = "correlation", na.action = na.pass, weights = NULL, ...)

# S3 method for formula networktree(formula, data, type = c("cor", "pcor", "glasso"), method = c("mob", "ctree"), na.action = na.pass, model = "correlation", ...)

Arguments

...

additional arguments passed to mob_control (mob) or ctree_control (ctree)

nodevars

the variables with which to compute the network. Can be vector, matrix, or dataframe

splitvars

the variables with which to test split the network. Can be vector, matrix, or dataframe

type

the type of network to compute. Can be "cor", "pcor", or "glasso". Note that networks are always stored internally as correlation matrices, but will be auto-adjusted in plots etc. according to type

method

"mob" or "ctree"

model

can be any combination of c("correlation", "mean", "variance") splits are determined based on the specified characteristics

na.action

a function which indicates what should happen when the data contain missing values (NAs).

weights

weights

formula

A symbolic description of the model to be fit. This should either be of type y1 + y2 + y3 ~ x1 + x2 with node vectors y1, y2, and y3 or y ~ x1 + x2 with a matrix response y. x1 and x2 are used as partitioning variables.

data

a data frame containing the variables in the model

Examples

Run this code
# NOT RUN {
set.seed(1)
d <- data.frame(trend = 1:200, foo = runif(200, -1, 1))
d <- cbind(d, rbind(
  mvtnorm::rmvnorm(100, mean = c(0, 0, 0),
          sigma = matrix(c(1, 0.5, 0.5, 0.5, 1, 0.5, 0.5, 0.5, 1), ncol = 3)),
  mvtnorm::rmvnorm(100, mean = c(0, 0, 0),
          sigma = matrix(c(1, 0, 0.5, 0, 1, 0.5, 0.5, 0.5, 1), ncol = 3))
))
colnames(d)[3:5] <- paste0("y", 1:3)

## Now use the function
tree1 <- networktree(nodevars=d[,3:5], splitvars=d[,1:2])

## Formula interface
tree2 <- networktree(y1 + y2 + y3 ~ trend + foo, data=d)

# }
# NOT RUN {
## Conditional version
tree3 <- networktree(nodevars=d[,3:5], splitvars=d[,1:2], 
                     method="ctree")

## Change control arguments
tree4 <- networktree(nodevars=d[,3:5], splitvars=d[,1:2],
                     alpha=0.01)
# }

Run the code above in your browser using DataLab