2025-01-12 04:36:52 +08:00

51 lines
1.6 KiB
Plaintext

R Under development (unstable) (2019-04-05 r76323) -- "Unsuffered Consequences"
Copyright (C) 2019 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(rpart)
> require(survival)
Loading required package: 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 ?
[1] TRUE
> aeq(temp1[indx1,3], temp2[indx2,3]*(1+ 1:7/10)) #scaled importance
[1] TRUE
>
>
>
> proc.time()
user system elapsed
0.693 0.051 0.738