glmtree: Logistic regression tree by...

Description Usage Arguments Value Author(s) Examples

View source: R/glmtree.R

Description

This function produces a logistic regression tree: a decision tree with logistic regressions at its leaves.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
glmtree(
  x,
  y,
  K = 10,
  iterations = 200,
  test = FALSE,
  validation = FALSE,
  proportions = c(0.3),
  criterion = "bic",
  ctree_controls = partykit::ctree_control(alpha = 0.1, minbucket = 100, maxdepth = 5)
)

Arguments

x

The features to use for prediction.

y

The binary / boolean labels to predict.

K

The number of segments to start with (maximum number of segments there'll be in the end).

iterations

The number of iterations to do in the SEM protocole (default: 200).

test

Boolean : True if the algorithm should use predictors to construct a test set on which to calculate the provided criterion using the best discretization scheme (chosen thanks to the provided criterion on either the test set (if true) or the training set (otherwise)) (default: TRUE).

validation

Boolean : True if the algorithm should use predictors to construct a validation set on which to search for the best discretization scheme using the provided criterion (default: TRUE).

proportions

The list of the proportions wanted for test and validation set. Not used when both test and validation are false. Only the first is used when there is only one of either test or validation that is set to TRUE. Produces an error when the sum is greater to one. Default: list(0.2,0.2) so that the training set has 0.6 of the input observations.

criterion

The criterion ('gini','aic','bic') to use to choose the best discretization scheme among the generated ones (default: 'gini'). Nota Bene: it is best to use 'gini' only when test is set to TRUE and 'aic' or 'bic' when it is not. When using 'aic' or 'bic' with a test set, the likelihood is returned as there is no need to penalize for generalization purposes.

ctree_controls

The controls to use for 'partykit::ctree'.

Value

An S4 object of class 'glmtree' that contains the parameters used to search for the logistic regression tree, the best tree it found, and its performance.

Author(s)

Adrien Ehrhardt

Examples

1
2
data <- generateData(n = 100, scenario = "no tree")
glmtree(x = data[, c("x1", "x2")], y = data$y, K = 5, iterations = 80, criterion = "aic")

Example output

The aic criterion for iteration 1 is 0
The aic criterion for iteration 2 is -112.241501973665
The aic criterion for iteration 3 is -112.241501973665
The aic criterion for iteration 4 is -112.241501973665
The aic criterion for iteration 5 is -112.241501973665
The aic criterion for iteration 6 is -112.241501973665
The aic criterion for iteration 7 is -112.241501973665
The aic criterion for iteration 8 is -112.241501973665
The aic criterion for iteration 9 is -112.241501973665
The aic criterion for iteration 10 is -112.241501973665
The aic criterion for iteration 11 is -112.241501973665
The aic criterion for iteration 12 is -112.241501973665
The aic criterion for iteration 13 is -112.241501973665
The aic criterion for iteration 14 is -112.241501973665
The aic criterion for iteration 15 is -112.241501973665
The aic criterion for iteration 16 is -112.241501973665
The aic criterion for iteration 17 is -112.241501973665
The aic criterion for iteration 18 is -112.241501973665
The aic criterion for iteration 19 is -112.241501973665
The aic criterion for iteration 20 is -112.241501973665
The aic criterion for iteration 21 is -112.241501973665
The aic criterion for iteration 22 is -112.241501973665
The aic criterion for iteration 23 is -112.241501973665
The aic criterion for iteration 24 is -112.241501973665
The aic criterion for iteration 25 is -112.241501973665
The aic criterion for iteration 26 is -112.241501973665
The aic criterion for iteration 27 is -112.241501973665
The aic criterion for iteration 28 is -112.241501973665
The aic criterion for iteration 29 is -112.241501973665
The aic criterion for iteration 30 is -112.241501973665
The aic criterion for iteration 31 is -112.241501973665
The aic criterion for iteration 32 is -112.241501973665
The aic criterion for iteration 33 is -112.241501973665
The aic criterion for iteration 34 is -112.241501973665
The aic criterion for iteration 35 is -112.241501973665
The aic criterion for iteration 36 is -112.241501973665
The aic criterion for iteration 37 is -112.241501973665
The aic criterion for iteration 38 is -112.241501973665
The aic criterion for iteration 39 is -112.241501973665
The aic criterion for iteration 40 is -112.241501973665
The aic criterion for iteration 41 is -112.241501973665
The aic criterion for iteration 42 is -112.241501973665
The aic criterion for iteration 43 is -112.241501973665
The aic criterion for iteration 44 is -112.241501973665
The aic criterion for iteration 45 is -112.241501973665
The aic criterion for iteration 46 is -112.241501973665
The aic criterion for iteration 47 is -112.241501973665
The aic criterion for iteration 48 is -112.241501973665
The aic criterion for iteration 49 is -112.241501973665
The aic criterion for iteration 50 is -112.241501973665
The aic criterion for iteration 51 is -112.241501973665
The aic criterion for iteration 52 is -112.241501973665
The aic criterion for iteration 53 is -112.241501973665
The aic criterion for iteration 54 is -112.241501973665
The aic criterion for iteration 55 is -112.241501973665
The aic criterion for iteration 56 is -112.241501973665
The aic criterion for iteration 57 is -112.241501973665
The aic criterion for iteration 58 is -112.241501973665
The aic criterion for iteration 59 is -112.241501973665
The aic criterion for iteration 60 is -112.241501973665
The aic criterion for iteration 61 is -112.241501973665
The aic criterion for iteration 62 is -112.241501973665
The aic criterion for iteration 63 is -112.241501973665
The aic criterion for iteration 64 is -112.241501973665
The aic criterion for iteration 65 is -112.241501973665
The aic criterion for iteration 66 is -112.241501973665
The aic criterion for iteration 67 is -112.241501973665
The aic criterion for iteration 68 is -112.241501973665
The aic criterion for iteration 69 is -112.241501973665
The aic criterion for iteration 70 is -112.241501973665
The aic criterion for iteration 71 is -112.241501973665
The aic criterion for iteration 72 is -112.241501973665
The aic criterion for iteration 73 is -112.241501973665
The aic criterion for iteration 74 is -112.241501973665
The aic criterion for iteration 75 is -112.241501973665
The aic criterion for iteration 76 is -112.241501973665
The aic criterion for iteration 77 is -112.241501973665
The aic criterion for iteration 78 is -112.241501973665
The aic criterion for iteration 79 is -112.241501973665
The aic criterion for iteration 80 is -112.241501973665
An object of class "glmtree"
Slot "parameters":
$K
[1] 5

$iterations
[1] 80

$test
[1] FALSE

$validation
[1] FALSE

$proportions
[1] 0.3

$criterion
[1] "aic"

$ctree_controls
$ctree_controls$criterion
[1] "p.value"

$ctree_controls$logmincriterion
[1] -0.1053605

$ctree_controls$minsplit
[1] 20

$ctree_controls$minbucket
[1] 100

$ctree_controls$minprob
[1] 0.01

$ctree_controls$stump
[1] FALSE

$ctree_controls$nmax
 yx   z 
Inf Inf 

$ctree_controls$lookahead
[1] FALSE

$ctree_controls$mtry
[1] Inf

$ctree_controls$maxdepth
[1] 5

$ctree_controls$multiway
[1] FALSE

$ctree_controls$splittry
[1] 2

$ctree_controls$maxsurrogate
[1] 0

$ctree_controls$numsurrogate
[1] FALSE

$ctree_controls$majority
[1] FALSE

$ctree_controls$caseweights
[1] TRUE

$ctree_controls$applyfun
function (X, FUN, ...) 
{
    FUN <- match.fun(FUN)
    if (!is.vector(X) || is.object(X)) 
        X <- as.list(X)
    .Internal(lapply(X, FUN))
}
<bytecode: 0x55e39fc515e0>
<environment: namespace:base>

$ctree_controls$saveinfo
[1] TRUE

$ctree_controls$bonferroni
[1] TRUE

$ctree_controls$update
NULL

$ctree_controls$selectfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .select(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55e3a549a910>
<environment: 0x55e3a549b518>

$ctree_controls$splitfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .split(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55e3a5498600>
<environment: 0x55e3a54991d0>

$ctree_controls$svselectfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .select(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55e3a549a910>
<environment: 0x55e3a54992b0>

$ctree_controls$svsplitfun
function (model, trafo, data, subset, weights, whichvar, ctrl) 
{
    args <- list(...)
    ctrl[names(args)] <- args
    .split(model, trafo, data, subset, weights, whichvar, ctrl, 
        FUN = .ctree_test)
}
<bytecode: 0x55e3a5498600>
<environment: 0x55e3a5499400>

$ctree_controls$teststat
[1] "quadratic"

$ctree_controls$splitstat
[1] "quadratic"

$ctree_controls$splittest
[1] FALSE

$ctree_controls$pargs
$maxpts
[1] 25000

$abseps
[1] 0.001

$releps
[1] 0

attr(,"class")
[1] "GenzBretz"

$ctree_controls$testtype
[1] "Bonferroni"

$ctree_controls$nresample
[1] 9999

$ctree_controls$tol
[1] 1.490116e-08

$ctree_controls$intersplit
[1] FALSE

$ctree_controls$MIA
[1] FALSE



Slot "best.tree":
$tree

Model formula:
c_hat ~ x1 + x2

Fitted party:
[1] root: 1 (n = 100, err = 75.0%) 

Number of inner nodes:    0
Number of terminal nodes: 1

$glms
$glms[[1]]

Call:  stats::glm(formula = y ~ ., family = stats::binomial(link = "logit"), 
    data = data_train_c_map)

Coefficients:
(Intercept)           x1           x2  
     2.1900       0.5628      -0.9590  

Degrees of Freedom: 99 Total (i.e. Null);  97 Residual
Null Deviance:	    138.3 
Residual Deviance: 106.2 	AIC: 112.2



Slot "performance":
$performance
[1] -112.2415

$criterionEvolution
$criterionEvolution[[1]]
[1] 0

$criterionEvolution[[2]]
[1] -112.2415

$criterionEvolution[[3]]
[1] -112.2415

$criterionEvolution[[4]]
[1] -112.2415

$criterionEvolution[[5]]
[1] -112.2415

$criterionEvolution[[6]]
[1] -112.2415

$criterionEvolution[[7]]
[1] -112.2415

$criterionEvolution[[8]]
[1] -112.2415

$criterionEvolution[[9]]
[1] -112.2415

$criterionEvolution[[10]]
[1] -112.2415

$criterionEvolution[[11]]
[1] -112.2415

$criterionEvolution[[12]]
[1] -112.2415

$criterionEvolution[[13]]
[1] -112.2415

$criterionEvolution[[14]]
[1] -112.2415

$criterionEvolution[[15]]
[1] -112.2415

$criterionEvolution[[16]]
[1] -112.2415

$criterionEvolution[[17]]
[1] -112.2415

$criterionEvolution[[18]]
[1] -112.2415

$criterionEvolution[[19]]
[1] -112.2415

$criterionEvolution[[20]]
[1] -112.2415

$criterionEvolution[[21]]
[1] -112.2415

$criterionEvolution[[22]]
[1] -112.2415

$criterionEvolution[[23]]
[1] -112.2415

$criterionEvolution[[24]]
[1] -112.2415

$criterionEvolution[[25]]
[1] -112.2415

$criterionEvolution[[26]]
[1] -112.2415

$criterionEvolution[[27]]
[1] -112.2415

$criterionEvolution[[28]]
[1] -112.2415

$criterionEvolution[[29]]
[1] -112.2415

$criterionEvolution[[30]]
[1] -112.2415

$criterionEvolution[[31]]
[1] -112.2415

$criterionEvolution[[32]]
[1] -112.2415

$criterionEvolution[[33]]
[1] -112.2415

$criterionEvolution[[34]]
[1] -112.2415

$criterionEvolution[[35]]
[1] -112.2415

$criterionEvolution[[36]]
[1] -112.2415

$criterionEvolution[[37]]
[1] -112.2415

$criterionEvolution[[38]]
[1] -112.2415

$criterionEvolution[[39]]
[1] -112.2415

$criterionEvolution[[40]]
[1] -112.2415

$criterionEvolution[[41]]
[1] -112.2415

$criterionEvolution[[42]]
[1] -112.2415

$criterionEvolution[[43]]
[1] -112.2415

$criterionEvolution[[44]]
[1] -112.2415

$criterionEvolution[[45]]
[1] -112.2415

$criterionEvolution[[46]]
[1] -112.2415

$criterionEvolution[[47]]
[1] -112.2415

$criterionEvolution[[48]]
[1] -112.2415

$criterionEvolution[[49]]
[1] -112.2415

$criterionEvolution[[50]]
[1] -112.2415

$criterionEvolution[[51]]
[1] -112.2415

$criterionEvolution[[52]]
[1] -112.2415

$criterionEvolution[[53]]
[1] -112.2415

$criterionEvolution[[54]]
[1] -112.2415

$criterionEvolution[[55]]
[1] -112.2415

$criterionEvolution[[56]]
[1] -112.2415

$criterionEvolution[[57]]
[1] -112.2415

$criterionEvolution[[58]]
[1] -112.2415

$criterionEvolution[[59]]
[1] -112.2415

$criterionEvolution[[60]]
[1] -112.2415

$criterionEvolution[[61]]
[1] -112.2415

$criterionEvolution[[62]]
[1] -112.2415

$criterionEvolution[[63]]
[1] -112.2415

$criterionEvolution[[64]]
[1] -112.2415

$criterionEvolution[[65]]
[1] -112.2415

$criterionEvolution[[66]]
[1] -112.2415

$criterionEvolution[[67]]
[1] -112.2415

$criterionEvolution[[68]]
[1] -112.2415

$criterionEvolution[[69]]
[1] -112.2415

$criterionEvolution[[70]]
[1] -112.2415

$criterionEvolution[[71]]
[1] -112.2415

$criterionEvolution[[72]]
[1] -112.2415

$criterionEvolution[[73]]
[1] -112.2415

$criterionEvolution[[74]]
[1] -112.2415

$criterionEvolution[[75]]
[1] -112.2415

$criterionEvolution[[76]]
[1] -112.2415

$criterionEvolution[[77]]
[1] -112.2415

$criterionEvolution[[78]]
[1] -112.2415

$criterionEvolution[[79]]
[1] -112.2415

$criterionEvolution[[80]]
[1] -112.2415



There were 50 or more warnings (use warnings() to see the first 50)

glmtree documentation built on Jan. 13, 2021, 4:58 p.m.