HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Program Files/R/R-4.4.0/library/rpart/tests/cost.R
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