-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctree.R
More file actions
50 lines (36 loc) · 1.28 KB
/
ctree.R
File metadata and controls
50 lines (36 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ctree - Classification and Regression
library(partykit) # use this to model, can also use party but that will give different output
### regression----
head(airquality)
airq <- subset(airquality, !is.na(Ozone))
airct <- ctree(Ozone ~ ., data = airq)
airct
plot(airct)
plot(airct, type='simple')
plot(as.simpleparty(airct)) #when partykit is used to model
library("strucchange")
strucchange::sctest(airct, node = 1)
strucchange::sctest(airct, node = c(2,7,4,9))
predict(airct)
mean((airq$Ozone - predict(airct))^2) #error
nodeids(airct,2)
nodeids(airct)
nodeids(airct, terminal=T)
nodeids(airct, from=2, terminal=T)
nodeids(airct,1,5)
#party
#party::ctree(Ozone ~ ., data = airq)
### classification ---
irisct <- partykit::ctree(Species ~ .,data = iris)
irisct
plot(irisct, type='simple')
strucchange::sctest(irisct, node = 1)
strucchange::sctest(irisct, node = c(3,4,7))
#7 not significant
nodeapply(irisct, ids = nodeids(irisct), function(n) info_node(n)$p.value)
table(predict(irisct), iris$Species)
### estimated class probabilities, a list
(tr <- predict(irisct, newdata = iris[1:10,], type = "prob"))
(tr <- predict(irisct, newdata = iris, type = "prob"))
(tr2 <- predict(irisct, newdata = iris[1:10,], type = "response"))
head(iris)