[R] cross validation with variables which have one factor only

Maik Rehnus maik.rehnus at gmx.de
Tue Mar 4 19:20:01 CET 2014


   Dear R-team
   I  did a model selection by AIC which explain me the habitat use of my
   animals   in   six   different   study   sites  (See  attached  files:
   cross_val_CORINE04032014.csv and cross_val_CORINE04032014.r). Sites were
   used as random factor because they are distributed over the Alps and so very
   different. In this way I also removed variables which exist in one study
   area  only  to  do the model selection. In next, I tried to do a cross
   validation with the estimated best model for its prediction per site. That
   means I used model of five sites togehther against the remaining site. In
   this step I received an error:

   > val_10_fold_minger <- cv.glm(data= minger, glmfit = best_model_year, K =
   10)
   Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
     contrasts can be applied only to factors with 2 or more levels

   So for some of the model variables used in the model formula below there are
   actually  not  two factor levels (example=C324F where absence :153 but
   presence:  0 )
   best_model_year <- glm(dung1_b ~ C231F+C324F+C332F, family=binomial(logit),
   minger)
   Does somebody know is there a possibility in cross validation methods which
   can deal with variables which have one factor only?
   Kindly

   Maik


More information about the R-help mailing list