Last updated on 2026-08-02 07:50:43 CEST.
| Flavor | Version | Tinstall | Tcheck | Ttotal | Status | Flags |
|---|---|---|---|---|---|---|
| r-devel-linux-x86_64-debian-clang | 1.2-29 | 15.47 | 253.21 | 268.68 | ERROR | |
| r-devel-linux-x86_64-debian-gcc | 1.2-29 | 9.71 | 177.11 | 186.82 | ERROR | |
| r-devel-linux-x86_64-fedora-clang | 1.2-29 | 24.00 | 399.49 | 423.49 | ERROR | |
| r-devel-linux-x86_64-fedora-gcc | 1.2-29 | 10.00 | 185.24 | 195.24 | ERROR | |
| r-devel-windows-x86_64 | 1.2-29 | 18.00 | 314.00 | 332.00 | ERROR | |
| r-patched-linux-x86_64 | 1.2-29 | 15.11 | 241.06 | 256.17 | ERROR | |
| r-release-linux-x86_64 | 1.2-29 | 15.17 | 243.80 | 258.97 | ERROR | |
| r-release-macos-arm64 | 1.2-29 | 4.00 | 78.00 | 82.00 | OK | |
| r-release-macos-x86_64 | 1.2-29 | 12.00 | 392.00 | 404.00 | OK | |
| r-release-windows-x86_64 | 1.2-29 | 18.00 | 304.00 | 322.00 | ERROR | |
| r-oldrel-macos-arm64 | 1.2-29 | 3.00 | 81.00 | 84.00 | OK | |
| r-oldrel-macos-x86_64 | 1.2-29 | 12.00 | 597.00 | 609.00 | OK | |
| r-oldrel-windows-x86_64 | 1.2-29 | 24.00 | 381.00 | 405.00 | ERROR |
Version: 1.2-29
Check: examples
Result: ERROR
Running examples in ‘partykit-Ex.R’ failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: glmtree
> ### Title: Generalized Linear Model Trees
> ### Aliases: glmtree plot.glmtree predict.glmtree print.glmtree
> ### Keywords: tree
>
> ### ** Examples
>
> if(require("mlbench") && require("vcd")) {
+
+ ## Pima Indians diabetes data
+ data("PimaIndiansDiabetes", package = "mlbench")
+
+ ## recursive partitioning of a logistic regression model
+ pid_tree2 <- glmtree(diabetes ~ glucose | pregnant +
+ pressure + triceps + insulin + mass + pedigree + age,
+ data = PimaIndiansDiabetes, family = binomial)
+
+ ## printing whole tree or individual nodes
+ print(pid_tree2)
+ print(pid_tree2, node = 1)
+
+ ## visualization
+ plot(pid_tree2)
+ plot(pid_tree2, tp_args = list(cdplot = TRUE))
+ plot(pid_tree2, terminal_panel = NULL)
+
+ ## estimated parameters
+ coef(pid_tree2)
+ coef(pid_tree2, node = 5)
+ summary(pid_tree2, node = 5)
+
+ ## deviance, log-likelihood and information criteria
+ deviance(pid_tree2)
+ logLik(pid_tree2)
+ AIC(pid_tree2)
+ BIC(pid_tree2)
+
+ ## different types of predictions
+ pid <- head(PimaIndiansDiabetes)
+ predict(pid_tree2, newdata = pid, type = "node")
+ predict(pid_tree2, newdata = pid, type = "response")
+ predict(pid_tree2, newdata = pid, type = "link")
+
+ }
Loading required package: mlbench
Loading required package: vcd
Warning in data("PimaIndiansDiabetes", package = "mlbench") :
data set ‘PimaIndiansDiabetes’ not found
Error in eval(mf, parent.frame()) :
object 'PimaIndiansDiabetes' not found
Calls: glmtree ... model.frame -> terms -> terms.Formula -> terms -> terms.formula
Execution halted
Flavors: r-devel-linux-x86_64-debian-clang, r-devel-linux-x86_64-debian-gcc, r-patched-linux-x86_64, r-release-linux-x86_64
Version: 1.2-29
Check: tests
Result: ERROR
Running ‘bugfixes.R’ [5s/7s]
Comparing ‘bugfixes.Rout’ to ‘bugfixes.Rout.save’ ... OK
Running ‘constparty.R’ [5s/6s]
Comparing ‘constparty.Rout’ to ‘constparty.Rout.save’ ... OK
Running ‘regtest-MIA.R’ [2s/2s]
Comparing ‘regtest-MIA.Rout’ to ‘regtest-MIA.Rout.save’ ... OK
Running ‘regtest-cforest.R’ [14s/18s]
Comparing ‘regtest-cforest.Rout’ to ‘regtest-cforest.Rout.save’ ... OK
Running ‘regtest-ctree.R’ [2s/3s]
Comparing ‘regtest-ctree.Rout’ to ‘regtest-ctree.Rout.save’ ... OK
Running ‘regtest-glmtree.R’ [34s/42s]
Running ‘regtest-honesty.R’ [2s/2s]
Running ‘regtest-lmtree.R’ [3s/3s]
Running ‘regtest-nmax.R’ [2s/3s]
Comparing ‘regtest-nmax.Rout’ to ‘regtest-nmax.Rout.save’ ... OK
Running ‘regtest-node.R’ [2s/2s]
Comparing ‘regtest-node.Rout’ to ‘regtest-node.Rout.save’ ... OK
Running ‘regtest-party-random.R’ [2s/3s]
Running ‘regtest-party.R’ [5s/5s]
Comparing ‘regtest-party.Rout’ to ‘regtest-party.Rout.save’ ... OK
Running ‘regtest-split.R’ [2s/2s]
Comparing ‘regtest-split.Rout’ to ‘regtest-split.Rout.save’ ... OK
Running ‘regtest-weights.R’ [2s/3s]
Comparing ‘regtest-weights.Rout’ to ‘regtest-weights.Rout.save’ ... OK
Running the tests in ‘tests/regtest-glmtree.R’ failed.
Complete output:
> suppressWarnings(RNGversion("3.5.2"))
>
> library("partykit")
Loading required package: grid
Loading required package: libcoin
Loading required package: mvtnorm
>
> set.seed(29)
> n <- 1000
> x <- runif(n)
> z <- runif(n)
> y <- rnorm(n, mean = x * c(-1, 1)[(z > 0.7) + 1], sd = 3)
> z_noise <- factor(sample(1:3, size = n, replace = TRUE))
> d <- data.frame(y = y, x = x, z = z, z_noise = z_noise)
>
>
> fmla <- as.formula("y ~ x | z + z_noise")
> fmly <- gaussian()
> fit <- partykit:::glmfit
>
> # versions of the data
> d1 <- d
> d1$z <- signif(d1$z, digits = 1)
>
> k <- 20
> zs_noise <- matrix(rnorm(n*k), nrow = n)
> colnames(zs_noise) <- paste0("z_noise_", 1:k)
> d2 <- cbind(d, zs_noise)
> fmla2 <- as.formula(paste("y ~ x | z + z_noise +",
+ paste0("z_noise_", 1:k, collapse = " + ")))
>
>
> d3 <- d2
> d3$z <- factor(sample(1:3, size = n, replace = TRUE, prob = c(0.1, 0.5, 0.4)))
> d3$y <- rnorm(n, mean = x * c(-1, 1)[(d3$z == 2) + 1], sd = 3)
>
> ## check weights
> w <- rep(1, n)
> w[1:10] <- 2
> (mw1 <- glmtree(formula = fmla, data = d, weights = w))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 706
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 304
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
> (mw2 <- glmtree(formula = fmla, data = d, weights = w, caseweights = FALSE))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
>
>
>
> ## check dfsplit
> (mmfluc2 <- mob(formula = fmla, data = d, fit = partykit:::glmfit))
Model-based recursive partitioning (partykit:::glmfit)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function: 2551.673
> (mmfluc3 <- glmtree(formula = fmla, data = d))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
> (mmfluc3_dfsplit <- glmtree(formula = fmla, data = d, dfsplit = 10))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
>
> ## check tests
> if (require("strucchange"))
+ print(sctest(mmfluc3, node = 1)) # does not yet work
Loading required package: strucchange
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Loading required package: sandwich
z z_noise
statistic 2.292499e+01 0.6165335
p.value 7.780038e-04 0.9984952
>
> x <- mmfluc3
> (tst3 <- nodeapply(x, ids = nodeids(x), function(n) n$info$criterion))
$`1`
NULL
$`2`
NULL
$`3`
NULL
>
>
>
>
> ## check logLik and AIC
> logLik(mmfluc2)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3_dfsplit)
'log Lik.' -2551.673 (df=16)
> logLik(glm(y ~ x, data = d))
'log Lik.' -2563.694 (df=3)
>
> AIC(mmfluc3)
[1] 5117.347
> AIC(mmfluc3_dfsplit)
[1] 5135.347
>
> ## check pruning
> pr2 <- prune.modelparty(mmfluc2)
> AIC(mmfluc2)
[1] 5117.347
> AIC(pr2)
[1] 5117.347
>
> mmfluc_dfsplit3 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 3)
> mmfluc_dfsplit4 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 4)
> pr_dfsplit3 <- prune.modelparty(mmfluc_dfsplit3)
> pr_dfsplit4 <- prune.modelparty(mmfluc_dfsplit4)
> AIC(mmfluc_dfsplit3)
[1] 5142.774
> AIC(mmfluc_dfsplit4)
[1] 5156.774
> AIC(pr_dfsplit3)
[1] 5142.774
> AIC(pr_dfsplit4)
[1] 5124.456
>
> width(mmfluc_dfsplit3)
[1] 8
> width(mmfluc_dfsplit4)
[1] 8
> width(pr_dfsplit3)
[1] 8
> width(pr_dfsplit4)
[1] 3
>
> ## check inner and terminal
> options <- list(NULL,
+ "object",
+ "estfun",
+ c("object", "estfun"))
>
> arguments <- list("inner",
+ "terminal",
+ c("inner", "terminal"))
>
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, inner = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, terminal = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ NA: NULL
..$ NA: NULL
$ 3:List of 2
..$ NA: NULL
..$ NA: NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ NA : NULL
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ NA : NULL
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
>
>
> ## check model
> m_mt <- glmtree(formula = fmla, data = d, model = TRUE)
> m_mf <- glmtree(formula = fmla, data = d, model = FALSE)
>
> dim(m_mt$data)
[1] 1000 4
> dim(m_mf$data)
[1] 0 4
>
>
> ## check multiway
> (m_mult <- glmtree(formula = fmla2, data = d3, catsplit = "multiway", minsize = 80))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise + z_noise_1 + z_noise_2 + z_noise_3 + z_noise_4 +
z_noise_5 + z_noise_6 + z_noise_7 + z_noise_8 + z_noise_9 +
z_noise_10 + z_noise_11 + z_noise_12 + z_noise_13 + z_noise_14 +
z_noise_15 + z_noise_16 + z_noise_17 + z_noise_18 + z_noise_19 +
z_noise_20
Fitted party:
[1] root
| [2] z in 1: n = 76
| (Intercept) x
| 0.9859847 -3.2600047
| [3] z in 2: n = 537
| (Intercept) x
| -0.06970187 1.12305074
| [4] z in 3: n = 387
| (Intercept) x
| 0.3824392 -1.8337151
Number of inner nodes: 1
Number of terminal nodes: 3
Number of parameters per node: 2
Objective function (negative log-likelihood): 2511.927
>
>
> ## check parm
> fmla_p <- as.formula("y ~ x + z_noise + z_noise_1 | z + z_noise_2")
> (m_interc <- glmtree(formula = fmla_p, data = d2, parm = 1))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root
| [2] z <= 0.65035: n = 644
| (Intercept) x z_noise2 z_noise3 z_noise_1
| -0.05585503 -1.01257554 0.34044520 -0.16384987 0.24197601
| [3] z > 0.65035: n = 356
| (Intercept) x z_noise2 z_noise3 z_noise_1
| 0.06411865 0.78733976 -0.67811149 -0.14240432 -0.01239154
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 5
Objective function (negative log-likelihood): 2548.32
>
> (m_p3 <- glmtree(formula = fmla_p, data = d2, parm = 3))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root: n = 1000
(Intercept) x z_noise2 z_noise3 z_noise_1
-0.058855295 -0.340314311 -0.008404682 -0.109839080 0.154798281
Number of inner nodes: 0
Number of terminal nodes: 1
Number of parameters per node: 5
Objective function (negative log-likelihood): 2562.32
>
>
> ## check trim
> (m_tt <- glmtree(formula = fmla, data = d, trim = 0.2))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
> (m_tf <- glmtree(formula = fmla, data = d, trim = 300, minsize = 300))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.6892: n = 691
| (Intercept) x
| -0.1778199 -0.7692901
| [3] z > 0.6892: n = 309
| (Intercept) x
| 0.1065746 0.5562243
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2552.12
>
>
>
> ## check breakties
> m_bt <- glmtree(formula = fmla, data = d1, breakties = TRUE)
> m_df <- glmtree(formula = fmla, data = d1, breakties = FALSE)
>
> all.equal(m_bt, m_df, check.environment = FALSE)
[1] "Component \"node\": Component \"kids\": Component 1: Component 5: Component 6: Mean relative difference: 0.1237503"
[2] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 5: Mean relative difference: 0.1746109"
[3] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 6: Mean relative difference: 0.0443985"
[4] "Component \"node\": Component \"info\": Component \"p.value\": Mean relative difference: 1.100407"
[5] "Component \"node\": Component \"info\": Component \"test\": Mean relative difference: 0.07721086"
[6] "Component \"info\": Component \"call\": target, current do not match when deparsed"
[7] "Component \"info\": Component \"control\": Component \"breakties\": 1 element mismatch"
>
> unclass(m_bt)$node$info$criterion
NULL
> unclass(m_df)$node$info$criterion
NULL
>
> if (requireNamespace("mlbench")) {
+
+ ### example from mob vignette
+ data("PimaIndiansDiabetes", package = "mlbench")
+
+ logit <- function(y, x, start = NULL, weights = NULL, offset = NULL, ...) {
+ glm(y ~ 0 + x, family = binomial, start = start, ...)
+ }
+
+ pid_formula <- diabetes ~ glucose | pregnant + pressure + triceps +
+ insulin + mass + pedigree + age
+
+ pid_tree <- mob(pid_formula, data = PimaIndiansDiabetes, fit = logit)
+ print(pid_tree)
+ print(nodeapply(pid_tree, ids = nodeids(pid_tree), function(n) n$info$criterion))
+
+ }
Loading required namespace: mlbench
Error in eval(mf, parent.frame()) :
object 'PimaIndiansDiabetes' not found
Calls: mob ... model.frame -> terms -> terms.Formula -> terms -> terms.formula
In addition: Warning message:
In data("PimaIndiansDiabetes", package = "mlbench") :
data set 'PimaIndiansDiabetes' not found
Execution halted
Flavor: r-devel-linux-x86_64-debian-clang
Version: 1.2-29
Check: re-building of vignette outputs
Result: ERROR
Error(s) in re-building vignettes:
...
--- re-building ‘constparty.Rnw’ using knitr
--- finished re-building ‘constparty.Rnw’
--- re-building ‘ctree.Rnw’ using knitr
--- finished re-building ‘ctree.Rnw’
--- re-building ‘mob.Rnw’ using knitr
Quitting from mob.Rnw:443-445 [PimaIndiansDiabetes-mob]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<error/rlang_error>
Error:
! object 'PimaIndiansDiabetes' not found
---
Backtrace:
x
1. +-stats::model.frame(...)
2. \-Formula:::model.frame.Formula(...)
3. +-stats::model.frame(...)
4. +-stats::terms(formula, lhs = lhs, rhs = rhs, data = data, dot = dot)
5. \-Formula:::terms.Formula(...)
6. +-stats::terms(form, ...)
7. \-stats::terms.formula(form, ...)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: processing vignette 'mob.Rnw' failed with diagnostics:
object 'PimaIndiansDiabetes' not found
--- failed re-building ‘mob.Rnw’
--- re-building ‘partykit.Rnw’ using knitr
--- finished re-building ‘partykit.Rnw’
SUMMARY: processing the following file failed:
‘mob.Rnw’
Error: Vignette re-building failed.
Execution halted
Flavors: r-devel-linux-x86_64-debian-clang, r-devel-linux-x86_64-debian-gcc, r-patched-linux-x86_64, r-release-linux-x86_64
Version: 1.2-29
Check: tests
Result: ERROR
Running ‘bugfixes.R’ [4s/4s]
Comparing ‘bugfixes.Rout’ to ‘bugfixes.Rout.save’ ... OK
Running ‘constparty.R’ [3s/4s]
Comparing ‘constparty.Rout’ to ‘constparty.Rout.save’ ... OK
Running ‘regtest-MIA.R’ [1s/2s]
Comparing ‘regtest-MIA.Rout’ to ‘regtest-MIA.Rout.save’ ... OK
Running ‘regtest-cforest.R’ [8s/9s]
Comparing ‘regtest-cforest.Rout’ to ‘regtest-cforest.Rout.save’ ... OK
Running ‘regtest-ctree.R’ [1s/2s]
Comparing ‘regtest-ctree.Rout’ to ‘regtest-ctree.Rout.save’ ... OK
Running ‘regtest-glmtree.R’ [22s/26s]
Running ‘regtest-honesty.R’ [1s/2s]
Running ‘regtest-lmtree.R’ [2s/3s]
Running ‘regtest-nmax.R’ [1s/2s]
Comparing ‘regtest-nmax.Rout’ to ‘regtest-nmax.Rout.save’ ... OK
Running ‘regtest-node.R’ [1s/2s]
Comparing ‘regtest-node.Rout’ to ‘regtest-node.Rout.save’ ... OK
Running ‘regtest-party-random.R’ [2s/2s]
Running ‘regtest-party.R’ [3s/3s]
Comparing ‘regtest-party.Rout’ to ‘regtest-party.Rout.save’ ... OK
Running ‘regtest-split.R’ [1s/2s]
Comparing ‘regtest-split.Rout’ to ‘regtest-split.Rout.save’ ... OK
Running ‘regtest-weights.R’ [2s/2s]
Comparing ‘regtest-weights.Rout’ to ‘regtest-weights.Rout.save’ ... OK
Running the tests in ‘tests/regtest-glmtree.R’ failed.
Complete output:
> suppressWarnings(RNGversion("3.5.2"))
>
> library("partykit")
Loading required package: grid
Loading required package: libcoin
Loading required package: mvtnorm
>
> set.seed(29)
> n <- 1000
> x <- runif(n)
> z <- runif(n)
> y <- rnorm(n, mean = x * c(-1, 1)[(z > 0.7) + 1], sd = 3)
> z_noise <- factor(sample(1:3, size = n, replace = TRUE))
> d <- data.frame(y = y, x = x, z = z, z_noise = z_noise)
>
>
> fmla <- as.formula("y ~ x | z + z_noise")
> fmly <- gaussian()
> fit <- partykit:::glmfit
>
> # versions of the data
> d1 <- d
> d1$z <- signif(d1$z, digits = 1)
>
> k <- 20
> zs_noise <- matrix(rnorm(n*k), nrow = n)
> colnames(zs_noise) <- paste0("z_noise_", 1:k)
> d2 <- cbind(d, zs_noise)
> fmla2 <- as.formula(paste("y ~ x | z + z_noise +",
+ paste0("z_noise_", 1:k, collapse = " + ")))
>
>
> d3 <- d2
> d3$z <- factor(sample(1:3, size = n, replace = TRUE, prob = c(0.1, 0.5, 0.4)))
> d3$y <- rnorm(n, mean = x * c(-1, 1)[(d3$z == 2) + 1], sd = 3)
>
> ## check weights
> w <- rep(1, n)
> w[1:10] <- 2
> (mw1 <- glmtree(formula = fmla, data = d, weights = w))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 706
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 304
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
> (mw2 <- glmtree(formula = fmla, data = d, weights = w, caseweights = FALSE))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
>
>
>
> ## check dfsplit
> (mmfluc2 <- mob(formula = fmla, data = d, fit = partykit:::glmfit))
Model-based recursive partitioning (partykit:::glmfit)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function: 2551.673
> (mmfluc3 <- glmtree(formula = fmla, data = d))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
> (mmfluc3_dfsplit <- glmtree(formula = fmla, data = d, dfsplit = 10))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
>
> ## check tests
> if (require("strucchange"))
+ print(sctest(mmfluc3, node = 1)) # does not yet work
Loading required package: strucchange
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Loading required package: sandwich
z z_noise
statistic 2.292499e+01 0.6165335
p.value 7.780038e-04 0.9984952
>
> x <- mmfluc3
> (tst3 <- nodeapply(x, ids = nodeids(x), function(n) n$info$criterion))
$`1`
NULL
$`2`
NULL
$`3`
NULL
>
>
>
>
> ## check logLik and AIC
> logLik(mmfluc2)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3_dfsplit)
'log Lik.' -2551.673 (df=16)
> logLik(glm(y ~ x, data = d))
'log Lik.' -2563.694 (df=3)
>
> AIC(mmfluc3)
[1] 5117.347
> AIC(mmfluc3_dfsplit)
[1] 5135.347
>
> ## check pruning
> pr2 <- prune.modelparty(mmfluc2)
> AIC(mmfluc2)
[1] 5117.347
> AIC(pr2)
[1] 5117.347
>
> mmfluc_dfsplit3 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 3)
> mmfluc_dfsplit4 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 4)
> pr_dfsplit3 <- prune.modelparty(mmfluc_dfsplit3)
> pr_dfsplit4 <- prune.modelparty(mmfluc_dfsplit4)
> AIC(mmfluc_dfsplit3)
[1] 5142.774
> AIC(mmfluc_dfsplit4)
[1] 5156.774
> AIC(pr_dfsplit3)
[1] 5142.774
> AIC(pr_dfsplit4)
[1] 5124.456
>
> width(mmfluc_dfsplit3)
[1] 8
> width(mmfluc_dfsplit4)
[1] 8
> width(pr_dfsplit3)
[1] 8
> width(pr_dfsplit4)
[1] 3
>
> ## check inner and terminal
> options <- list(NULL,
+ "object",
+ "estfun",
+ c("object", "estfun"))
>
> arguments <- list("inner",
+ "terminal",
+ c("inner", "terminal"))
>
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, inner = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, terminal = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ NA: NULL
..$ NA: NULL
$ 3:List of 2
..$ NA: NULL
..$ NA: NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ NA : NULL
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ NA : NULL
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
>
>
> ## check model
> m_mt <- glmtree(formula = fmla, data = d, model = TRUE)
> m_mf <- glmtree(formula = fmla, data = d, model = FALSE)
>
> dim(m_mt$data)
[1] 1000 4
> dim(m_mf$data)
[1] 0 4
>
>
> ## check multiway
> (m_mult <- glmtree(formula = fmla2, data = d3, catsplit = "multiway", minsize = 80))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise + z_noise_1 + z_noise_2 + z_noise_3 + z_noise_4 +
z_noise_5 + z_noise_6 + z_noise_7 + z_noise_8 + z_noise_9 +
z_noise_10 + z_noise_11 + z_noise_12 + z_noise_13 + z_noise_14 +
z_noise_15 + z_noise_16 + z_noise_17 + z_noise_18 + z_noise_19 +
z_noise_20
Fitted party:
[1] root
| [2] z in 1: n = 76
| (Intercept) x
| 0.9859847 -3.2600047
| [3] z in 2: n = 537
| (Intercept) x
| -0.06970187 1.12305074
| [4] z in 3: n = 387
| (Intercept) x
| 0.3824392 -1.8337151
Number of inner nodes: 1
Number of terminal nodes: 3
Number of parameters per node: 2
Objective function (negative log-likelihood): 2511.927
>
>
> ## check parm
> fmla_p <- as.formula("y ~ x + z_noise + z_noise_1 | z + z_noise_2")
> (m_interc <- glmtree(formula = fmla_p, data = d2, parm = 1))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root
| [2] z <= 0.65035: n = 644
| (Intercept) x z_noise2 z_noise3 z_noise_1
| -0.05585503 -1.01257554 0.34044520 -0.16384987 0.24197601
| [3] z > 0.65035: n = 356
| (Intercept) x z_noise2 z_noise3 z_noise_1
| 0.06411865 0.78733976 -0.67811149 -0.14240432 -0.01239154
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 5
Objective function (negative log-likelihood): 2548.32
>
> (m_p3 <- glmtree(formula = fmla_p, data = d2, parm = 3))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root: n = 1000
(Intercept) x z_noise2 z_noise3 z_noise_1
-0.058855295 -0.340314311 -0.008404682 -0.109839080 0.154798281
Number of inner nodes: 0
Number of terminal nodes: 1
Number of parameters per node: 5
Objective function (negative log-likelihood): 2562.32
>
>
> ## check trim
> (m_tt <- glmtree(formula = fmla, data = d, trim = 0.2))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
> (m_tf <- glmtree(formula = fmla, data = d, trim = 300, minsize = 300))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.6892: n = 691
| (Intercept) x
| -0.1778199 -0.7692901
| [3] z > 0.6892: n = 309
| (Intercept) x
| 0.1065746 0.5562243
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2552.12
>
>
>
> ## check breakties
> m_bt <- glmtree(formula = fmla, data = d1, breakties = TRUE)
> m_df <- glmtree(formula = fmla, data = d1, breakties = FALSE)
>
> all.equal(m_bt, m_df, check.environment = FALSE)
[1] "Component \"node\": Component \"kids\": Component 1: Component 5: Component 6: Mean relative difference: 0.1237503"
[2] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 5: Mean relative difference: 0.1746109"
[3] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 6: Mean relative difference: 0.0443985"
[4] "Component \"node\": Component \"info\": Component \"p.value\": Mean relative difference: 1.100407"
[5] "Component \"node\": Component \"info\": Component \"test\": Mean relative difference: 0.07721086"
[6] "Component \"info\": Component \"call\": target, current do not match when deparsed"
[7] "Component \"info\": Component \"control\": Component \"breakties\": 1 element mismatch"
>
> unclass(m_bt)$node$info$criterion
NULL
> unclass(m_df)$node$info$criterion
NULL
>
> if (requireNamespace("mlbench")) {
+
+ ### example from mob vignette
+ data("PimaIndiansDiabetes", package = "mlbench")
+
+ logit <- function(y, x, start = NULL, weights = NULL, offset = NULL, ...) {
+ glm(y ~ 0 + x, family = binomial, start = start, ...)
+ }
+
+ pid_formula <- diabetes ~ glucose | pregnant + pressure + triceps +
+ insulin + mass + pedigree + age
+
+ pid_tree <- mob(pid_formula, data = PimaIndiansDiabetes, fit = logit)
+ print(pid_tree)
+ print(nodeapply(pid_tree, ids = nodeids(pid_tree), function(n) n$info$criterion))
+
+ }
Loading required namespace: mlbench
Error in eval(mf, parent.frame()) :
object 'PimaIndiansDiabetes' not found
Calls: mob ... model.frame -> terms -> terms.Formula -> terms -> terms.formula
In addition: Warning message:
In data("PimaIndiansDiabetes", package = "mlbench") :
data set 'PimaIndiansDiabetes' not found
Execution halted
Flavor: r-devel-linux-x86_64-debian-gcc
Version: 1.2-29
Check: for new files in some other directories
Result: NOTE
Found the following files/directories:
‘~/tmp/scratch/Rtmp0148cU’ ‘~/tmp/scratch/Rtmp039Xlx’
‘~/tmp/scratch/Rtmp0Spig2’ ‘~/tmp/scratch/Rtmp0hwdAW’
‘~/tmp/scratch/Rtmp12kCdR’ ‘~/tmp/scratch/Rtmp1Lpvu7’
‘~/tmp/scratch/Rtmp2A01jz’ ‘~/tmp/scratch/Rtmp2EplCw’
‘~/tmp/scratch/Rtmp2ZuKxW’ ‘~/tmp/scratch/Rtmp31TrT5’
‘~/tmp/scratch/Rtmp3Jmbut’ ‘~/tmp/scratch/Rtmp3NBFuu’
‘~/tmp/scratch/Rtmp3PXYGP’ ‘~/tmp/scratch/Rtmp3kxGra’
‘~/tmp/scratch/Rtmp3ph3AM’ ‘~/tmp/scratch/Rtmp4G18Dp’
‘~/tmp/scratch/Rtmp4HPI1A’ ‘~/tmp/scratch/Rtmp4LerwO’
‘~/tmp/scratch/Rtmp4QxKCn’ ‘~/tmp/scratch/Rtmp4b9lSV’
‘~/tmp/scratch/Rtmp4rdlMl’ ‘~/tmp/scratch/Rtmp4tip8p’
‘~/tmp/scratch/Rtmp560Uom’ ‘~/tmp/scratch/Rtmp5q1iZh’
‘~/tmp/scratch/Rtmp64HJQF’ ‘~/tmp/scratch/Rtmp6h1N4Z’
‘~/tmp/scratch/Rtmp6o0vks’ ‘~/tmp/scratch/Rtmp7QP1ua’
‘~/tmp/scratch/Rtmp7eY0Hc’ ‘~/tmp/scratch/Rtmp7fqv0C’
‘~/tmp/scratch/RtmpA1a7H8’ ‘~/tmp/scratch/RtmpACPhSE’
‘~/tmp/scratch/RtmpASiHtY’ ‘~/tmp/scratch/RtmpAeRRuE’
‘~/tmp/scratch/RtmpAo18sy’ ‘~/tmp/scratch/RtmpB2ywTd’
‘~/tmp/scratch/RtmpBE6lMg’ ‘~/tmp/scratch/RtmpBLJYwj’
‘~/tmp/scratch/RtmpBXOxLI’ ‘~/tmp/scratch/RtmpBa5bXj’
‘~/tmp/scratch/RtmpCQFwM8’ ‘~/tmp/scratch/RtmpCgva6z’
‘~/tmp/scratch/RtmpD49vT4’ ‘~/tmp/scratch/RtmpDBdU5d’
‘~/tmp/scratch/RtmpDINeFy’ ‘~/tmp/scratch/RtmpEEhjVj’
‘~/tmp/scratch/RtmpEJA5zY’ ‘~/tmp/scratch/RtmpEPH2k2’
‘~/tmp/scratch/RtmpF0fXl8’ ‘~/tmp/scratch/RtmpFFbRFQ’
‘~/tmp/scratch/RtmpFHtjA7’ ‘~/tmp/scratch/RtmpGpSFvf’
‘~/tmp/scratch/RtmpJc9nGa’ ‘~/tmp/scratch/RtmpK1ZdKh’
‘~/tmp/scratch/RtmpKQjNCT’ ‘~/tmp/scratch/RtmpLGXErH’
‘~/tmp/scratch/RtmpLWOxsC’ ‘~/tmp/scratch/RtmpLwhPF3’
‘~/tmp/scratch/RtmpLxrrzI’ ‘~/tmp/scratch/RtmpMJCBgd’
‘~/tmp/scratch/RtmpMLXrre’ ‘~/tmp/scratch/RtmpMpa43G’
‘~/tmp/scratch/RtmpNRdJFe’ ‘~/tmp/scratch/RtmpNiCGCL’
‘~/tmp/scratch/RtmpOL9cWl’ ‘~/tmp/scratch/RtmpOQfacK’
‘~/tmp/scratch/RtmpOZgFA4’ ‘~/tmp/scratch/RtmpOfKAQm’
‘~/tmp/scratch/RtmpQOYj0x’ ‘~/tmp/scratch/RtmpR6I2bv’
‘~/tmp/scratch/RtmpRBjWiX’ ‘~/tmp/scratch/RtmpRORDvj’
‘~/tmp/scratch/RtmpST9hLD’ ‘~/tmp/scratch/RtmpSfWkKn’
‘~/tmp/scratch/RtmpSwI4Zo’ ‘~/tmp/scratch/RtmpT64tBp’
‘~/tmp/scratch/RtmpTOHJ4g’ ‘~/tmp/scratch/RtmpTQZqFO’
‘~/tmp/scratch/RtmpTbijIJ’ ‘~/tmp/scratch/RtmpTciYxJ’
‘~/tmp/scratch/RtmpTd0Pq7’ ‘~/tmp/scratch/RtmpUHskL9’
‘~/tmp/scratch/RtmpUwgVnj’ ‘~/tmp/scratch/RtmpUy3Xn9’
‘~/tmp/scratch/RtmpVLr5FT’ ‘~/tmp/scratch/RtmpVr0ugB’
‘~/tmp/scratch/RtmpWIGzT1’ ‘~/tmp/scratch/RtmpWifffB’
‘~/tmp/scratch/RtmpWrPo71’ ‘~/tmp/scratch/RtmpWsr5tM’
‘~/tmp/scratch/RtmpX1j3e0’ ‘~/tmp/scratch/RtmpXHQvMV’
‘~/tmp/scratch/RtmpXRCGKY’ ‘~/tmp/scratch/RtmpXf9HxX’
‘~/tmp/scratch/RtmpYIuOUF’ ‘~/tmp/scratch/RtmpYOLF2N’
‘~/tmp/scratch/RtmpYUiZwB’ ‘~/tmp/scratch/RtmpYmU9lv’
‘~/tmp/scratch/RtmpYmqHU1’ ‘~/tmp/scratch/RtmpZcfbI1’
‘~/tmp/scratch/Rtmpb6Y4xB’ ‘~/tmp/scratch/RtmpbLGWrw’
‘~/tmp/scratch/Rtmpbltv3Q’ ‘~/tmp/scratch/Rtmpbo5W7E’
‘~/tmp/scratch/RtmpbvOQ8t’ ‘~/tmp/scratch/RtmpcMMfCb’
‘~/tmp/scratch/RtmpcSQOp1’ ‘~/tmp/scratch/Rtmpck2pao’
‘~/tmp/scratch/Rtmpco9dFw’ ‘~/tmp/scratch/RtmpdBO52b’
‘~/tmp/scratch/RtmpdY7vp8’ ‘~/tmp/scratch/Rtmpdi9ljE’
‘~/tmp/scratch/Rtmped84NF’ ‘~/tmp/scratch/RtmpedCZQw’
‘~/tmp/scratch/RtmpekAb7G’ ‘~/tmp/scratch/RtmpekSZzj’
‘~/tmp/scratch/Rtmpf48y50’ ‘~/tmp/scratch/Rtmpf5PNby’
‘~/tmp/scratch/RtmpfKTXXZ’ ‘~/tmp/scratch/RtmpfXtY90’
‘~/tmp/scratch/RtmpfkM93s’ ‘~/tmp/scratch/RtmpfoAbxI’
‘~/tmp/scratch/RtmpfsHFGG’ ‘~/tmp/scratch/RtmpghWYds’
‘~/tmp/scratch/Rtmphf7FcQ’ ‘~/tmp/scratch/RtmpiTg56b’
‘~/tmp/scratch/Rtmpj709uW’ ‘~/tmp/scratch/RtmpjOb3jf’
‘~/tmp/scratch/RtmpjbE8oK’ ‘~/tmp/scratch/RtmpjsjSoX’
‘~/tmp/scratch/Rtmpk9l0Ip’ ‘~/tmp/scratch/Rtmpkuc8iw’
‘~/tmp/scratch/RtmplH04Ic’ ‘~/tmp/scratch/RtmplRKcq0’
‘~/tmp/scratch/Rtmpm27ajV’ ‘~/tmp/scratch/RtmpmFEhN4’
‘~/tmp/scratch/RtmpmSMaS7’ ‘~/tmp/scratch/RtmpmfBiLn’
‘~/tmp/scratch/Rtmpn3FZGF’ ‘~/tmp/scratch/Rtmpnn1bb9’
‘~/tmp/scratch/RtmpnoS27c’ ‘~/tmp/scratch/Rtmpo6QAtx’
‘~/tmp/scratch/RtmpoTdhaU’ ‘~/tmp/scratch/RtmpoZxc5D’
‘~/tmp/scratch/RtmpoaOdDV’ ‘~/tmp/scratch/Rtmpon1yeu’
‘~/tmp/scratch/Rtmpp9JOSU’ ‘~/tmp/scratch/RtmppG0f5C’
‘~/tmp/scratch/RtmppLEDMV’ ‘~/tmp/scratch/RtmpphYxdR’
‘~/tmp/scratch/RtmpplpnPE’ ‘~/tmp/scratch/Rtmpq6dKon’
‘~/tmp/scratch/RtmpqP7iCu’ ‘~/tmp/scratch/RtmprEmygX’
‘~/tmp/scratch/RtmprruNXL’ ‘~/tmp/scratch/RtmprwSngI’
‘~/tmp/scratch/RtmpsAmJ8V’ ‘~/tmp/scratch/RtmpsGJMwR’
‘~/tmp/scratch/RtmpsPXjP8’ ‘~/tmp/scratch/RtmpsfwFWH’
‘~/tmp/scratch/RtmptIqKHk’ ‘~/tmp/scratch/RtmpteOWE1’
‘~/tmp/scratch/Rtmpts3vIx’ ‘~/tmp/scratch/RtmpuiX5tp’
‘~/tmp/scratch/RtmpvA928e’ ‘~/tmp/scratch/RtmpvGa5jf’
‘~/tmp/scratch/RtmpvroWNY’ ‘~/tmp/scratch/RtmpwcFm29’
‘~/tmp/scratch/Rtmpy1JuES’ ‘~/tmp/scratch/RtmpyssybZ’
‘~/tmp/scratch/Rtmpz4FZFb’ ‘~/tmp/scratch/Rtmpz4ZVhc’
‘~/tmp/scratch/Rtmpz6Vrgp’ ‘~/tmp/scratch/RtmpzAVy36’
‘~/tmp/scratch/RtmpzGmq9K’ ‘~/tmp/scratch/arJjEWh5’
‘~/tmp/scratch/xvfb-run.1eUMUe’ ‘~/tmp/scratch/xvfb-run.4RChcH’
‘~/tmp/scratch/xvfb-run.5CUN5w’ ‘~/tmp/scratch/xvfb-run.5r273y’
‘~/tmp/scratch/xvfb-run.7eLdof’ ‘~/tmp/scratch/xvfb-run.7kRybO’
‘~/tmp/scratch/xvfb-run.8EssDI’ ‘~/tmp/scratch/xvfb-run.AM1yfG’
‘~/tmp/scratch/xvfb-run.BNgQXv’ ‘~/tmp/scratch/xvfb-run.BmO1sd’
‘~/tmp/scratch/xvfb-run.CS7EJv’ ‘~/tmp/scratch/xvfb-run.CrlYl2’
‘~/tmp/scratch/xvfb-run.DHaQT7’ ‘~/tmp/scratch/xvfb-run.Dprusz’
‘~/tmp/scratch/xvfb-run.FUENV9’ ‘~/tmp/scratch/xvfb-run.FrhQxX’
‘~/tmp/scratch/xvfb-run.G4nRC0’ ‘~/tmp/scratch/xvfb-run.GQguee’
‘~/tmp/scratch/xvfb-run.Ht1DkE’ ‘~/tmp/scratch/xvfb-run.IOEv94’
‘~/tmp/scratch/xvfb-run.JhHA0U’ ‘~/tmp/scratch/xvfb-run.L1HsrC’
‘~/tmp/scratch/xvfb-run.LE0hwa’ ‘~/tmp/scratch/xvfb-run.LJZbXw’
‘~/tmp/scratch/xvfb-run.LOA33B’ ‘~/tmp/scratch/xvfb-run.LimOz6’
‘~/tmp/scratch/xvfb-run.MU65zC’ ‘~/tmp/scratch/xvfb-run.N360Ne’
‘~/tmp/scratch/xvfb-run.NCzteW’ ‘~/tmp/scratch/xvfb-run.NGlV2K’
‘~/tmp/scratch/xvfb-run.P3qIpr’ ‘~/tmp/scratch/xvfb-run.PAK0N2’
‘~/tmp/scratch/xvfb-run.QwsQAP’ ‘~/tmp/scratch/xvfb-run.QycRyC’
‘~/tmp/scratch/xvfb-run.RwL2cV’ ‘~/tmp/scratch/xvfb-run.S9MVAT’
‘~/tmp/scratch/xvfb-run.SbmXUW’ ‘~/tmp/scratch/xvfb-run.SgAnSj’
‘~/tmp/scratch/xvfb-run.TD9R7v’ ‘~/tmp/scratch/xvfb-run.VTO59K’
‘~/tmp/scratch/xvfb-run.XDbXyw’ ‘~/tmp/scratch/xvfb-run.XKlOGX’
‘~/tmp/scratch/xvfb-run.XvjGUF’ ‘~/tmp/scratch/xvfb-run.YGUGpr’
‘~/tmp/scratch/xvfb-run.YzwzVw’ ‘~/tmp/scratch/xvfb-run.aJEAfb’
‘~/tmp/scratch/xvfb-run.bVwWNk’ ‘~/tmp/scratch/xvfb-run.bykia7’
‘~/tmp/scratch/xvfb-run.cJxYH4’ ‘~/tmp/scratch/xvfb-run.czfEJi’
‘~/tmp/scratch/xvfb-run.dPocec’ ‘~/tmp/scratch/xvfb-run.e9M9VH’
‘~/tmp/scratch/xvfb-run.fKfgG3’ ‘~/tmp/scratch/xvfb-run.gKYPck’
‘~/tmp/scratch/xvfb-run.gMOyGZ’ ‘~/tmp/scratch/xvfb-run.gzefqw’
‘~/tmp/scratch/xvfb-run.hSRqA7’ ‘~/tmp/scratch/xvfb-run.hg3czB’
‘~/tmp/scratch/xvfb-run.pEvc3a’ ‘~/tmp/scratch/xvfb-run.pZJEMe’
‘~/tmp/scratch/xvfb-run.psayls’ ‘~/tmp/scratch/xvfb-run.qlxMrn’
‘~/tmp/scratch/xvfb-run.qxliQf’ ‘~/tmp/scratch/xvfb-run.sTqrxU’
‘~/tmp/scratch/xvfb-run.umXCNK’ ‘~/tmp/scratch/xvfb-run.v4MFAa’
‘~/tmp/scratch/xvfb-run.vY7IZ0’ ‘~/tmp/scratch/xvfb-run.w66BQb’
‘~/tmp/scratch/xvfb-run.x21xq6’ ‘~/tmp/scratch/xvfb-run.x7Bu3I’
‘~/tmp/scratch/xvfb-run.xArxcy’ ‘~/tmp/scratch/xvfb-run.xVAoQZ’
‘~/tmp/scratch/xvfb-run.y8vtZL’ ‘~/tmp/scratch/xvfb-run.yUnFNs’
‘~/tmp/scratch/xvfb-run.yUoQXE’ ‘~/tmp/scratch/xvfb-run.yjs0eu’
‘~/tmp/scratch/xvfb-run.zIsugi’ ‘~/tmp/scratch/xvfb-run.zy7qoP’
‘/dev/shm/sm_segment.gimli1.1001.10070000.0’
‘/dev/shm/sm_segment.gimli1.1001.22f60000.0’
‘/dev/shm/sm_segment.gimli1.1001.26c00000.0’
‘/dev/shm/sm_segment.gimli1.1001.26ff0000.0’
‘/dev/shm/sm_segment.gimli1.1001.30890000.0’
‘/dev/shm/sm_segment.gimli1.1001.322e0000.0’
‘/dev/shm/sm_segment.gimli1.1001.38070000.0’
‘/dev/shm/sm_segment.gimli1.1001.3b6f0000.0’
‘/dev/shm/sm_segment.gimli1.1001.3b8f0000.0’
‘/dev/shm/sm_segment.gimli1.1001.3c140000.0’
‘/dev/shm/sm_segment.gimli1.1001.3ff50000.0’
‘/dev/shm/sm_segment.gimli1.1001.44f0000.0’
‘/dev/shm/sm_segment.gimli1.1001.45cc0000.0’
‘/dev/shm/sm_segment.gimli1.1001.46470000.0’
‘/dev/shm/sm_segment.gimli1.1001.50000000.0’
‘/dev/shm/sm_segment.gimli1.1001.5f2c0000.0’
‘/dev/shm/sm_segment.gimli1.1001.63820000.0’
‘/dev/shm/sm_segment.gimli1.1001.6a740000.0’
‘/dev/shm/sm_segment.gimli1.1001.6c6d0000.0’
‘/dev/shm/sm_segment.gimli1.1001.6d400000.0’
‘/dev/shm/sm_segment.gimli1.1001.701d0000.0’
‘/dev/shm/sm_segment.gimli1.1001.708b0000.0’
‘/dev/shm/sm_segment.gimli1.1001.78e60000.0’
‘/dev/shm/sm_segment.gimli1.1001.7b890000.0’
‘/dev/shm/sm_segment.gimli1.1001.81ee0000.0’
‘/dev/shm/sm_segment.gimli1.1001.81f40000.0’
‘/dev/shm/sm_segment.gimli1.1001.83990000.0’
‘/dev/shm/sm_segment.gimli1.1001.85930000.0’
‘/dev/shm/sm_segment.gimli1.1001.88930000.0’
‘/dev/shm/sm_segment.gimli1.1001.8c130000.0’
‘/dev/shm/sm_segment.gimli1.1001.8c230000.0’
‘/dev/shm/sm_segment.gimli1.1001.8e950000.0’
‘/dev/shm/sm_segment.gimli1.1001.94100000.0’
‘/dev/shm/sm_segment.gimli1.1001.a79b0000.0’
‘/dev/shm/sm_segment.gimli1.1001.abc0000.0’
‘/dev/shm/sm_segment.gimli1.1001.afbb0000.0’
‘/dev/shm/sm_segment.gimli1.1001.ba590000.0’
‘/dev/shm/sm_segment.gimli1.1001.bb7d0000.0’
‘/dev/shm/sm_segment.gimli1.1001.c42a0000.0’
‘/dev/shm/sm_segment.gimli1.1001.c55f0000.0’
‘/dev/shm/sm_segment.gimli1.1001.d7970000.0’
‘/dev/shm/sm_segment.gimli1.1001.d8570000.0’
‘/dev/shm/sm_segment.gimli1.1001.debd0000.0’
‘/dev/shm/sm_segment.gimli1.1001.def10000.0’
‘/dev/shm/sm_segment.gimli1.1001.f4a70000.0’
‘~/.cache/pocl/uncached/tempfile_1kSXKx’
‘~/.cache/pocl/uncached/tempfile_2xKvxd’
‘~/.cache/pocl/uncached/tempfile_3OJ8Ci’
‘~/.cache/pocl/uncached/tempfile_471EO9’
‘~/.cache/pocl/uncached/tempfile_5Kcl8Q’
‘~/.cache/pocl/uncached/tempfile_63COGf’
‘~/.cache/pocl/uncached/tempfile_6U8bES’
‘~/.cache/pocl/uncached/tempfile_6fHwTS’
‘~/.cache/pocl/uncached/tempfile_8jpYsF’
‘~/.cache/pocl/uncached/tempfile_8vNeGB’
‘~/.cache/pocl/uncached/tempfile_99twut’
‘~/.cache/pocl/uncached/tempfile_9quShi’
‘~/.cache/pocl/uncached/tempfile_BC8jo1’
‘~/.cache/pocl/uncached/tempfile_CVtTyO’
‘~/.cache/pocl/uncached/tempfile_EM82lW’
‘~/.cache/pocl/uncached/tempfile_GsP4ZF’
‘~/.cache/pocl/uncached/tempfile_I9d2j2’
‘~/.cache/pocl/uncached/tempfile_KRZoXU’
‘~/.cache/pocl/uncached/tempfile_L8mi8K’
‘~/.cache/pocl/uncached/tempfile_NgAZd9’
‘~/.cache/pocl/uncached/tempfile_OhhSYk’
‘~/.cache/pocl/uncached/tempfile_OvaVRF’
‘~/.cache/pocl/uncached/tempfile_PJMDrU’
‘~/.cache/pocl/uncached/tempfile_QYJ8OB’
‘~/.cache/pocl/uncached/tempfile_QiRkMp’
‘~/.cache/pocl/uncached/tempfile_RJ4tpd’
‘~/.cache/pocl/uncached/tempfile_SeZpkT’
‘~/.cache/pocl/uncached/tempfile_TjVsC9’
‘~/.cache/pocl/uncached/tempfile_V2pSEN’
‘~/.cache/pocl/uncached/tempfile_bXCNj9’
‘~/.cache/pocl/uncached/tempfile_cDQDFN’
‘~/.cache/pocl/uncached/tempfile_cFchav’
‘~/.cache/pocl/uncached/tempfile_derkBF’
‘~/.cache/pocl/uncached/tempfile_e8VNsz’
‘~/.cache/pocl/uncached/tempfile_exZRkU’
‘~/.cache/pocl/uncached/tempfile_hro8XR’
‘~/.cache/pocl/uncached/tempfile_kWeVDQ’
‘~/.cache/pocl/uncached/tempfile_nC4BH7’
‘~/.cache/pocl/uncached/tempfile_p8Yjjw’
‘~/.cache/pocl/uncached/tempfile_pe2KYh’
‘~/.cache/pocl/uncached/tempfile_ph1qlh’
‘~/.cache/pocl/uncached/tempfile_pyxsxW’
‘~/.cache/pocl/uncached/tempfile_qnaU15’
‘~/.cache/pocl/uncached/tempfile_rI4H9y’
‘~/.cache/pocl/uncached/tempfile_yFqBod’
‘~/.cache/pocl/uncached/tempfile_yRHPJh’
Flavor: r-devel-linux-x86_64-debian-gcc
Version: 1.2-29
Check: examples
Result: ERROR
Running examples in ‘partykit-Ex.R’ failed
The error most likely occurred in:
> ### Name: glmtree
> ### Title: Generalized Linear Model Trees
> ### Aliases: glmtree plot.glmtree predict.glmtree print.glmtree
> ### Keywords: tree
>
> ### ** Examples
>
> if(require("mlbench") && require("vcd")) {
+
+ ## Pima Indians diabetes data
+ data("PimaIndiansDiabetes", package = "mlbench")
+
+ ## recursive partitioning of a logistic regression model
+ pid_tree2 <- glmtree(diabetes ~ glucose | pregnant +
+ pressure + triceps + insulin + mass + pedigree + age,
+ data = PimaIndiansDiabetes, family = binomial)
+
+ ## printing whole tree or individual nodes
+ print(pid_tree2)
+ print(pid_tree2, node = 1)
+
+ ## visualization
+ plot(pid_tree2)
+ plot(pid_tree2, tp_args = list(cdplot = TRUE))
+ plot(pid_tree2, terminal_panel = NULL)
+
+ ## estimated parameters
+ coef(pid_tree2)
+ coef(pid_tree2, node = 5)
+ summary(pid_tree2, node = 5)
+
+ ## deviance, log-likelihood and information criteria
+ deviance(pid_tree2)
+ logLik(pid_tree2)
+ AIC(pid_tree2)
+ BIC(pid_tree2)
+
+ ## different types of predictions
+ pid <- head(PimaIndiansDiabetes)
+ predict(pid_tree2, newdata = pid, type = "node")
+ predict(pid_tree2, newdata = pid, type = "response")
+ predict(pid_tree2, newdata = pid, type = "link")
+
+ }
Loading required package: mlbench
Loading required package: vcd
Warning in data("PimaIndiansDiabetes", package = "mlbench") :
data set ‘PimaIndiansDiabetes’ not found
Error in eval(mf, parent.frame()) :
object 'PimaIndiansDiabetes' not found
Calls: glmtree ... model.frame -> terms -> terms.Formula -> terms -> terms.formula
Execution halted
Flavors: r-devel-linux-x86_64-fedora-clang, r-devel-linux-x86_64-fedora-gcc, r-devel-windows-x86_64, r-release-windows-x86_64, r-oldrel-windows-x86_64
Version: 1.2-29
Check: tests
Result: ERROR
Running ‘bugfixes.R’ [9s/12s]
Comparing ‘bugfixes.Rout’ to ‘bugfixes.Rout.save’ ... OK
Running ‘constparty.R’ [9s/12s]
Comparing ‘constparty.Rout’ to ‘constparty.Rout.save’ ... OK
Running ‘regtest-MIA.R’
Comparing ‘regtest-MIA.Rout’ to ‘regtest-MIA.Rout.save’ ... OK
Running ‘regtest-cforest.R’ [21s/28s]
Comparing ‘regtest-cforest.Rout’ to ‘regtest-cforest.Rout.save’ ... OK
Running ‘regtest-ctree.R’
Comparing ‘regtest-ctree.Rout’ to ‘regtest-ctree.Rout.save’ ... OK
Running ‘regtest-glmtree.R’ [52s/58s]
Running ‘regtest-honesty.R’
Running ‘regtest-lmtree.R’
Running ‘regtest-nmax.R’
Comparing ‘regtest-nmax.Rout’ to ‘regtest-nmax.Rout.save’ ... OK
Running ‘regtest-node.R’
Comparing ‘regtest-node.Rout’ to ‘regtest-node.Rout.save’ ... OK
Running ‘regtest-party-random.R’
Running ‘regtest-party.R’
Comparing ‘regtest-party.Rout’ to ‘regtest-party.Rout.save’ ... OK
Running ‘regtest-split.R’
Comparing ‘regtest-split.Rout’ to ‘regtest-split.Rout.save’ ... OK
Running ‘regtest-weights.R’
Comparing ‘regtest-weights.Rout’ to ‘regtest-weights.Rout.save’ ... OK
Running the tests in ‘tests/regtest-glmtree.R’ failed.
Complete output:
> suppressWarnings(RNGversion("3.5.2"))
>
> library("partykit")
Loading required package: grid
Loading required package: libcoin
Loading required package: mvtnorm
>
> set.seed(29)
> n <- 1000
> x <- runif(n)
> z <- runif(n)
> y <- rnorm(n, mean = x * c(-1, 1)[(z > 0.7) + 1], sd = 3)
> z_noise <- factor(sample(1:3, size = n, replace = TRUE))
> d <- data.frame(y = y, x = x, z = z, z_noise = z_noise)
>
>
> fmla <- as.formula("y ~ x | z + z_noise")
> fmly <- gaussian()
> fit <- partykit:::glmfit
>
> # versions of the data
> d1 <- d
> d1$z <- signif(d1$z, digits = 1)
>
> k <- 20
> zs_noise <- matrix(rnorm(n*k), nrow = n)
> colnames(zs_noise) <- paste0("z_noise_", 1:k)
> d2 <- cbind(d, zs_noise)
> fmla2 <- as.formula(paste("y ~ x | z + z_noise +",
+ paste0("z_noise_", 1:k, collapse = " + ")))
>
>
> d3 <- d2
> d3$z <- factor(sample(1:3, size = n, replace = TRUE, prob = c(0.1, 0.5, 0.4)))
> d3$y <- rnorm(n, mean = x * c(-1, 1)[(d3$z == 2) + 1], sd = 3)
>
> ## check weights
> w <- rep(1, n)
> w[1:10] <- 2
> (mw1 <- glmtree(formula = fmla, data = d, weights = w))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 706
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 304
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
> (mw2 <- glmtree(formula = fmla, data = d, weights = w, caseweights = FALSE))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
>
>
>
> ## check dfsplit
> (mmfluc2 <- mob(formula = fmla, data = d, fit = partykit:::glmfit))
Model-based recursive partitioning (partykit:::glmfit)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function: 2551.673
> (mmfluc3 <- glmtree(formula = fmla, data = d))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
> (mmfluc3_dfsplit <- glmtree(formula = fmla, data = d, dfsplit = 10))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
>
> ## check tests
> if (require("strucchange"))
+ print(sctest(mmfluc3, node = 1)) # does not yet work
Loading required package: strucchange
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Loading required package: sandwich
z z_noise
statistic 2.292499e+01 0.6165335
p.value 7.780038e-04 0.9984952
>
> x <- mmfluc3
> (tst3 <- nodeapply(x, ids = nodeids(x), function(n) n$info$criterion))
$`1`
NULL
$`2`
NULL
$`3`
NULL
>
>
>
>
> ## check logLik and AIC
> logLik(mmfluc2)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3_dfsplit)
'log Lik.' -2551.673 (df=16)
> logLik(glm(y ~ x, data = d))
'log Lik.' -2563.694 (df=3)
>
> AIC(mmfluc3)
[1] 5117.347
> AIC(mmfluc3_dfsplit)
[1] 5135.347
>
> ## check pruning
> pr2 <- prune.modelparty(mmfluc2)
> AIC(mmfluc2)
[1] 5117.347
> AIC(pr2)
[1] 5117.347
>
> mmfluc_dfsplit3 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 3)
> mmfluc_dfsplit4 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 4)
> pr_dfsplit3 <- prune.modelparty(mmfluc_dfsplit3)
> pr_dfsplit4 <- prune.modelparty(mmfluc_dfsplit4)
> AIC(mmfluc_dfsplit3)
[1] 5142.774
> AIC(mmfluc_dfsplit4)
[1] 5156.774
> AIC(pr_dfsplit3)
[1] 5142.774
> AIC(pr_dfsplit4)
[1] 5124.456
>
> width(mmfluc_dfsplit3)
[1] 8
> width(mmfluc_dfsplit4)
[1] 8
> width(pr_dfsplit3)
[1] 8
> width(pr_dfsplit4)
[1] 3
>
> ## check inner and terminal
> options <- list(NULL,
+ "object",
+ "estfun",
+ c("object", "estfun"))
>
> arguments <- list("inner",
+ "terminal",
+ c("inner", "terminal"))
>
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, inner = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, terminal = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ NA: NULL
..$ NA: NULL
$ 3:List of 2
..$ NA: NULL
..$ NA: NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ NA : NULL
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ NA : NULL
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
>
>
> ## check model
> m_mt <- glmtree(formula = fmla, data = d, model = TRUE)
> m_mf <- glmtree(formula = fmla, data = d, model = FALSE)
>
> dim(m_mt$data)
[1] 1000 4
> dim(m_mf$data)
[1] 0 4
>
>
> ## check multiway
> (m_mult <- glmtree(formula = fmla2, data = d3, catsplit = "multiway", minsize = 80))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise + z_noise_1 + z_noise_2 + z_noise_3 + z_noise_4 +
z_noise_5 + z_noise_6 + z_noise_7 + z_noise_8 + z_noise_9 +
z_noise_10 + z_noise_11 + z_noise_12 + z_noise_13 + z_noise_14 +
z_noise_15 + z_noise_16 + z_noise_17 + z_noise_18 + z_noise_19 +
z_noise_20
Fitted party:
[1] root
| [2] z in 1: n = 76
| (Intercept) x
| 0.9859847 -3.2600047
| [3] z in 2: n = 537
| (Intercept) x
| -0.06970187 1.12305074
| [4] z in 3: n = 387
| (Intercept) x
| 0.3824392 -1.8337151
Number of inner nodes: 1
Number of terminal nodes: 3
Number of parameters per node: 2
Objective function (negative log-likelihood): 2511.927
>
>
> ## check parm
> fmla_p <- as.formula("y ~ x + z_noise + z_noise_1 | z + z_noise_2")
> (m_interc <- glmtree(formula = fmla_p, data = d2, parm = 1))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root
| [2] z <= 0.65035: n = 644
| (Intercept) x z_noise2 z_noise3 z_noise_1
| -0.05585503 -1.01257554 0.34044520 -0.16384987 0.24197601
| [3] z > 0.65035: n = 356
| (Intercept) x z_noise2 z_noise3 z_noise_1
| 0.06411865 0.78733976 -0.67811149 -0.14240432 -0.01239154
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 5
Objective function (negative log-likelihood): 2548.32
>
> (m_p3 <- glmtree(formula = fmla_p, data = d2, parm = 3))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root: n = 1000
(Intercept) x z_noise2 z_noise3 z_noise_1
-0.058855295 -0.340314311 -0.008404682 -0.109839080 0.154798281
Number of inner nodes: 0
Number of terminal nodes: 1
Number of parameters per node: 5
Objective function (negative log-likelihood): 2562.32
>
>
> ## check trim
> (m_tt <- glmtree(formula = fmla, data = d, trim = 0.2))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
> (m_tf <- glmtree(formula = fmla, data = d, trim = 300, minsize = 300))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.6892: n = 691
| (Intercept) x
| -0.1778199 -0.7692901
| [3] z > 0.6892: n = 309
| (Intercept) x
| 0.1065746 0.5562243
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2552.12
>
>
>
> ## check breakties
> m_bt <- glmtree(formula = fmla, data = d1, breakties = TRUE)
> m_df <- glmtree(formula = fmla, data = d1, breakties = FALSE)
>
> all.equal(m_bt, m_df, check.environment = FALSE)
[1] "Component \"node\": Component \"kids\": Component 1: Component 5: Component 6: Mean relative difference: 0.1237503"
[2] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 5: Mean relative difference: 0.1746109"
[3] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 6: Mean relative difference: 0.0443985"
[4] "Component \"node\": Component \"info\": Component \"p.value\": Mean relative difference: 1.100407"
[5] "Component \"node\": Component \"info\": Component \"test\": Mean relative difference: 0.07721086"
[6] "Component \"info\": Component \"call\": target, current do not match when deparsed"
[7] "Component \"info\": Component \"control\": Component \"breakties\": 1 element mismatch"
>
> unclass(m_bt)$node$info$criterion
NULL
> unclass(m_df)$node$info$criterion
NULL
>
> if (requireNamespace("mlbench")) {
+
+ ### example from mob vignette
+ data("PimaIndiansDiabetes", package = "mlbench")
+
+ logit <- function(y, x, start = NULL, weights = NULL, offset = NULL, ...) {
+ glm(y ~ 0 + x, family = binomial, start = start, ...)
+ }
+
+ pid_formula <- diabetes ~ glucose | pregnant + pressure + triceps +
+ insulin + mass + pedigree + age
+
+ pid_tree <- mob(pid_formula, data = PimaIndiansDiabetes, fit = logit)
+ print(pid_tree)
+ print(nodeapply(pid_tree, ids = nodeids(pid_tree), function(n) n$info$criterion))
+
+ }
Loading required namespace: mlbench
Error in eval(mf, parent.frame()) :
object 'PimaIndiansDiabetes' not found
Calls: mob ... model.frame -> terms -> terms.Formula -> terms -> terms.formula
In addition: Warning message:
In data("PimaIndiansDiabetes", package = "mlbench") :
data set 'PimaIndiansDiabetes' not found
Execution halted
Flavor: r-devel-linux-x86_64-fedora-clang
Version: 1.2-29
Check: re-building of vignette outputs
Result: ERROR
Error(s) in re-building vignettes:
--- re-building ‘constparty.Rnw’ using knitr
--- finished re-building ‘constparty.Rnw’
--- re-building ‘ctree.Rnw’ using knitr
--- finished re-building ‘ctree.Rnw’
--- re-building ‘mob.Rnw’ using knitr
Quitting from mob.Rnw:443-445 [PimaIndiansDiabetes-mob]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<error/rlang_error>
Error:
! object 'PimaIndiansDiabetes' not found
---
Backtrace:
x
1. +-stats::model.frame(...)
2. \-Formula:::model.frame.Formula(...)
3. +-stats::model.frame(...)
4. +-stats::terms(formula, lhs = lhs, rhs = rhs, data = data, dot = dot)
5. \-Formula:::terms.Formula(...)
6. +-stats::terms(form, ...)
7. \-stats::terms.formula(form, ...)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: processing vignette 'mob.Rnw' failed with diagnostics:
object 'PimaIndiansDiabetes' not found
--- failed re-building ‘mob.Rnw’
--- re-building ‘partykit.Rnw’ using knitr
--- finished re-building ‘partykit.Rnw’
SUMMARY: processing the following file failed:
‘mob.Rnw’
Error: Vignette re-building failed.
Execution halted
Flavors: r-devel-linux-x86_64-fedora-clang, r-devel-linux-x86_64-fedora-gcc, r-devel-windows-x86_64, r-release-windows-x86_64, r-oldrel-windows-x86_64
Version: 1.2-29
Check: tests
Result: ERROR
Running ‘bugfixes.R’
Comparing ‘bugfixes.Rout’ to ‘bugfixes.Rout.save’ ... OK
Running ‘constparty.R’
Comparing ‘constparty.Rout’ to ‘constparty.Rout.save’ ... OK
Running ‘regtest-MIA.R’
Comparing ‘regtest-MIA.Rout’ to ‘regtest-MIA.Rout.save’ ... OK
Running ‘regtest-cforest.R’ [8s/15s]
Comparing ‘regtest-cforest.Rout’ to ‘regtest-cforest.Rout.save’ ... OK
Running ‘regtest-ctree.R’
Comparing ‘regtest-ctree.Rout’ to ‘regtest-ctree.Rout.save’ ... OK
Running ‘regtest-glmtree.R’ [27s/51s]
Running ‘regtest-honesty.R’
Running ‘regtest-lmtree.R’
Running ‘regtest-nmax.R’
Comparing ‘regtest-nmax.Rout’ to ‘regtest-nmax.Rout.save’ ... OK
Running ‘regtest-node.R’
Comparing ‘regtest-node.Rout’ to ‘regtest-node.Rout.save’ ... OK
Running ‘regtest-party-random.R’
Running ‘regtest-party.R’
Comparing ‘regtest-party.Rout’ to ‘regtest-party.Rout.save’ ... OK
Running ‘regtest-split.R’
Comparing ‘regtest-split.Rout’ to ‘regtest-split.Rout.save’ ... OK
Running ‘regtest-weights.R’
Comparing ‘regtest-weights.Rout’ to ‘regtest-weights.Rout.save’ ... OK
Running the tests in ‘tests/regtest-glmtree.R’ failed.
Complete output:
> suppressWarnings(RNGversion("3.5.2"))
>
> library("partykit")
Loading required package: grid
Loading required package: libcoin
Loading required package: mvtnorm
>
> set.seed(29)
> n <- 1000
> x <- runif(n)
> z <- runif(n)
> y <- rnorm(n, mean = x * c(-1, 1)[(z > 0.7) + 1], sd = 3)
> z_noise <- factor(sample(1:3, size = n, replace = TRUE))
> d <- data.frame(y = y, x = x, z = z, z_noise = z_noise)
>
>
> fmla <- as.formula("y ~ x | z + z_noise")
> fmly <- gaussian()
> fit <- partykit:::glmfit
>
> # versions of the data
> d1 <- d
> d1$z <- signif(d1$z, digits = 1)
>
> k <- 20
> zs_noise <- matrix(rnorm(n*k), nrow = n)
> colnames(zs_noise) <- paste0("z_noise_", 1:k)
> d2 <- cbind(d, zs_noise)
> fmla2 <- as.formula(paste("y ~ x | z + z_noise +",
+ paste0("z_noise_", 1:k, collapse = " + ")))
>
>
> d3 <- d2
> d3$z <- factor(sample(1:3, size = n, replace = TRUE, prob = c(0.1, 0.5, 0.4)))
> d3$y <- rnorm(n, mean = x * c(-1, 1)[(d3$z == 2) + 1], sd = 3)
>
> ## check weights
> w <- rep(1, n)
> w[1:10] <- 2
> (mw1 <- glmtree(formula = fmla, data = d, weights = w))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 706
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 304
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
> (mw2 <- glmtree(formula = fmla, data = d, weights = w, caseweights = FALSE))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
>
>
>
> ## check dfsplit
> (mmfluc2 <- mob(formula = fmla, data = d, fit = partykit:::glmfit))
Model-based recursive partitioning (partykit:::glmfit)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function: 2551.673
> (mmfluc3 <- glmtree(formula = fmla, data = d))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
> (mmfluc3_dfsplit <- glmtree(formula = fmla, data = d, dfsplit = 10))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
>
> ## check tests
> if (require("strucchange"))
+ print(sctest(mmfluc3, node = 1)) # does not yet work
Loading required package: strucchange
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Loading required package: sandwich
z z_noise
statistic 2.292499e+01 0.6165335
p.value 7.780038e-04 0.9984952
>
> x <- mmfluc3
> (tst3 <- nodeapply(x, ids = nodeids(x), function(n) n$info$criterion))
$`1`
NULL
$`2`
NULL
$`3`
NULL
>
>
>
>
> ## check logLik and AIC
> logLik(mmfluc2)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3_dfsplit)
'log Lik.' -2551.673 (df=16)
> logLik(glm(y ~ x, data = d))
'log Lik.' -2563.694 (df=3)
>
> AIC(mmfluc3)
[1] 5117.347
> AIC(mmfluc3_dfsplit)
[1] 5135.347
>
> ## check pruning
> pr2 <- prune.modelparty(mmfluc2)
> AIC(mmfluc2)
[1] 5117.347
> AIC(pr2)
[1] 5117.347
>
> mmfluc_dfsplit3 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 3)
> mmfluc_dfsplit4 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 4)
> pr_dfsplit3 <- prune.modelparty(mmfluc_dfsplit3)
> pr_dfsplit4 <- prune.modelparty(mmfluc_dfsplit4)
> AIC(mmfluc_dfsplit3)
[1] 5142.774
> AIC(mmfluc_dfsplit4)
[1] 5156.774
> AIC(pr_dfsplit3)
[1] 5142.774
> AIC(pr_dfsplit4)
[1] 5124.456
>
> width(mmfluc_dfsplit3)
[1] 8
> width(mmfluc_dfsplit4)
[1] 8
> width(pr_dfsplit3)
[1] 8
> width(pr_dfsplit4)
[1] 3
>
> ## check inner and terminal
> options <- list(NULL,
+ "object",
+ "estfun",
+ c("object", "estfun"))
>
> arguments <- list("inner",
+ "terminal",
+ c("inner", "terminal"))
>
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, inner = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, terminal = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ NA: NULL
..$ NA: NULL
$ 3:List of 2
..$ NA: NULL
..$ NA: NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ NA : NULL
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ NA : NULL
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
>
>
> ## check model
> m_mt <- glmtree(formula = fmla, data = d, model = TRUE)
> m_mf <- glmtree(formula = fmla, data = d, model = FALSE)
>
> dim(m_mt$data)
[1] 1000 4
> dim(m_mf$data)
[1] 0 4
>
>
> ## check multiway
> (m_mult <- glmtree(formula = fmla2, data = d3, catsplit = "multiway", minsize = 80))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise + z_noise_1 + z_noise_2 + z_noise_3 + z_noise_4 +
z_noise_5 + z_noise_6 + z_noise_7 + z_noise_8 + z_noise_9 +
z_noise_10 + z_noise_11 + z_noise_12 + z_noise_13 + z_noise_14 +
z_noise_15 + z_noise_16 + z_noise_17 + z_noise_18 + z_noise_19 +
z_noise_20
Fitted party:
[1] root
| [2] z in 1: n = 76
| (Intercept) x
| 0.9859847 -3.2600047
| [3] z in 2: n = 537
| (Intercept) x
| -0.06970187 1.12305074
| [4] z in 3: n = 387
| (Intercept) x
| 0.3824392 -1.8337151
Number of inner nodes: 1
Number of terminal nodes: 3
Number of parameters per node: 2
Objective function (negative log-likelihood): 2511.927
>
>
> ## check parm
> fmla_p <- as.formula("y ~ x + z_noise + z_noise_1 | z + z_noise_2")
> (m_interc <- glmtree(formula = fmla_p, data = d2, parm = 1))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root
| [2] z <= 0.65035: n = 644
| (Intercept) x z_noise2 z_noise3 z_noise_1
| -0.05585503 -1.01257554 0.34044520 -0.16384987 0.24197601
| [3] z > 0.65035: n = 356
| (Intercept) x z_noise2 z_noise3 z_noise_1
| 0.06411865 0.78733976 -0.67811149 -0.14240432 -0.01239154
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 5
Objective function (negative log-likelihood): 2548.32
>
> (m_p3 <- glmtree(formula = fmla_p, data = d2, parm = 3))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root: n = 1000
(Intercept) x z_noise2 z_noise3 z_noise_1
-0.058855295 -0.340314311 -0.008404682 -0.109839080 0.154798281
Number of inner nodes: 0
Number of terminal nodes: 1
Number of parameters per node: 5
Objective function (negative log-likelihood): 2562.32
>
>
> ## check trim
> (m_tt <- glmtree(formula = fmla, data = d, trim = 0.2))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
> (m_tf <- glmtree(formula = fmla, data = d, trim = 300, minsize = 300))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.6892: n = 691
| (Intercept) x
| -0.1778199 -0.7692901
| [3] z > 0.6892: n = 309
| (Intercept) x
| 0.1065746 0.5562243
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2552.12
>
>
>
> ## check breakties
> m_bt <- glmtree(formula = fmla, data = d1, breakties = TRUE)
> m_df <- glmtree(formula = fmla, data = d1, breakties = FALSE)
>
> all.equal(m_bt, m_df, check.environment = FALSE)
[1] "Component \"node\": Component \"kids\": Component 1: Component 5: Component 6: Mean relative difference: 0.1237503"
[2] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 5: Mean relative difference: 0.1746109"
[3] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 6: Mean relative difference: 0.0443985"
[4] "Component \"node\": Component \"info\": Component \"p.value\": Mean relative difference: 1.100407"
[5] "Component \"node\": Component \"info\": Component \"test\": Mean relative difference: 0.07721086"
[6] "Component \"info\": Component \"call\": target, current do not match when deparsed"
[7] "Component \"info\": Component \"control\": Component \"breakties\": 1 element mismatch"
>
> unclass(m_bt)$node$info$criterion
NULL
> unclass(m_df)$node$info$criterion
NULL
>
> if (requireNamespace("mlbench")) {
+
+ ### example from mob vignette
+ data("PimaIndiansDiabetes", package = "mlbench")
+
+ logit <- function(y, x, start = NULL, weights = NULL, offset = NULL, ...) {
+ glm(y ~ 0 + x, family = binomial, start = start, ...)
+ }
+
+ pid_formula <- diabetes ~ glucose | pregnant + pressure + triceps +
+ insulin + mass + pedigree + age
+
+ pid_tree <- mob(pid_formula, data = PimaIndiansDiabetes, fit = logit)
+ print(pid_tree)
+ print(nodeapply(pid_tree, ids = nodeids(pid_tree), function(n) n$info$criterion))
+
+ }
Loading required namespace: mlbench
Error in eval(mf, parent.frame()) :
object 'PimaIndiansDiabetes' not found
Calls: mob ... model.frame -> terms -> terms.Formula -> terms -> terms.formula
In addition: Warning message:
In data("PimaIndiansDiabetes", package = "mlbench") :
data set 'PimaIndiansDiabetes' not found
Execution halted
Flavor: r-devel-linux-x86_64-fedora-gcc
Version: 1.2-29
Check: tests
Result: ERROR
Running 'bugfixes.R' [5s]
Comparing 'bugfixes.Rout' to 'bugfixes.Rout.save' ... OK
Running 'constparty.R' [5s]
Comparing 'constparty.Rout' to 'constparty.Rout.save' ... OK
Running 'regtest-MIA.R' [2s]
Comparing 'regtest-MIA.Rout' to 'regtest-MIA.Rout.save' ... OK
Running 'regtest-cforest.R' [9s]
Comparing 'regtest-cforest.Rout' to 'regtest-cforest.Rout.save' ... OK
Running 'regtest-ctree.R' [2s]
Comparing 'regtest-ctree.Rout' to 'regtest-ctree.Rout.save' ... OK
Running 'regtest-glmtree.R' [45s]
Running 'regtest-honesty.R' [2s]
Running 'regtest-lmtree.R' [3s]
Running 'regtest-nmax.R' [2s]
Comparing 'regtest-nmax.Rout' to 'regtest-nmax.Rout.save' ... OK
Running 'regtest-node.R' [1s]
Comparing 'regtest-node.Rout' to 'regtest-node.Rout.save' ... OK
Running 'regtest-party-random.R' [2s]
Running 'regtest-party.R' [5s]
Comparing 'regtest-party.Rout' to 'regtest-party.Rout.save' ... OK
Running 'regtest-split.R' [2s]
Comparing 'regtest-split.Rout' to 'regtest-split.Rout.save' ... OK
Running 'regtest-weights.R' [2s]
Comparing 'regtest-weights.Rout' to 'regtest-weights.Rout.save' ... OK
Running the tests in 'tests/regtest-glmtree.R' failed.
Complete output:
> suppressWarnings(RNGversion("3.5.2"))
>
> library("partykit")
Loading required package: grid
Loading required package: libcoin
Loading required package: mvtnorm
>
> set.seed(29)
> n <- 1000
> x <- runif(n)
> z <- runif(n)
> y <- rnorm(n, mean = x * c(-1, 1)[(z > 0.7) + 1], sd = 3)
> z_noise <- factor(sample(1:3, size = n, replace = TRUE))
> d <- data.frame(y = y, x = x, z = z, z_noise = z_noise)
>
>
> fmla <- as.formula("y ~ x | z + z_noise")
> fmly <- gaussian()
> fit <- partykit:::glmfit
>
> # versions of the data
> d1 <- d
> d1$z <- signif(d1$z, digits = 1)
>
> k <- 20
> zs_noise <- matrix(rnorm(n*k), nrow = n)
> colnames(zs_noise) <- paste0("z_noise_", 1:k)
> d2 <- cbind(d, zs_noise)
> fmla2 <- as.formula(paste("y ~ x | z + z_noise +",
+ paste0("z_noise_", 1:k, collapse = " + ")))
>
>
> d3 <- d2
> d3$z <- factor(sample(1:3, size = n, replace = TRUE, prob = c(0.1, 0.5, 0.4)))
> d3$y <- rnorm(n, mean = x * c(-1, 1)[(d3$z == 2) + 1], sd = 3)
>
> ## check weights
> w <- rep(1, n)
> w[1:10] <- 2
> (mw1 <- glmtree(formula = fmla, data = d, weights = w))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 706
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 304
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
> (mw2 <- glmtree(formula = fmla, data = d, weights = w, caseweights = FALSE))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
>
>
>
> ## check dfsplit
> (mmfluc2 <- mob(formula = fmla, data = d, fit = partykit:::glmfit))
Model-based recursive partitioning (partykit:::glmfit)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function: 2551.673
> (mmfluc3 <- glmtree(formula = fmla, data = d))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
> (mmfluc3_dfsplit <- glmtree(formula = fmla, data = d, dfsplit = 10))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
>
> ## check tests
> if (require("strucchange"))
+ print(sctest(mmfluc3, node = 1)) # does not yet work
Loading required package: strucchange
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Loading required package: sandwich
z z_noise
statistic 2.292499e+01 0.6165335
p.value 7.780038e-04 0.9984952
>
> x <- mmfluc3
> (tst3 <- nodeapply(x, ids = nodeids(x), function(n) n$info$criterion))
$`1`
NULL
$`2`
NULL
$`3`
NULL
>
>
>
>
> ## check logLik and AIC
> logLik(mmfluc2)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3_dfsplit)
'log Lik.' -2551.673 (df=16)
> logLik(glm(y ~ x, data = d))
'log Lik.' -2563.694 (df=3)
>
> AIC(mmfluc3)
[1] 5117.347
> AIC(mmfluc3_dfsplit)
[1] 5135.347
>
> ## check pruning
> pr2 <- prune.modelparty(mmfluc2)
> AIC(mmfluc2)
[1] 5117.347
> AIC(pr2)
[1] 5117.347
>
> mmfluc_dfsplit3 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 3)
> mmfluc_dfsplit4 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 4)
> pr_dfsplit3 <- prune.modelparty(mmfluc_dfsplit3)
> pr_dfsplit4 <- prune.modelparty(mmfluc_dfsplit4)
> AIC(mmfluc_dfsplit3)
[1] 5142.774
> AIC(mmfluc_dfsplit4)
[1] 5156.774
> AIC(pr_dfsplit3)
[1] 5142.774
> AIC(pr_dfsplit4)
[1] 5124.456
>
> width(mmfluc_dfsplit3)
[1] 8
> width(mmfluc_dfsplit4)
[1] 8
> width(pr_dfsplit3)
[1] 8
> width(pr_dfsplit4)
[1] 3
>
> ## check inner and terminal
> options <- list(NULL,
+ "object",
+ "estfun",
+ c("object", "estfun"))
>
> arguments <- list("inner",
+ "terminal",
+ c("inner", "terminal"))
>
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, inner = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, terminal = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ NA: NULL
..$ NA: NULL
$ 3:List of 2
..$ NA: NULL
..$ NA: NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ NA : NULL
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ NA : NULL
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
>
>
> ## check model
> m_mt <- glmtree(formula = fmla, data = d, model = TRUE)
> m_mf <- glmtree(formula = fmla, data = d, model = FALSE)
>
> dim(m_mt$data)
[1] 1000 4
> dim(m_mf$data)
[1] 0 4
>
>
> ## check multiway
> (m_mult <- glmtree(formula = fmla2, data = d3, catsplit = "multiway", minsize = 80))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise + z_noise_1 + z_noise_2 + z_noise_3 + z_noise_4 +
z_noise_5 + z_noise_6 + z_noise_7 + z_noise_8 + z_noise_9 +
z_noise_10 + z_noise_11 + z_noise_12 + z_noise_13 + z_noise_14 +
z_noise_15 + z_noise_16 + z_noise_17 + z_noise_18 + z_noise_19 +
z_noise_20
Fitted party:
[1] root
| [2] z in 1: n = 76
| (Intercept) x
| 0.9859847 -3.2600047
| [3] z in 2: n = 537
| (Intercept) x
| -0.06970187 1.12305074
| [4] z in 3: n = 387
| (Intercept) x
| 0.3824392 -1.8337151
Number of inner nodes: 1
Number of terminal nodes: 3
Number of parameters per node: 2
Objective function (negative log-likelihood): 2511.927
>
>
> ## check parm
> fmla_p <- as.formula("y ~ x + z_noise + z_noise_1 | z + z_noise_2")
> (m_interc <- glmtree(formula = fmla_p, data = d2, parm = 1))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root
| [2] z <= 0.65035: n = 644
| (Intercept) x z_noise2 z_noise3 z_noise_1
| -0.05585503 -1.01257554 0.34044520 -0.16384987 0.24197601
| [3] z > 0.65035: n = 356
| (Intercept) x z_noise2 z_noise3 z_noise_1
| 0.06411865 0.78733976 -0.67811149 -0.14240432 -0.01239154
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 5
Objective function (negative log-likelihood): 2548.32
>
> (m_p3 <- glmtree(formula = fmla_p, data = d2, parm = 3))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root: n = 1000
(Intercept) x z_noise2 z_noise3 z_noise_1
-0.058855295 -0.340314311 -0.008404682 -0.109839080 0.154798281
Number of inner nodes: 0
Number of terminal nodes: 1
Number of parameters per node: 5
Objective function (negative log-likelihood): 2562.32
>
>
> ## check trim
> (m_tt <- glmtree(formula = fmla, data = d, trim = 0.2))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
> (m_tf <- glmtree(formula = fmla, data = d, trim = 300, minsize = 300))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.6892: n = 691
| (Intercept) x
| -0.1778199 -0.7692901
| [3] z > 0.6892: n = 309
| (Intercept) x
| 0.1065746 0.5562243
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2552.12
>
>
>
> ## check breakties
> m_bt <- glmtree(formula = fmla, data = d1, breakties = TRUE)
> m_df <- glmtree(formula = fmla, data = d1, breakties = FALSE)
>
> all.equal(m_bt, m_df, check.environment = FALSE)
[1] "Component \"node\": Component \"kids\": Component 1: Component 5: Component 6: Mean relative difference: 0.1237503"
[2] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 5: Mean relative difference: 0.1746109"
[3] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 6: Mean relative difference: 0.0443985"
[4] "Component \"node\": Component \"info\": Component \"p.value\": Mean relative difference: 1.100407"
[5] "Component \"node\": Component \"info\": Component \"test\": Mean relative difference: 0.07721086"
[6] "Component \"info\": Component \"call\": target, current do not match when deparsed"
[7] "Component \"info\": Component \"control\": Component \"breakties\": 1 element mismatch"
>
> unclass(m_bt)$node$info$criterion
NULL
> unclass(m_df)$node$info$criterion
NULL
>
> if (requireNamespace("mlbench")) {
+
+ ### example from mob vignette
+ data("PimaIndiansDiabetes", package = "mlbench")
+
+ logit <- function(y, x, start = NULL, weights = NULL, offset = NULL, ...) {
+ glm(y ~ 0 + x, family = binomial, start = start, ...)
+ }
+
+ pid_formula <- diabetes ~ glucose | pregnant + pressure + triceps +
+ insulin + mass + pedigree + age
+
+ pid_tree <- mob(pid_formula, data = PimaIndiansDiabetes, fit = logit)
+ print(pid_tree)
+ print(nodeapply(pid_tree, ids = nodeids(pid_tree), function(n) n$info$criterion))
+
+ }
Loading required namespace: mlbench
Error in eval(mf, parent.frame()) :
object 'PimaIndiansDiabetes' not found
Calls: mob ... model.frame -> terms -> terms.Formula -> terms -> terms.formula
In addition: Warning message:
In data("PimaIndiansDiabetes", package = "mlbench") :
data set 'PimaIndiansDiabetes' not found
Execution halted
Flavor: r-devel-windows-x86_64
Version: 1.2-29
Check: tests
Result: ERROR
Running ‘bugfixes.R’ [5s/7s]
Comparing ‘bugfixes.Rout’ to ‘bugfixes.Rout.save’ ... OK
Running ‘constparty.R’ [5s/7s]
Comparing ‘constparty.Rout’ to ‘constparty.Rout.save’ ... OK
Running ‘regtest-MIA.R’ [2s/4s]
Comparing ‘regtest-MIA.Rout’ to ‘regtest-MIA.Rout.save’ ... OK
Running ‘regtest-cforest.R’ [12s/15s]
Comparing ‘regtest-cforest.Rout’ to ‘regtest-cforest.Rout.save’ ... OK
Running ‘regtest-ctree.R’ [2s/3s]
Comparing ‘regtest-ctree.Rout’ to ‘regtest-ctree.Rout.save’ ... OK
Running ‘regtest-glmtree.R’ [33s/40s]
Running ‘regtest-honesty.R’ [2s/2s]
Running ‘regtest-lmtree.R’ [3s/3s]
Running ‘regtest-nmax.R’ [2s/2s]
Comparing ‘regtest-nmax.Rout’ to ‘regtest-nmax.Rout.save’ ... OK
Running ‘regtest-node.R’ [2s/3s]
Comparing ‘regtest-node.Rout’ to ‘regtest-node.Rout.save’ ... OK
Running ‘regtest-party-random.R’ [2s/3s]
Running ‘regtest-party.R’ [5s/5s]
Comparing ‘regtest-party.Rout’ to ‘regtest-party.Rout.save’ ... OK
Running ‘regtest-split.R’ [2s/2s]
Comparing ‘regtest-split.Rout’ to ‘regtest-split.Rout.save’ ... OK
Running ‘regtest-weights.R’ [2s/3s]
Comparing ‘regtest-weights.Rout’ to ‘regtest-weights.Rout.save’ ... OK
Running the tests in ‘tests/regtest-glmtree.R’ failed.
Complete output:
> suppressWarnings(RNGversion("3.5.2"))
>
> library("partykit")
Loading required package: grid
Loading required package: libcoin
Loading required package: mvtnorm
>
> set.seed(29)
> n <- 1000
> x <- runif(n)
> z <- runif(n)
> y <- rnorm(n, mean = x * c(-1, 1)[(z > 0.7) + 1], sd = 3)
> z_noise <- factor(sample(1:3, size = n, replace = TRUE))
> d <- data.frame(y = y, x = x, z = z, z_noise = z_noise)
>
>
> fmla <- as.formula("y ~ x | z + z_noise")
> fmly <- gaussian()
> fit <- partykit:::glmfit
>
> # versions of the data
> d1 <- d
> d1$z <- signif(d1$z, digits = 1)
>
> k <- 20
> zs_noise <- matrix(rnorm(n*k), nrow = n)
> colnames(zs_noise) <- paste0("z_noise_", 1:k)
> d2 <- cbind(d, zs_noise)
> fmla2 <- as.formula(paste("y ~ x | z + z_noise +",
+ paste0("z_noise_", 1:k, collapse = " + ")))
>
>
> d3 <- d2
> d3$z <- factor(sample(1:3, size = n, replace = TRUE, prob = c(0.1, 0.5, 0.4)))
> d3$y <- rnorm(n, mean = x * c(-1, 1)[(d3$z == 2) + 1], sd = 3)
>
> ## check weights
> w <- rep(1, n)
> w[1:10] <- 2
> (mw1 <- glmtree(formula = fmla, data = d, weights = w))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 706
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 304
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
> (mw2 <- glmtree(formula = fmla, data = d, weights = w, caseweights = FALSE))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
>
>
>
> ## check dfsplit
> (mmfluc2 <- mob(formula = fmla, data = d, fit = partykit:::glmfit))
Model-based recursive partitioning (partykit:::glmfit)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function: 2551.673
> (mmfluc3 <- glmtree(formula = fmla, data = d))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
> (mmfluc3_dfsplit <- glmtree(formula = fmla, data = d, dfsplit = 10))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
>
> ## check tests
> if (require("strucchange"))
+ print(sctest(mmfluc3, node = 1)) # does not yet work
Loading required package: strucchange
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Loading required package: sandwich
z z_noise
statistic 2.292499e+01 0.6165335
p.value 7.780038e-04 0.9984952
>
> x <- mmfluc3
> (tst3 <- nodeapply(x, ids = nodeids(x), function(n) n$info$criterion))
$`1`
NULL
$`2`
NULL
$`3`
NULL
>
>
>
>
> ## check logLik and AIC
> logLik(mmfluc2)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3_dfsplit)
'log Lik.' -2551.673 (df=16)
> logLik(glm(y ~ x, data = d))
'log Lik.' -2563.694 (df=3)
>
> AIC(mmfluc3)
[1] 5117.347
> AIC(mmfluc3_dfsplit)
[1] 5135.347
>
> ## check pruning
> pr2 <- prune.modelparty(mmfluc2)
> AIC(mmfluc2)
[1] 5117.347
> AIC(pr2)
[1] 5117.347
>
> mmfluc_dfsplit3 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 3)
> mmfluc_dfsplit4 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 4)
> pr_dfsplit3 <- prune.modelparty(mmfluc_dfsplit3)
> pr_dfsplit4 <- prune.modelparty(mmfluc_dfsplit4)
> AIC(mmfluc_dfsplit3)
[1] 5142.774
> AIC(mmfluc_dfsplit4)
[1] 5156.774
> AIC(pr_dfsplit3)
[1] 5142.774
> AIC(pr_dfsplit4)
[1] 5124.456
>
> width(mmfluc_dfsplit3)
[1] 8
> width(mmfluc_dfsplit4)
[1] 8
> width(pr_dfsplit3)
[1] 8
> width(pr_dfsplit4)
[1] 3
>
> ## check inner and terminal
> options <- list(NULL,
+ "object",
+ "estfun",
+ c("object", "estfun"))
>
> arguments <- list("inner",
+ "terminal",
+ c("inner", "terminal"))
>
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, inner = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, terminal = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ NA: NULL
..$ NA: NULL
$ 3:List of 2
..$ NA: NULL
..$ NA: NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ NA : NULL
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ NA : NULL
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
>
>
> ## check model
> m_mt <- glmtree(formula = fmla, data = d, model = TRUE)
> m_mf <- glmtree(formula = fmla, data = d, model = FALSE)
>
> dim(m_mt$data)
[1] 1000 4
> dim(m_mf$data)
[1] 0 4
>
>
> ## check multiway
> (m_mult <- glmtree(formula = fmla2, data = d3, catsplit = "multiway", minsize = 80))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise + z_noise_1 + z_noise_2 + z_noise_3 + z_noise_4 +
z_noise_5 + z_noise_6 + z_noise_7 + z_noise_8 + z_noise_9 +
z_noise_10 + z_noise_11 + z_noise_12 + z_noise_13 + z_noise_14 +
z_noise_15 + z_noise_16 + z_noise_17 + z_noise_18 + z_noise_19 +
z_noise_20
Fitted party:
[1] root
| [2] z in 1: n = 76
| (Intercept) x
| 0.9859847 -3.2600047
| [3] z in 2: n = 537
| (Intercept) x
| -0.06970187 1.12305074
| [4] z in 3: n = 387
| (Intercept) x
| 0.3824392 -1.8337151
Number of inner nodes: 1
Number of terminal nodes: 3
Number of parameters per node: 2
Objective function (negative log-likelihood): 2511.927
>
>
> ## check parm
> fmla_p <- as.formula("y ~ x + z_noise + z_noise_1 | z + z_noise_2")
> (m_interc <- glmtree(formula = fmla_p, data = d2, parm = 1))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root
| [2] z <= 0.65035: n = 644
| (Intercept) x z_noise2 z_noise3 z_noise_1
| -0.05585503 -1.01257554 0.34044520 -0.16384987 0.24197601
| [3] z > 0.65035: n = 356
| (Intercept) x z_noise2 z_noise3 z_noise_1
| 0.06411865 0.78733976 -0.67811149 -0.14240432 -0.01239154
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 5
Objective function (negative log-likelihood): 2548.32
>
> (m_p3 <- glmtree(formula = fmla_p, data = d2, parm = 3))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root: n = 1000
(Intercept) x z_noise2 z_noise3 z_noise_1
-0.058855295 -0.340314311 -0.008404682 -0.109839080 0.154798281
Number of inner nodes: 0
Number of terminal nodes: 1
Number of parameters per node: 5
Objective function (negative log-likelihood): 2562.32
>
>
> ## check trim
> (m_tt <- glmtree(formula = fmla, data = d, trim = 0.2))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
> (m_tf <- glmtree(formula = fmla, data = d, trim = 300, minsize = 300))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.6892: n = 691
| (Intercept) x
| -0.1778199 -0.7692901
| [3] z > 0.6892: n = 309
| (Intercept) x
| 0.1065746 0.5562243
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2552.12
>
>
>
> ## check breakties
> m_bt <- glmtree(formula = fmla, data = d1, breakties = TRUE)
> m_df <- glmtree(formula = fmla, data = d1, breakties = FALSE)
>
> all.equal(m_bt, m_df, check.environment = FALSE)
[1] "Component \"node\": Component \"kids\": Component 1: Component 5: Component 6: Mean relative difference: 0.1237503"
[2] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 5: Mean relative difference: 0.1746109"
[3] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 6: Mean relative difference: 0.0443985"
[4] "Component \"node\": Component \"info\": Component \"p.value\": Mean relative difference: 1.100407"
[5] "Component \"node\": Component \"info\": Component \"test\": Mean relative difference: 0.07721086"
[6] "Component \"info\": Component \"call\": target, current do not match when deparsed"
[7] "Component \"info\": Component \"control\": Component \"breakties\": 1 element mismatch"
>
> unclass(m_bt)$node$info$criterion
NULL
> unclass(m_df)$node$info$criterion
NULL
>
> if (requireNamespace("mlbench")) {
+
+ ### example from mob vignette
+ data("PimaIndiansDiabetes", package = "mlbench")
+
+ logit <- function(y, x, start = NULL, weights = NULL, offset = NULL, ...) {
+ glm(y ~ 0 + x, family = binomial, start = start, ...)
+ }
+
+ pid_formula <- diabetes ~ glucose | pregnant + pressure + triceps +
+ insulin + mass + pedigree + age
+
+ pid_tree <- mob(pid_formula, data = PimaIndiansDiabetes, fit = logit)
+ print(pid_tree)
+ print(nodeapply(pid_tree, ids = nodeids(pid_tree), function(n) n$info$criterion))
+
+ }
Loading required namespace: mlbench
Error in eval(mf, parent.frame()) :
object 'PimaIndiansDiabetes' not found
Calls: mob ... model.frame -> terms -> terms.Formula -> terms -> terms.formula
In addition: Warning message:
In data("PimaIndiansDiabetes", package = "mlbench") :
data set 'PimaIndiansDiabetes' not found
Execution halted
Flavor: r-patched-linux-x86_64
Version: 1.2-29
Check: tests
Result: ERROR
Running ‘bugfixes.R’ [5s/7s]
Comparing ‘bugfixes.Rout’ to ‘bugfixes.Rout.save’ ... OK
Running ‘constparty.R’ [5s/6s]
Comparing ‘constparty.Rout’ to ‘constparty.Rout.save’ ... OK
Running ‘regtest-MIA.R’ [2s/2s]
Comparing ‘regtest-MIA.Rout’ to ‘regtest-MIA.Rout.save’ ... OK
Running ‘regtest-cforest.R’ [12s/13s]
Comparing ‘regtest-cforest.Rout’ to ‘regtest-cforest.Rout.save’ ... OK
Running ‘regtest-ctree.R’ [2s/2s]
Comparing ‘regtest-ctree.Rout’ to ‘regtest-ctree.Rout.save’ ... OK
Running ‘regtest-glmtree.R’ [33s/40s]
Running ‘regtest-honesty.R’ [2s/3s]
Running ‘regtest-lmtree.R’ [3s/3s]
Running ‘regtest-nmax.R’ [2s/3s]
Comparing ‘regtest-nmax.Rout’ to ‘regtest-nmax.Rout.save’ ... OK
Running ‘regtest-node.R’ [2s/2s]
Comparing ‘regtest-node.Rout’ to ‘regtest-node.Rout.save’ ... OK
Running ‘regtest-party-random.R’ [2s/3s]
Running ‘regtest-party.R’ [5s/5s]
Comparing ‘regtest-party.Rout’ to ‘regtest-party.Rout.save’ ... OK
Running ‘regtest-split.R’ [2s/2s]
Comparing ‘regtest-split.Rout’ to ‘regtest-split.Rout.save’ ... OK
Running ‘regtest-weights.R’ [2s/3s]
Comparing ‘regtest-weights.Rout’ to ‘regtest-weights.Rout.save’ ... OK
Running the tests in ‘tests/regtest-glmtree.R’ failed.
Complete output:
> suppressWarnings(RNGversion("3.5.2"))
>
> library("partykit")
Loading required package: grid
Loading required package: libcoin
Loading required package: mvtnorm
>
> set.seed(29)
> n <- 1000
> x <- runif(n)
> z <- runif(n)
> y <- rnorm(n, mean = x * c(-1, 1)[(z > 0.7) + 1], sd = 3)
> z_noise <- factor(sample(1:3, size = n, replace = TRUE))
> d <- data.frame(y = y, x = x, z = z, z_noise = z_noise)
>
>
> fmla <- as.formula("y ~ x | z + z_noise")
> fmly <- gaussian()
> fit <- partykit:::glmfit
>
> # versions of the data
> d1 <- d
> d1$z <- signif(d1$z, digits = 1)
>
> k <- 20
> zs_noise <- matrix(rnorm(n*k), nrow = n)
> colnames(zs_noise) <- paste0("z_noise_", 1:k)
> d2 <- cbind(d, zs_noise)
> fmla2 <- as.formula(paste("y ~ x | z + z_noise +",
+ paste0("z_noise_", 1:k, collapse = " + ")))
>
>
> d3 <- d2
> d3$z <- factor(sample(1:3, size = n, replace = TRUE, prob = c(0.1, 0.5, 0.4)))
> d3$y <- rnorm(n, mean = x * c(-1, 1)[(d3$z == 2) + 1], sd = 3)
>
> ## check weights
> w <- rep(1, n)
> w[1:10] <- 2
> (mw1 <- glmtree(formula = fmla, data = d, weights = w))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 706
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 304
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
> (mw2 <- glmtree(formula = fmla, data = d, weights = w, caseweights = FALSE))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
>
>
>
> ## check dfsplit
> (mmfluc2 <- mob(formula = fmla, data = d, fit = partykit:::glmfit))
Model-based recursive partitioning (partykit:::glmfit)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function: 2551.673
> (mmfluc3 <- glmtree(formula = fmla, data = d))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
> (mmfluc3_dfsplit <- glmtree(formula = fmla, data = d, dfsplit = 10))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
>
> ## check tests
> if (require("strucchange"))
+ print(sctest(mmfluc3, node = 1)) # does not yet work
Loading required package: strucchange
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Loading required package: sandwich
z z_noise
statistic 2.292499e+01 0.6165335
p.value 7.780038e-04 0.9984952
>
> x <- mmfluc3
> (tst3 <- nodeapply(x, ids = nodeids(x), function(n) n$info$criterion))
$`1`
NULL
$`2`
NULL
$`3`
NULL
>
>
>
>
> ## check logLik and AIC
> logLik(mmfluc2)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3_dfsplit)
'log Lik.' -2551.673 (df=16)
> logLik(glm(y ~ x, data = d))
'log Lik.' -2563.694 (df=3)
>
> AIC(mmfluc3)
[1] 5117.347
> AIC(mmfluc3_dfsplit)
[1] 5135.347
>
> ## check pruning
> pr2 <- prune.modelparty(mmfluc2)
> AIC(mmfluc2)
[1] 5117.347
> AIC(pr2)
[1] 5117.347
>
> mmfluc_dfsplit3 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 3)
> mmfluc_dfsplit4 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 4)
> pr_dfsplit3 <- prune.modelparty(mmfluc_dfsplit3)
> pr_dfsplit4 <- prune.modelparty(mmfluc_dfsplit4)
> AIC(mmfluc_dfsplit3)
[1] 5142.774
> AIC(mmfluc_dfsplit4)
[1] 5156.774
> AIC(pr_dfsplit3)
[1] 5142.774
> AIC(pr_dfsplit4)
[1] 5124.456
>
> width(mmfluc_dfsplit3)
[1] 8
> width(mmfluc_dfsplit4)
[1] 8
> width(pr_dfsplit3)
[1] 8
> width(pr_dfsplit4)
[1] 3
>
> ## check inner and terminal
> options <- list(NULL,
+ "object",
+ "estfun",
+ c("object", "estfun"))
>
> arguments <- list("inner",
+ "terminal",
+ c("inner", "terminal"))
>
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, inner = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, terminal = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ NA: NULL
..$ NA: NULL
$ 3:List of 2
..$ NA: NULL
..$ NA: NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ NA : NULL
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ NA : NULL
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
>
>
> ## check model
> m_mt <- glmtree(formula = fmla, data = d, model = TRUE)
> m_mf <- glmtree(formula = fmla, data = d, model = FALSE)
>
> dim(m_mt$data)
[1] 1000 4
> dim(m_mf$data)
[1] 0 4
>
>
> ## check multiway
> (m_mult <- glmtree(formula = fmla2, data = d3, catsplit = "multiway", minsize = 80))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise + z_noise_1 + z_noise_2 + z_noise_3 + z_noise_4 +
z_noise_5 + z_noise_6 + z_noise_7 + z_noise_8 + z_noise_9 +
z_noise_10 + z_noise_11 + z_noise_12 + z_noise_13 + z_noise_14 +
z_noise_15 + z_noise_16 + z_noise_17 + z_noise_18 + z_noise_19 +
z_noise_20
Fitted party:
[1] root
| [2] z in 1: n = 76
| (Intercept) x
| 0.9859847 -3.2600047
| [3] z in 2: n = 537
| (Intercept) x
| -0.06970187 1.12305074
| [4] z in 3: n = 387
| (Intercept) x
| 0.3824392 -1.8337151
Number of inner nodes: 1
Number of terminal nodes: 3
Number of parameters per node: 2
Objective function (negative log-likelihood): 2511.927
>
>
> ## check parm
> fmla_p <- as.formula("y ~ x + z_noise + z_noise_1 | z + z_noise_2")
> (m_interc <- glmtree(formula = fmla_p, data = d2, parm = 1))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root
| [2] z <= 0.65035: n = 644
| (Intercept) x z_noise2 z_noise3 z_noise_1
| -0.05585503 -1.01257554 0.34044520 -0.16384987 0.24197601
| [3] z > 0.65035: n = 356
| (Intercept) x z_noise2 z_noise3 z_noise_1
| 0.06411865 0.78733976 -0.67811149 -0.14240432 -0.01239154
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 5
Objective function (negative log-likelihood): 2548.32
>
> (m_p3 <- glmtree(formula = fmla_p, data = d2, parm = 3))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root: n = 1000
(Intercept) x z_noise2 z_noise3 z_noise_1
-0.058855295 -0.340314311 -0.008404682 -0.109839080 0.154798281
Number of inner nodes: 0
Number of terminal nodes: 1
Number of parameters per node: 5
Objective function (negative log-likelihood): 2562.32
>
>
> ## check trim
> (m_tt <- glmtree(formula = fmla, data = d, trim = 0.2))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
> (m_tf <- glmtree(formula = fmla, data = d, trim = 300, minsize = 300))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.6892: n = 691
| (Intercept) x
| -0.1778199 -0.7692901
| [3] z > 0.6892: n = 309
| (Intercept) x
| 0.1065746 0.5562243
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2552.12
>
>
>
> ## check breakties
> m_bt <- glmtree(formula = fmla, data = d1, breakties = TRUE)
> m_df <- glmtree(formula = fmla, data = d1, breakties = FALSE)
>
> all.equal(m_bt, m_df, check.environment = FALSE)
[1] "Component \"node\": Component \"kids\": Component 1: Component 5: Component 6: Mean relative difference: 0.1237503"
[2] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 5: Mean relative difference: 0.1746109"
[3] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 6: Mean relative difference: 0.0443985"
[4] "Component \"node\": Component \"info\": Component \"p.value\": Mean relative difference: 1.100407"
[5] "Component \"node\": Component \"info\": Component \"test\": Mean relative difference: 0.07721086"
[6] "Component \"info\": Component \"call\": target, current do not match when deparsed"
[7] "Component \"info\": Component \"control\": Component \"breakties\": 1 element mismatch"
>
> unclass(m_bt)$node$info$criterion
NULL
> unclass(m_df)$node$info$criterion
NULL
>
> if (requireNamespace("mlbench")) {
+
+ ### example from mob vignette
+ data("PimaIndiansDiabetes", package = "mlbench")
+
+ logit <- function(y, x, start = NULL, weights = NULL, offset = NULL, ...) {
+ glm(y ~ 0 + x, family = binomial, start = start, ...)
+ }
+
+ pid_formula <- diabetes ~ glucose | pregnant + pressure + triceps +
+ insulin + mass + pedigree + age
+
+ pid_tree <- mob(pid_formula, data = PimaIndiansDiabetes, fit = logit)
+ print(pid_tree)
+ print(nodeapply(pid_tree, ids = nodeids(pid_tree), function(n) n$info$criterion))
+
+ }
Loading required namespace: mlbench
Error in eval(mf, parent.frame()) :
object 'PimaIndiansDiabetes' not found
Calls: mob ... model.frame -> terms -> terms.Formula -> terms -> terms.formula
In addition: Warning message:
In data("PimaIndiansDiabetes", package = "mlbench") :
data set 'PimaIndiansDiabetes' not found
Execution halted
Flavor: r-release-linux-x86_64
Version: 1.2-29
Check: tests
Result: ERROR
Running 'bugfixes.R' [5s]
Comparing 'bugfixes.Rout' to 'bugfixes.Rout.save' ... OK
Running 'constparty.R' [4s]
Comparing 'constparty.Rout' to 'constparty.Rout.save' ... OK
Running 'regtest-MIA.R' [2s]
Comparing 'regtest-MIA.Rout' to 'regtest-MIA.Rout.save' ... OK
Running 'regtest-cforest.R' [8s]
Comparing 'regtest-cforest.Rout' to 'regtest-cforest.Rout.save' ... OK
Running 'regtest-ctree.R' [2s]
Comparing 'regtest-ctree.Rout' to 'regtest-ctree.Rout.save' ... OK
Running 'regtest-glmtree.R' [41s]
Running 'regtest-honesty.R' [2s]
Running 'regtest-lmtree.R' [2s]
Running 'regtest-nmax.R' [2s]
Comparing 'regtest-nmax.Rout' to 'regtest-nmax.Rout.save' ... OK
Running 'regtest-node.R' [2s]
Comparing 'regtest-node.Rout' to 'regtest-node.Rout.save' ... OK
Running 'regtest-party-random.R' [3s]
Running 'regtest-party.R' [4s]
Comparing 'regtest-party.Rout' to 'regtest-party.Rout.save' ... OK
Running 'regtest-split.R' [1s]
Comparing 'regtest-split.Rout' to 'regtest-split.Rout.save' ... OK
Running 'regtest-weights.R' [2s]
Comparing 'regtest-weights.Rout' to 'regtest-weights.Rout.save' ... OK
Running the tests in 'tests/regtest-glmtree.R' failed.
Complete output:
> suppressWarnings(RNGversion("3.5.2"))
>
> library("partykit")
Loading required package: grid
Loading required package: libcoin
Loading required package: mvtnorm
>
> set.seed(29)
> n <- 1000
> x <- runif(n)
> z <- runif(n)
> y <- rnorm(n, mean = x * c(-1, 1)[(z > 0.7) + 1], sd = 3)
> z_noise <- factor(sample(1:3, size = n, replace = TRUE))
> d <- data.frame(y = y, x = x, z = z, z_noise = z_noise)
>
>
> fmla <- as.formula("y ~ x | z + z_noise")
> fmly <- gaussian()
> fit <- partykit:::glmfit
>
> # versions of the data
> d1 <- d
> d1$z <- signif(d1$z, digits = 1)
>
> k <- 20
> zs_noise <- matrix(rnorm(n*k), nrow = n)
> colnames(zs_noise) <- paste0("z_noise_", 1:k)
> d2 <- cbind(d, zs_noise)
> fmla2 <- as.formula(paste("y ~ x | z + z_noise +",
+ paste0("z_noise_", 1:k, collapse = " + ")))
>
>
> d3 <- d2
> d3$z <- factor(sample(1:3, size = n, replace = TRUE, prob = c(0.1, 0.5, 0.4)))
> d3$y <- rnorm(n, mean = x * c(-1, 1)[(d3$z == 2) + 1], sd = 3)
>
> ## check weights
> w <- rep(1, n)
> w[1:10] <- 2
> (mw1 <- glmtree(formula = fmla, data = d, weights = w))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 706
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 304
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
> (mw2 <- glmtree(formula = fmla, data = d, weights = w, caseweights = FALSE))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
>
>
>
> ## check dfsplit
> (mmfluc2 <- mob(formula = fmla, data = d, fit = partykit:::glmfit))
Model-based recursive partitioning (partykit:::glmfit)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function: 2551.673
> (mmfluc3 <- glmtree(formula = fmla, data = d))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
> (mmfluc3_dfsplit <- glmtree(formula = fmla, data = d, dfsplit = 10))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
>
> ## check tests
> if (require("strucchange"))
+ print(sctest(mmfluc3, node = 1)) # does not yet work
Loading required package: strucchange
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Loading required package: sandwich
z z_noise
statistic 2.292499e+01 0.6165335
p.value 7.780038e-04 0.9984952
>
> x <- mmfluc3
> (tst3 <- nodeapply(x, ids = nodeids(x), function(n) n$info$criterion))
$`1`
NULL
$`2`
NULL
$`3`
NULL
>
>
>
>
> ## check logLik and AIC
> logLik(mmfluc2)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3_dfsplit)
'log Lik.' -2551.673 (df=16)
> logLik(glm(y ~ x, data = d))
'log Lik.' -2563.694 (df=3)
>
> AIC(mmfluc3)
[1] 5117.347
> AIC(mmfluc3_dfsplit)
[1] 5135.347
>
> ## check pruning
> pr2 <- prune.modelparty(mmfluc2)
> AIC(mmfluc2)
[1] 5117.347
> AIC(pr2)
[1] 5117.347
>
> mmfluc_dfsplit3 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 3)
> mmfluc_dfsplit4 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 4)
> pr_dfsplit3 <- prune.modelparty(mmfluc_dfsplit3)
> pr_dfsplit4 <- prune.modelparty(mmfluc_dfsplit4)
> AIC(mmfluc_dfsplit3)
[1] 5142.774
> AIC(mmfluc_dfsplit4)
[1] 5156.774
> AIC(pr_dfsplit3)
[1] 5142.774
> AIC(pr_dfsplit4)
[1] 5124.456
>
> width(mmfluc_dfsplit3)
[1] 8
> width(mmfluc_dfsplit4)
[1] 8
> width(pr_dfsplit3)
[1] 8
> width(pr_dfsplit4)
[1] 3
>
> ## check inner and terminal
> options <- list(NULL,
+ "object",
+ "estfun",
+ c("object", "estfun"))
>
> arguments <- list("inner",
+ "terminal",
+ c("inner", "terminal"))
>
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, inner = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, terminal = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ NA: NULL
..$ NA: NULL
$ 3:List of 2
..$ NA: NULL
..$ NA: NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ NA : NULL
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ NA : NULL
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
>
>
> ## check model
> m_mt <- glmtree(formula = fmla, data = d, model = TRUE)
> m_mf <- glmtree(formula = fmla, data = d, model = FALSE)
>
> dim(m_mt$data)
[1] 1000 4
> dim(m_mf$data)
[1] 0 4
>
>
> ## check multiway
> (m_mult <- glmtree(formula = fmla2, data = d3, catsplit = "multiway", minsize = 80))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise + z_noise_1 + z_noise_2 + z_noise_3 + z_noise_4 +
z_noise_5 + z_noise_6 + z_noise_7 + z_noise_8 + z_noise_9 +
z_noise_10 + z_noise_11 + z_noise_12 + z_noise_13 + z_noise_14 +
z_noise_15 + z_noise_16 + z_noise_17 + z_noise_18 + z_noise_19 +
z_noise_20
Fitted party:
[1] root
| [2] z in 1: n = 76
| (Intercept) x
| 0.9859847 -3.2600047
| [3] z in 2: n = 537
| (Intercept) x
| -0.06970187 1.12305074
| [4] z in 3: n = 387
| (Intercept) x
| 0.3824392 -1.8337151
Number of inner nodes: 1
Number of terminal nodes: 3
Number of parameters per node: 2
Objective function (negative log-likelihood): 2511.927
>
>
> ## check parm
> fmla_p <- as.formula("y ~ x + z_noise + z_noise_1 | z + z_noise_2")
> (m_interc <- glmtree(formula = fmla_p, data = d2, parm = 1))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root
| [2] z <= 0.65035: n = 644
| (Intercept) x z_noise2 z_noise3 z_noise_1
| -0.05585503 -1.01257554 0.34044520 -0.16384987 0.24197601
| [3] z > 0.65035: n = 356
| (Intercept) x z_noise2 z_noise3 z_noise_1
| 0.06411865 0.78733976 -0.67811149 -0.14240432 -0.01239154
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 5
Objective function (negative log-likelihood): 2548.32
>
> (m_p3 <- glmtree(formula = fmla_p, data = d2, parm = 3))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root: n = 1000
(Intercept) x z_noise2 z_noise3 z_noise_1
-0.058855295 -0.340314311 -0.008404682 -0.109839080 0.154798281
Number of inner nodes: 0
Number of terminal nodes: 1
Number of parameters per node: 5
Objective function (negative log-likelihood): 2562.32
>
>
> ## check trim
> (m_tt <- glmtree(formula = fmla, data = d, trim = 0.2))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
> (m_tf <- glmtree(formula = fmla, data = d, trim = 300, minsize = 300))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.6892: n = 691
| (Intercept) x
| -0.1778199 -0.7692901
| [3] z > 0.6892: n = 309
| (Intercept) x
| 0.1065746 0.5562243
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2552.12
>
>
>
> ## check breakties
> m_bt <- glmtree(formula = fmla, data = d1, breakties = TRUE)
> m_df <- glmtree(formula = fmla, data = d1, breakties = FALSE)
>
> all.equal(m_bt, m_df, check.environment = FALSE)
[1] "Component \"node\": Component \"kids\": Component 1: Component 5: Component 6: Mean relative difference: 0.1237503"
[2] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 5: Mean relative difference: 0.1746109"
[3] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 6: Mean relative difference: 0.0443985"
[4] "Component \"node\": Component \"info\": Component \"p.value\": Mean relative difference: 1.100407"
[5] "Component \"node\": Component \"info\": Component \"test\": Mean relative difference: 0.07721086"
[6] "Component \"info\": Component \"call\": target, current do not match when deparsed"
[7] "Component \"info\": Component \"control\": Component \"breakties\": 1 element mismatch"
>
> unclass(m_bt)$node$info$criterion
NULL
> unclass(m_df)$node$info$criterion
NULL
>
> if (requireNamespace("mlbench")) {
+
+ ### example from mob vignette
+ data("PimaIndiansDiabetes", package = "mlbench")
+
+ logit <- function(y, x, start = NULL, weights = NULL, offset = NULL, ...) {
+ glm(y ~ 0 + x, family = binomial, start = start, ...)
+ }
+
+ pid_formula <- diabetes ~ glucose | pregnant + pressure + triceps +
+ insulin + mass + pedigree + age
+
+ pid_tree <- mob(pid_formula, data = PimaIndiansDiabetes, fit = logit)
+ print(pid_tree)
+ print(nodeapply(pid_tree, ids = nodeids(pid_tree), function(n) n$info$criterion))
+
+ }
Loading required namespace: mlbench
Error in eval(mf, parent.frame()) :
object 'PimaIndiansDiabetes' not found
Calls: mob ... model.frame -> terms -> terms.Formula -> terms -> terms.formula
In addition: Warning message:
In data("PimaIndiansDiabetes", package = "mlbench") :
data set 'PimaIndiansDiabetes' not found
Execution halted
Flavor: r-release-windows-x86_64
Version: 1.2-29
Check: tests
Result: ERROR
Running 'bugfixes.R' [8s]
Comparing 'bugfixes.Rout' to 'bugfixes.Rout.save' ... OK
Running 'constparty.R' [7s]
Comparing 'constparty.Rout' to 'constparty.Rout.save' ... OK
Running 'regtest-MIA.R' [3s]
Comparing 'regtest-MIA.Rout' to 'regtest-MIA.Rout.save' ... OK
Running 'regtest-cforest.R' [13s]
Comparing 'regtest-cforest.Rout' to 'regtest-cforest.Rout.save' ... OK
Running 'regtest-ctree.R' [3s]
Comparing 'regtest-ctree.Rout' to 'regtest-ctree.Rout.save' ... OK
Running 'regtest-glmtree.R' [57s]
Running 'regtest-honesty.R' [3s]
Running 'regtest-lmtree.R' [4s]
Running 'regtest-nmax.R' [3s]
Comparing 'regtest-nmax.Rout' to 'regtest-nmax.Rout.save' ... OK
Running 'regtest-node.R' [2s]
Comparing 'regtest-node.Rout' to 'regtest-node.Rout.save' ... OK
Running 'regtest-party-random.R' [4s]
Running 'regtest-party.R' [6s]
Comparing 'regtest-party.Rout' to 'regtest-party.Rout.save' ... OK
Running 'regtest-split.R' [2s]
Comparing 'regtest-split.Rout' to 'regtest-split.Rout.save' ... OK
Running 'regtest-weights.R' [3s]
Comparing 'regtest-weights.Rout' to 'regtest-weights.Rout.save' ... OK
Running the tests in 'tests/regtest-glmtree.R' failed.
Complete output:
> suppressWarnings(RNGversion("3.5.2"))
>
> library("partykit")
Loading required package: grid
Loading required package: libcoin
Loading required package: mvtnorm
>
> set.seed(29)
> n <- 1000
> x <- runif(n)
> z <- runif(n)
> y <- rnorm(n, mean = x * c(-1, 1)[(z > 0.7) + 1], sd = 3)
> z_noise <- factor(sample(1:3, size = n, replace = TRUE))
> d <- data.frame(y = y, x = x, z = z, z_noise = z_noise)
>
>
> fmla <- as.formula("y ~ x | z + z_noise")
> fmly <- gaussian()
> fit <- partykit:::glmfit
>
> # versions of the data
> d1 <- d
> d1$z <- signif(d1$z, digits = 1)
>
> k <- 20
> zs_noise <- matrix(rnorm(n*k), nrow = n)
> colnames(zs_noise) <- paste0("z_noise_", 1:k)
> d2 <- cbind(d, zs_noise)
> fmla2 <- as.formula(paste("y ~ x | z + z_noise +",
+ paste0("z_noise_", 1:k, collapse = " + ")))
>
>
> d3 <- d2
> d3$z <- factor(sample(1:3, size = n, replace = TRUE, prob = c(0.1, 0.5, 0.4)))
> d3$y <- rnorm(n, mean = x * c(-1, 1)[(d3$z == 2) + 1], sd = 3)
>
> ## check weights
> w <- rep(1, n)
> w[1:10] <- 2
> (mw1 <- glmtree(formula = fmla, data = d, weights = w))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 706
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 304
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
> (mw2 <- glmtree(formula = fmla, data = d, weights = w, caseweights = FALSE))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1447422 -0.8138701
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.07006626 0.73278593
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.48
>
>
>
> ## check dfsplit
> (mmfluc2 <- mob(formula = fmla, data = d, fit = partykit:::glmfit))
Model-based recursive partitioning (partykit:::glmfit)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function: 2551.673
> (mmfluc3 <- glmtree(formula = fmla, data = d))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
> (mmfluc3_dfsplit <- glmtree(formula = fmla, data = d, dfsplit = 10))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
>
> ## check tests
> if (require("strucchange"))
+ print(sctest(mmfluc3, node = 1)) # does not yet work
Loading required package: strucchange
Loading required package: zoo
Attaching package: 'zoo'
The following objects are masked from 'package:base':
as.Date, as.Date.numeric
Loading required package: sandwich
z z_noise
statistic 2.292499e+01 0.6165335
p.value 7.780038e-04 0.9984952
>
> x <- mmfluc3
> (tst3 <- nodeapply(x, ids = nodeids(x), function(n) n$info$criterion))
$`1`
NULL
$`2`
NULL
$`3`
NULL
>
>
>
>
> ## check logLik and AIC
> logLik(mmfluc2)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3)
'log Lik.' -2551.673 (df=7)
> logLik(mmfluc3_dfsplit)
'log Lik.' -2551.673 (df=16)
> logLik(glm(y ~ x, data = d))
'log Lik.' -2563.694 (df=3)
>
> AIC(mmfluc3)
[1] 5117.347
> AIC(mmfluc3_dfsplit)
[1] 5135.347
>
> ## check pruning
> pr2 <- prune.modelparty(mmfluc2)
> AIC(mmfluc2)
[1] 5117.347
> AIC(pr2)
[1] 5117.347
>
> mmfluc_dfsplit3 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 3)
> mmfluc_dfsplit4 <- glmtree(formula = fmla, data = d, alpha = 0.5, dfsplit = 4)
> pr_dfsplit3 <- prune.modelparty(mmfluc_dfsplit3)
> pr_dfsplit4 <- prune.modelparty(mmfluc_dfsplit4)
> AIC(mmfluc_dfsplit3)
[1] 5142.774
> AIC(mmfluc_dfsplit4)
[1] 5156.774
> AIC(pr_dfsplit3)
[1] 5142.774
> AIC(pr_dfsplit4)
[1] 5124.456
>
> width(mmfluc_dfsplit3)
[1] 8
> width(mmfluc_dfsplit4)
[1] 8
> width(pr_dfsplit3)
[1] 8
> width(pr_dfsplit4)
[1] 3
>
> ## check inner and terminal
> options <- list(NULL,
+ "object",
+ "estfun",
+ c("object", "estfun"))
>
> arguments <- list("inner",
+ "terminal",
+ c("inner", "terminal"))
>
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, inner = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
>
> for (o in options) {
+ print(o)
+ x <- glmtree(formula = fmla, data = d, terminal = o)
+ str(nodeapply(x, ids = nodeids(x), function(n) n$info[c("object", "estfun")]), 2)
+ }
NULL
List of 3
$ 1:List of 2
..$ NA: NULL
..$ NA: NULL
$ 2:List of 2
..$ NA: NULL
..$ NA: NULL
$ 3:List of 2
..$ NA: NULL
..$ NA: NULL
[1] "object"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ NA : NULL
[1] "estfun"
List of 3
$ 1:List of 2
..$ NA : NULL
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ NA : NULL
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ NA : NULL
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
[1] "object" "estfun"
List of 3
$ 1:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:1000, 1:2] -0.1375 -0.0583 -0.0553 0.1043 -0.0744 ...
.. ..- attr(*, "dimnames")=List of 2
$ 2:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:704, 1:2] -0.1291 0.5104 -0.0603 -0.1868 -0.0981 ...
.. ..- attr(*, "dimnames")=List of 2
$ 3:List of 2
..$ object:List of 24
.. ..- attr(*, "class")= chr [1:2] "glm" "lm"
..$ estfun: num [1:296, 1:2] -0.1053 -0.0877 0.0544 -0.1581 0.43 ...
.. ..- attr(*, "dimnames")=List of 2
>
>
> ## check model
> m_mt <- glmtree(formula = fmla, data = d, model = TRUE)
> m_mf <- glmtree(formula = fmla, data = d, model = FALSE)
>
> dim(m_mt$data)
[1] 1000 4
> dim(m_mf$data)
[1] 0 4
>
>
> ## check multiway
> (m_mult <- glmtree(formula = fmla2, data = d3, catsplit = "multiway", minsize = 80))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise + z_noise_1 + z_noise_2 + z_noise_3 + z_noise_4 +
z_noise_5 + z_noise_6 + z_noise_7 + z_noise_8 + z_noise_9 +
z_noise_10 + z_noise_11 + z_noise_12 + z_noise_13 + z_noise_14 +
z_noise_15 + z_noise_16 + z_noise_17 + z_noise_18 + z_noise_19 +
z_noise_20
Fitted party:
[1] root
| [2] z in 1: n = 76
| (Intercept) x
| 0.9859847 -3.2600047
| [3] z in 2: n = 537
| (Intercept) x
| -0.06970187 1.12305074
| [4] z in 3: n = 387
| (Intercept) x
| 0.3824392 -1.8337151
Number of inner nodes: 1
Number of terminal nodes: 3
Number of parameters per node: 2
Objective function (negative log-likelihood): 2511.927
>
>
> ## check parm
> fmla_p <- as.formula("y ~ x + z_noise + z_noise_1 | z + z_noise_2")
> (m_interc <- glmtree(formula = fmla_p, data = d2, parm = 1))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root
| [2] z <= 0.65035: n = 644
| (Intercept) x z_noise2 z_noise3 z_noise_1
| -0.05585503 -1.01257554 0.34044520 -0.16384987 0.24197601
| [3] z > 0.65035: n = 356
| (Intercept) x z_noise2 z_noise3 z_noise_1
| 0.06411865 0.78733976 -0.67811149 -0.14240432 -0.01239154
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 5
Objective function (negative log-likelihood): 2548.32
>
> (m_p3 <- glmtree(formula = fmla_p, data = d2, parm = 3))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x + z_noise + z_noise_1 | z + z_noise_2
Fitted party:
[1] root: n = 1000
(Intercept) x z_noise2 z_noise3 z_noise_1
-0.058855295 -0.340314311 -0.008404682 -0.109839080 0.154798281
Number of inner nodes: 0
Number of terminal nodes: 1
Number of parameters per node: 5
Objective function (negative log-likelihood): 2562.32
>
>
> ## check trim
> (m_tt <- glmtree(formula = fmla, data = d, trim = 0.2))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.70311: n = 704
| (Intercept) x
| -0.1619978 -0.7896293
| [3] z > 0.70311: n = 296
| (Intercept) x
| 0.08683535 0.65598287
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2551.673
>
> (m_tf <- glmtree(formula = fmla, data = d, trim = 300, minsize = 300))
Generalized linear model tree (family: gaussian)
Model formula:
y ~ x | z + z_noise
Fitted party:
[1] root
| [2] z <= 0.6892: n = 691
| (Intercept) x
| -0.1778199 -0.7692901
| [3] z > 0.6892: n = 309
| (Intercept) x
| 0.1065746 0.5562243
Number of inner nodes: 1
Number of terminal nodes: 2
Number of parameters per node: 2
Objective function (negative log-likelihood): 2552.12
>
>
>
> ## check breakties
> m_bt <- glmtree(formula = fmla, data = d1, breakties = TRUE)
> m_df <- glmtree(formula = fmla, data = d1, breakties = FALSE)
>
> all.equal(m_bt, m_df, check.environment = FALSE)
[1] "Component \"node\": Component \"kids\": Component 1: Component 5: Component 6: Mean relative difference: 0.1237503"
[2] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 5: Mean relative difference: 0.1746109"
[3] "Component \"node\": Component \"kids\": Component 2: Component 5: Component 6: Mean relative difference: 0.0443985"
[4] "Component \"node\": Component \"info\": Component \"p.value\": Mean relative difference: 1.100407"
[5] "Component \"node\": Component \"info\": Component \"test\": Mean relative difference: 0.07721086"
[6] "Component \"info\": Component \"call\": target, current do not match when deparsed"
[7] "Component \"info\": Component \"control\": Component \"breakties\": 1 element mismatch"
>
> unclass(m_bt)$node$info$criterion
NULL
> unclass(m_df)$node$info$criterion
NULL
>
> if (requireNamespace("mlbench")) {
+
+ ### example from mob vignette
+ data("PimaIndiansDiabetes", package = "mlbench")
+
+ logit <- function(y, x, start = NULL, weights = NULL, offset = NULL, ...) {
+ glm(y ~ 0 + x, family = binomial, start = start, ...)
+ }
+
+ pid_formula <- diabetes ~ glucose | pregnant + pressure + triceps +
+ insulin + mass + pedigree + age
+
+ pid_tree <- mob(pid_formula, data = PimaIndiansDiabetes, fit = logit)
+ print(pid_tree)
+ print(nodeapply(pid_tree, ids = nodeids(pid_tree), function(n) n$info$criterion))
+
+ }
Loading required namespace: mlbench
Error in eval(mf, parent.frame()) :
object 'PimaIndiansDiabetes' not found
Calls: mob ... model.frame -> terms -> terms.Formula -> terms -> terms.formula
In addition: Warning message:
In data("PimaIndiansDiabetes", package = "mlbench") :
data set 'PimaIndiansDiabetes' not found
Execution halted
Flavor: r-oldrel-windows-x86_64