xpred.rpart              package:rpart              R Documentation

_R_e_t_u_r_n _C_r_o_s_s-_V_a_l_i_d_a_t_e_d _P_r_e_d_i_c_t_i_o_n_s

_D_e_s_c_r_i_p_t_i_o_n:

     Gives the predicted values for an 'rpart' fit, under cross
     validation, for a set of complexity parameter values.

_U_s_a_g_e:

     xpred.rpart(fit, xval=10, cp)

_A_r_g_u_m_e_n_t_s:

     fit: a 'rpart' object.  

    xval: number of cross-validation groups.  This may also be an
          explicit list of integers that define the cross-validation
          groups. 

      cp: the desired list of complexity values.  By default it is
          taken from the 'cptable' component of the fit. 

_D_e_t_a_i_l_s:

     Complexity penalties are actually ranges, not values.  If the 'cp'
     values found in the table were .36, .28, and .13, for instance,
     this means that the first row of the table holds for all
     complexity penalties in the range [.36, 1], the second row for
     'cp' in the range [.28, .36) and the third row for [.13,.28).  By
     default, the geometric mean of each interval is used for cross
     validation.

_V_a_l_u_e:

     a matrix with one row for each observation and one column for each
     complexity value.

_S_e_e _A_l_s_o:

     'rpart'

_E_x_a_m_p_l_e_s:

     fit <- rpart(Mileage ~ Weight, car.test.frame)
     xmat <- xpred.rpart(fit)
     xerr <- (xmat - car.test.frame$Mileage)^2
     apply(xerr, 2, sum)   # cross-validated error estimate

     # approx same result as rel. error from printcp(fit)
     apply(xerr, 2, sum)/var(car.test.frame$Mileage) 
     printcp(fit)

