nodeapply {etree} | R Documentation |
Apply functions over nodes
Description
Returns a list of values obtained by applying a function to "etree"
or
"partynode"
objects.
Usage
nodeapply(obj, ids = 1, FUN = NULL, ...)
## S3 method for class 'partynode'
nodeapply(obj, ids = 1, FUN = NULL, ...)
## S3 method for class 'etree'
nodeapply(obj, ids = 1, FUN = NULL, by_node = TRUE, ...)
Arguments
obj |
Object of class |
ids |
Integer vector of node identifiers to apply over. |
FUN |
Function to be applied to nodes. By default, the node itself is returned. |
... |
Additional arguments. |
by_node |
Logical indicating whether FUN should be applied to subsets of
|
Details
The method for "partynode"
objects apply function FUN
to all
nodes with node identifiers in ids
. The method for "etree"
objects by default calls the nodeapply
method on the corresponding
node slot. If by_node
is FALSE
, it is applied to the
"etree"
object with root node ids
.
Value
A list of results whose length is given by length(ids)
.
Methods (by class)
-
partynode
: nodeapply() method for objects of class "partynode". -
etree
: nodeapply() method for objects of class "etree".
Examples
## Covariates
nobs <- 100
cov_num <- rnorm(nobs)
cov_nom <- factor(rbinom(nobs, size = 1, prob = 0.5))
cov_gph <- lapply(1:nobs, function(j) igraph::sample_gnp(100, 0.2))
cov_fun <- fda.usc::rproc2fdata(nobs, seq(0, 1, len = 100), sigma = 1)
cov_list <- list(cov_num, cov_nom, cov_gph, cov_fun)
## Response variable
resp_reg <- cov_num ^ 2
## Fit
etree_fit <- etree(response = resp_reg, covariates = cov_list)
## Get pvalues of inner nodes
tnodes <- nodeids(etree_fit, terminal = TRUE)
nodes <- 1:max(tnodes)
inodes <- nodes[-tnodes]
nodeapply(etree_fit, ids = inodes, FUN = function(n) n$info$pvalue)