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/cptest.R
library(rpart)
mystate <- data.frame(state.x77, region=factor(state.region))
names(mystate) <- c("population","income" , "illiteracy","life" ,
       "murder", "hs.grad", "frost",     "area",      "region")
#
# This little test came out of a query that cp did not scale
#  with the data size.  It does
#
# tdata = 20 copies of "mystate"  
# trees with tdata and trees with mystate should be the same (they are)
#  except for the n's
set.seed(10)

tdata <- rbind(mystate, mystate, mystate, mystate, mystate)
tdata <- rbind(tdata, tdata, tdata, tdata)
tfit1 <- rpart(income ~ population + illiteracy + murder + hs.grad + region,
               data = mystate, method = "anova", xval=0, cp=.089)
tfit2 <- rpart(income ~ population + illiteracy + murder + hs.grad + region,
               data = tdata, method='anova', xval=0, cp=.089, 
               minsplit=400, minbucket=140)

all.equal(tfit1$splits[,-1], tfit2$splits[,-1])