cv                 package:monoProc                 R Documentation

_C_r_o_s_s _v_a_l_i_d_a_t_i_o_n _f_u_n_c_t_i_o_n

_D_e_s_c_r_i_p_t_i_o_n:

     computes the cross validation value (leave one out method) for the
     monotonized and the unconstraint fit

_U_s_a_g_e:

     cv(fit, ...)

_A_r_g_u_m_e_n_t_s:

     fit: an object of class '"monoproclocfit.1d"' or
          '"monoproclocfit.2d"'

     ...: currently not in use

_D_e_t_a_i_l_s:

     so far, this function can only be used for objects of class
     '"monoproc"' if the originally fit came from the
     'locfit'-function. This function is currently not  really
     computational efficient.

_V_a_l_u_e:

     returns a matrix where column 1 and 2 represents the values for
     the new 'fit' and the 'fitold', respectively, under leave one out
     cross valdiation. The rows correspond to the observation number.

_S_e_e _A_l_s_o:

     'monoproc'

_E_x_a_m_p_l_e_s:

     if(require(UsingR)&&require(locfit)){
             data(fat)
             fat<-fat[-39,] ##two extreme observations
             fat<-fat[-41,] ##are deleted
             attach(fat)
             x<-as.matrix(cbind(weight, height))
             fit<-locfit.raw(x,body.fat.siri, alpha=0.3, deg=1, kern="epan")
             fitmono<-monoproc(fit,bandwidth=1,dir="xy", gridsize=30)
             nf<- layout(matrix(c(1,1,1,2,2,3,3,3,4,4), 2, 5, byrow = TRUE))
             layout.show(nf)
             plot(fit, type="persp", theta = 135, phi = 30,col="lightblue",
             cex=0.7,main="unconstraint Bodyfat estimate")
             plot(fit)
             plot(fitmono,theta = 135, phi = 30, col="lightblue",cex=0.7, 
             main="monotone Bodyfat estimate")
             plot(fitmono, type="contour")
             t<-cv(fitmono)
             #Cross Validation for the unconstraint estimator
             sum((t[,2]-body.fat.siri)^2)/250    
             #Cross Validation for the monotone estimator
             sum((t[,1]-body.fat.siri)^2)/250   
             plot(seq(1:250),rep(1,250), type="l",col=2, xlab="observation index", 
             ylab="Ratio of CV-unconstraint over CV-monotone")
                     points((t[,2]-body.fat.siri)^2/(t[,1]-body.fat.siri)^2)
             }

