View source: R/compute_vardepth.R
compute_vardepth | R Documentation |
Extract characteristics from the trees building process
compute_vardepth(dynforest_obj)
dynforest_obj |
dynforest_obj |
compute_vardepth function return a list with the following elements:
min_depth | A table providing for each feature in row: the average depth and the rank |
var_node_depth | A table providing for each tree in column the minimal depth for each feature in row. NA indicates that the feature was not used for the corresponding tree |
var_count | A table providing for each tree in column the number of times where the feature is used (in row). 0 value indicates that the feature was not used for the corresponding tree |
dynforest()
data(pbc2)
# Get Gaussian distribution for longitudinal predictors
pbc2$serBilir <- log(pbc2$serBilir)
pbc2$SGOT <- log(pbc2$SGOT)
pbc2$albumin <- log(pbc2$albumin)
pbc2$alkaline <- log(pbc2$alkaline)
# Sample 100 subjects
set.seed(1234)
id <- unique(pbc2$id)
id_sample <- sample(id, 100)
id_row <- which(pbc2$id%in%id_sample)
pbc2_train <- pbc2[id_row,]
timeData_train <- pbc2_train[,c("id","time",
"serBilir","SGOT",
"albumin","alkaline")]
# Create object with longitudinal association for each predictor
timeVarModel <- list(serBilir = list(fixed = serBilir ~ time,
random = ~ time),
SGOT = list(fixed = SGOT ~ time + I(time^2),
random = ~ time + I(time^2)),
albumin = list(fixed = albumin ~ time,
random = ~ time),
alkaline = list(fixed = alkaline ~ time,
random = ~ time))
# Build fixed data
fixedData_train <- unique(pbc2_train[,c("id","age","drug","sex")])
# Build outcome data
Y <- list(type = "surv",
Y = unique(pbc2_train[,c("id","years","event")]))
# Run dynforest function
res_dyn <- dynforest(timeData = timeData_train, fixedData = fixedData_train,
timeVar = "time", idVar = "id",
timeVarModel = timeVarModel, Y = Y,
ntree = 50, nodesize = 5, minsplit = 5,
cause = 2, ncores = 2, seed = 1234)
# Run compute_vardepth function
res_varDepth <- compute_vardepth(res_dyn)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.