2

What are the cp values on the rpart plotcp() chart? I would expect these values to match the cp column in printcp(), but instead the following scale is calculated (from the plotcp code):

p.rpart <- x$cptable
cp0 <- p.rpart[, 1L]
cp <- sqrt(cp0 * c(Inf, cp0[-length(cp0)]))

So each cp value from the CV table is multiplied against the following one in the same column and then square rooted. Why?

Robert Kubrick
  • 8,413
  • 13
  • 59
  • 91

1 Answers1

1

According to Uwe's answer, which can be found here:Re: [R] Different cp values in rpart() using plotcp() and printcp()

printcp() gives the minimal cp for which the pruning happens.
plotcp() plots against the geometric mean

Actual relationship in the source code is provided below, where cp0 is the cp value used in the printcp while cp is the cp value used in the plotcp.

cp0 <- p.rpart[, 1L]  
cp <- sqrt(cp0 * c(Inf, cp0[-length(cp0)]))
Sharp Yan
  • 345
  • 1
  • 9