|
a |
|
b/partyMod/tests/Predict-regtest.R |
|
|
1 |
|
|
|
2 |
set.seed(290875) |
|
|
3 |
library("party") |
|
|
4 |
if (!require("TH.data")) |
|
|
5 |
stop("cannot load package TH.data") |
|
|
6 |
if (!require("coin")) |
|
|
7 |
stop("cannot load package coin") |
|
|
8 |
|
|
|
9 |
### get rid of the NAMESPACE |
|
|
10 |
attach(asNamespace("party")) |
|
|
11 |
|
|
|
12 |
data(treepipit, package = "coin") |
|
|
13 |
ct <- ctree(counts ~ ., data = treepipit) |
|
|
14 |
stopifnot(isequal(predict(ct), predict(ct, newdata = treepipit))) |
|
|
15 |
|
|
|
16 |
|
|
|
17 |
data(GlaucomaM, package = "TH.data") |
|
|
18 |
ct <- ctree(Class ~ ., data = GlaucomaM) |
|
|
19 |
stopifnot(isequal(predict(ct), predict(ct, newdata = GlaucomaM))) |
|
|
20 |
stopifnot(isequal(predict(ct, type = "prob"), predict(ct, type = "prob", |
|
|
21 |
newdata = GlaucomaM))) |
|
|
22 |
stopifnot(isequal(predict(ct, type = "node"), predict(ct, type = "node", |
|
|
23 |
newdata = GlaucomaM))) |
|
|
24 |
stopifnot(isequal(predict(ct, type = "prob"), treeresponse(ct))) |
|
|
25 |
|
|
|
26 |
data("GBSG2", package = "TH.data") |
|
|
27 |
|
|
|
28 |
GBSG2tree <- ctree(Surv(time, cens) ~ ., data = GBSG2) |
|
|
29 |
stopifnot(isequal(GBSG2tree@predict_response(), |
|
|
30 |
GBSG2tree@predict_response(newdata = GBSG2))) |
|
|
31 |
stopifnot(isequal(GBSG2tree@cond_distr_response(), |
|
|
32 |
GBSG2tree@cond_distr_response(newdata = GBSG2))) |
|
|
33 |
|
|
|
34 |
data("mammoexp", package = "TH.data") |
|
|
35 |
attr(mammoexp$ME, "scores") <- 1:3 |
|
|
36 |
attr(mammoexp$SYMPT, "scores") <- 1:4 |
|
|
37 |
attr(mammoexp$DECT, "scores") <- 1:3 |
|
|
38 |
names(mammoexp)[names(mammoexp) == "SYMPT"] <- "symptoms" |
|
|
39 |
names(mammoexp)[names(mammoexp) == "PB"] <- "benefit" |
|
|
40 |
|
|
|
41 |
names(mammoexp) |
|
|
42 |
mtree <- ctree(ME ~ ., data = mammoexp) |
|
|
43 |
stopifnot(isequal(predict(mtree), predict(mtree, newdata = mammoexp))) |
|
|
44 |
stopifnot(isequal(predict(mtree), predict(mtree, newdata = mammoexp))) |