tvcglm: Coefficient-wise tree-based varying coefficient regression...

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/tvcm.R

Description

The tvcglm function implements the tree-based varying coefficient regression algorithm for generalized linear models introduced by Buergin and Ritschard (2017). The algorithm approximates varying coefficients by piecewise constant functions using recursive partitioning, i.e., it estimates the selected coefficients individually by strata of the value space of partitioning variables. The special feature of the provided algorithm is that it allows building for each varying coefficient an individual partition, which enhances the possibilities for model specification and to select partitioning variables individually by coefficient.

Usage

1
2
3
4
5
6
7
8
9
tvcglm(formula, data, family, 
       weights, subset, offset, na.action = na.omit, 
       control = tvcglm_control(), ...)

tvcglm_control(minsize = 30, mindev = 2.0,
               maxnomsplit = 5, maxordsplit = 9, maxnumsplit = 9,
               cv = TRUE, folds = folds_control("kfold", 5),
               prune = cv, fast = TRUE, center = fast,
	       maxstep = 1e3, verbose = FALSE, ...)

Arguments

formula

a symbolic description of the model to fit, e.g.,

y ~ vc(z1, z2, z3) + vc(z1, z2, by = x1) + vc(z2, z3, by = x2)

where the vc terms specify the varying fixed coefficients. The unnamed arguments within vc terms are interpreted as partitioning variables (i.e., moderators). The by argument specifies the associated predictor variable. If no such predictor variable is specified (e.g., see the first term in the above example formula), the vc term is interpreted as a varying intercept, i.e., an nonparametric estimate of the direct effect of the partitioning variables. For details, see vcrpart-formula. Note that the global intercept may be removed by a -1 term, according to the desired interpretation of the model.

family

the model family. An object of class family.

data

a data frame containing the variables in the model.

weights

an optional numeric vector of weights to be used in the fitting process.

subset

an optional logical or integer vector specifying a subset of 'data' to be used in the fitting process.

offset

this can be used to specify an a priori known component to be included in the linear predictor during fitting.

na.action

a function that indicates what should happen if data contain NAs. The default na.action = na.omit is listwise deletion, i.e., observations with missings on any variable are dropped. See na.action.

control

a list with control parameters as returned by tvcglm_control, or by tvcm_control for advanced users.

minsize

numeric (vector). The minimum sum of weights in terminal nodes.

mindev

numeric scalar. The minimum permitted training error reduction a split must exhibit to be considered of a new split. The main role of this parameter is to save computing time by early stopping. May be set lower for very few partitioning variables resp. higher for many partitioning variables.

maxnomsplit, maxordsplit, maxnumsplit

integer scalars for split candidate reduction. See tvcm_control

cv

logical scalar. Whether or not the cp parameter should be cross-validated. If TRUE cvloss is called.

folds

a list of parameters to create folds as produced by folds_control. Is used for cross-validation.

prune

logical scalar. Whether or not the initial tree should be pruned by the estimated cp parameter from cross-validation. Cannot be TRUE if cv = FALSE.

fast

logical scalar. Whether the approximative model should be used to search for the next split. The approximative search model uses only the observations of the node to split and incorporates the fitted values of the current model as offsets. Therewith the estimation is reduces to the coefficients of the added split. If FALSE, the accurate search model is used.

center

logical integer. Whether the predictor variables of update models during the grid search should be centered. Note that TRUE will not modify the predictors of the fitted model.

maxstep

integer. The maximum number of iterations i.e. number of splits to be processed.

verbose

logical. Should information about the fitting process be printed to the screen?

...

additional arguments passed to the fitting function fit or to tvcm_control.

Details

tvcglm processes two stages. The first stage, called partitioning stage, builds overly fine partitions for each vc term; the second stage, called pruning stage, selects the best-sized partitions by collapsing inner nodes. For details on the pruning stage, see tvcm-assessment. The partitioning stage iterates the following steps:

  1. Fit the current generalized linear model

    y ~ NodeA:x1 + ... + NodeK:xK

    with glm, where Nodek is a categorical variable with terminal node labels for the k-th varying coefficient.

  2. Search the globally best split among the candidate splits by an exhaustive -2 likelihood training error search that cycles through all possible splits.

  3. If the -2 likelihood training error reduction of the best split is smaller than mindev or there is no candidate split satisfying the minimum node size minsize, stop the algorithm.

  4. Else incorporate the best split and repeat the procedure.

The partitioning stage selects, in each iteration, the split that maximizes the -2 likelihood training error reduction, compared to the current model. The default stopping parameters are minsize = 30 (a minimum node size of 30) and mindev = 2 (the training error reduction of the best split must be larger than two to continue).

The algorithm implements a number of split point reduction methods to decrease the computational complexity. See the arguments maxnomsplit, maxordsplit and maxnumsplit.

The algorithm can be seen as an extension of CART (Breiman et. al., 1984) and PartReg (Wang and Hastie, 2014), with the new feature that partitioning can be processed coefficient-wise.

Value

An object of class tvcm

Author(s)

Reto Buergin

References

Breiman, L., J. H. Friedman, R. A. Olshen and C.J. Stone (1984). Classification and Regression Trees. New York, USA: Wadsworth.

Wang, J. C., Hastie, T. (2014), Boosted Varying-Coefficient Regression Models for Product Demand Prediction, Journal of Computational and Graphical Statistics, 23(2), 361-382.

Buergin, R. and G. Ritschard (2017), Coefficient-Wise Tree-Based Varying Coefficient Regression with vcrpart. Journal of Statistical Software, 80(6), 1–33.

