File: cost.R

package info (click to toggle)
rpart 4.1.24-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,640 kB
  • sloc: ansic: 2,994; makefile: 2
file content (26 lines) | stat: -rw-r--r-- 841 bytes parent folder | download | duplicates (3)
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
library(rpart)
require(survival)
aeq <- function(x,y, ...) all.equal(as.vector(x), as.vector(y), ...)

set.seed(10)
#
# Check out using costs
#
fit1 <- rpart(Surv(time, status) ~ age + sex + ph.ecog + ph.karno + pat.karno
	      + meal.cal + wt.loss, data=lung,
	      maxdepth=1, maxcompete=6, xval=0)

fit2 <- rpart(Surv(time, status) ~ age + sex + ph.ecog + ph.karno + pat.karno
	      + meal.cal + wt.loss, data=lung,
	      maxdepth=1, maxcompete=6, xval=0, cost=(1+ 1:7/10))

temp1 <- fit1$splits[1:7,]
temp2 <- fit2$splits[1:7,]
temp3 <- c('age', 'sex', 'ph.ecog', 'ph.karno', 'pat.karno', 'meal.cal',
	   'wt.loss')
indx1 <- match(temp3, dimnames(temp1)[[1]])
indx2 <- match(temp3, dimnames(temp2)[[1]])
aeq(temp1[indx1,1], temp2[indx2,1])             #same n's ?
aeq(temp1[indx1,3], temp2[indx2,3]*(1+ 1:7/10)) #scaled importance