Learn R Programming

partykit (version 1.2-22)

extree_data: Data Preprocessing for Extensible Trees.

Description

A routine for preprocessing data before an extensible tree can be grown by extree_fit.

Usage

extree_data(formula, data, subset, na.action = na.pass, weights, offset, 
            cluster, strata, scores = NULL, yx = c("none", "matrix"),
            ytype = c("vector", "data.frame", "matrix"), 
            nmax = c(yx = Inf, z = Inf), ...)

Value

An object of class extree_data.

Arguments

formula

a formula describing the model of the form y1 + y2 + ... ~ x1 + x2 + ... | z1 + z2 + ....

data

an optional data.frame containing the variables in the model.

subset

an optional vector specifying a subset of observations to be used in the fitting process.

na.action

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

weights

an optional vector of weights.

offset

an optional offset vector.

cluster

an optional factor describing clusters. The interpretation depends on the specific tree algorithm.

strata

an optional factor describing strata. The interpretation depends on the specific tree algorithm.

scores

an optional named list of numeric scores to be assigned to ordered factors in the z part of the formula.

yx

a character indicating if design matrices shall be computed.

ytype

a character indicating how response variables shall be stored.

nmax

a numeric vector of length two with the maximal number of bins in the response and x-part (first element) and the z part. Use Inf to switch-off binning.

...

additional arguments.

Details

This internal functionality will be the basis of implementations of other tree algorithms in future versions. Currently, only ctree relies on this function.

Examples

Run this code

  data("iris")

  ed <- extree_data(Species ~ Sepal.Width + Sepal.Length | Petal.Width + Petal.Length, 
                    data = iris, nmax = c("yx" = 25, "z" = 10), yx = "matrix")

  ### the model.frame
  mf <- model.frame(ed)
  all.equal(mf, iris[, names(mf)])

  ### binned y ~ x part
  model.frame(ed, yxonly = TRUE)

  ### binned Petal.Width
  ed[[4, type = "index"]]

  ### response
  ed$yx$y

  ### model matrix 
  ed$yx$x

Run the code above in your browser using DataLab