See Also

tvcm_control, tvcm-methods, tvcm-plot, tvcm-plot, tvcm-assessment, fvcglm, glm

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## ------------------------------------------------------------------- #  
## Example: Moderated effect of education on poverty
##
## The algorithm is used to find out whether the effect of high
## education 'EduHigh' on poverty 'Poor' is moderated by the civil
## status 'CivStat'. We specify two 'vc' terms in the logistic
## regression model for 'Poor': a first that accounts for the direct
## effect of 'CivStat' and a second that accounts for the moderation of
## 'CivStat' on the relation between 'EduHigh' and 'Poor'. We use here
## the 2-stage procedure with a partitioning- and a pruning stage as
## described in Buergin and Ritschard (2017). 
## ------------------------------------------------------------------- #

data(poverty)
poverty$EduHigh <- 1 * (poverty$Edu == "high")

## fit the model
model.Pov <-
  tvcglm(Poor ~ -1 +  vc(CivStat) + vc(CivStat, by = EduHigh) + NChild, 
         family = binomial(), data = poverty, subset = 1:200,
         control = tvcm_control(verbose = TRUE, papply = lapply,
           folds = folds_control(K = 1, type = "subsampling", seed = 7)))

## diagnosis
plot(model.Pov, "cv")
plot(model.Pov, "coef")
summary(model.Pov)
splitpath(model.Pov, steps = 1:3)
prunepath(model.Pov, steps = 1)

Example output

Loading required package: parallel
Loading required package: partykit
Loading required package: grid
Loading required package: libcoin
Loading required package: mvtnorm
* checking arguments ... OK
* setting formulas ... OK
* extracting model frames ... OK
* setting arguments ... 
* starting partitioning and cross validation ...
* fold 0 ...
* starting step 1 ...

Varying-coefficient(s) of current model:
            Estimate
(Intercept)    -0.91
EduHigh        -0.61

* computing splits OK

Partition: A
Node: 1
Variable: CivStat
Cutpoint:
  single married widow sep/div
2      1       1     0       0
Model comparison:
         loss   dev
step 0 204.32      
step 1 189.46 14.86

* starting step 2 ...

Varying-coefficient(s) of current model:
        Estimate
NodeA2    -1.434
NodeA3    -0.089
EduHigh   -0.699

* computing splits OK

Partition: B
Node: 1
Variable: CivStat
Cutpoint:
  single married widow sep/div
2      1       1     0       0
Model comparison:
         loss  dev
step 1 189.26     
step 2 186.28 2.98

* starting step 3 ...

Varying-coefficient(s) of current model:
               Estimate
NodeA2           -1.157
NodeA3           -0.300
NodeB2:EduHigh   -1.904
NodeB3:EduHigh   -0.059


Stopping partitioning.
Message: no admissible splits (exceeded tree size parameters) 
* fold 1 ... OK

estimated cp = 2.46 

* pruning ... OK

Fitted model:
Tree-Based Varying Coefficients Model 
  Family: binomial logit 
 Formula: Poor ~ -1 + vc(CivStat) + vc(CivStat, by = EduHigh) + NChild 
    Data: poverty 
  Subset: 1:200 

Fixed Effects:
        NChild
[1,] 0.1417691

Varying Coefficient A: vc(CivStat, by = (Intercept))
[1] root
|   [2] CivStat in single, married
|         (Intercept)
|           -1.157078
|   [3] CivStat in widow, sep/div
|         (Intercept)
|          -0.2999993

Varying Coefficient B: vc(CivStat, by = EduHigh)
[1] root
|   [2] CivStat in single, married
|           EduHigh
|         -1.904493
|   [3] CivStat in widow, sep/div
|             EduHigh
|         -0.05917639
* computations finished, return object
Tree-Based Varying Coefficients Model 
  Family: binomial logit 
 Formula: Poor ~ -1 + vc(CivStat) + vc(CivStat, by = EduHigh) + NChild 
    Data: poverty 
  Subset: 1:200 

Fixed Effects:
        Estimate Std. Error z value
NChild 0.1417691  0.1297385 1.09273

Varying Coefficient A: vc(CivStat, by = (Intercept))
[1] root
|   [2] CivStat in single, married
|                      Estimate  Std. Error     z value
|       (Intercept)  -1.1570782   0.4405772  -2.6262779
|   [3] CivStat in widow, sep/div
|                      Estimate  Std. Error     z value
|       (Intercept)  -0.2999993   0.4606072  -0.6513127

Varying Coefficient B: vc(CivStat, by = EduHigh)
[1] root
|   [2] CivStat in single, married
|                  Estimate  Std. Error     z value
|       EduHigh  -1.9044925   0.7878335  -2.4173796
|   [3] CivStat in widow, sep/div
|                   Estimate   Std. Error      z value
|       EduHigh  -0.05917639   0.48221183  -0.12271865
Step: 1

Selected Split:
Partition: A
Node: 1
Variable: CivStat
Cutpoint: {single, married}, {widow, sep/div}

Step: 2

Selected Split:
Partition: B
Node: 1
Variable: CivStat
Cutpoint: {single, married}, {widow, sep/div}

Step: 3 (no splitting processed)

Step: 1 
       part node loss     npar nsplit dev     
<none>           184.5268 5    2              
1      A     1   188.8215 4    1      4.294678
2      B     1   189.2615 4    1      4.734693

vcrpart documentation built on April 19, 2021, 1:07 a.m.