我正在尝试在生成的glm fit上使用cv.glm()。这是我的数据框:
'data.frame': 158 obs. of 31 variables:
$ Weight : num 15.9 3.9 10.4 6.6 8.2 37 16 10 3.8 10.8 ...
$ Gender1 : Factor w/ 2 levels "0","1": 2 1 1 1 1 2 1 1 2 1 ...
$ Gender2 : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
$ Gender3 : Factor w/ 2 levels "0","1": 1 1 2 1 2 1 2 2 1 1 ...
$ BCS : int 9 5 5 5 7 7 5 5 5 8 ...
$ UNDER_ANAESTHESIA: Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
$ DOA : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
$ Multiples : Factor w/ 2 levels "0","1": 1 1 1 1 2 2 2 2 2 1 ...
$ CV : Factor w/ 2 levels "0","1": 1 2 1 1 1 1 1 2 1 1 ...
$ FatalArrhyth : Factor w/ 2 levels "0","1": 1 1 1 1 1 2 1 1 1 1 ...
$ OTHER_CAUSE : Factor w/ 2 levels "0","1": 1 1 2 1 2 1 1 1 1 1 ...
$ arrh1 : Factor w/ 2 levels "0","1": 1 1 1 1 2 2 2 2 2 1 ...
$ arrh2 : Factor w/ 2 levels "0","1": 1 1 2 2 1 1 1 1 1 1 ...
$ arrh3 : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
$ arrh4 : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
$ arrh5 : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 2 ...
$ arrh6 : Factor w/ 2 levels "0","1": 2 2 1 1 1 1 1 1 1 1 ...
$ AfterHours : Factor w/ 2 levels "0","1": 2 1 2 2 2 2 2 2 1 2 ...
$ Duration : int 15 15 10 10 10 20 15 20 10 20 ...
$ Mannitol : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
$ LIDO : Factor w/ 2 levels "0","1": 1 2 1 1 1 1 1 1 1 1 ...
$ FLUIDS : Factor w/ 2 levels "0","1": 2 2 1 1 1 2 1 1 1 1 ...
$ ABDCOMP : Factor w/ 2 levels "0","1": 1 1 1 1 2 1 1 1 2 1 ...
$ DOPA : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
$ DOB : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
$ STEROIDS : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
$ VASO : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
$ ROUNDS_EPI : int 3 2 2 3 2 3 3 0 0 4 ...
$ ROUNDS_ATR : int 3 1 1 3 2 0 3 0 1 4 ...
$ Lateral : Factor w/ 2 levels "0","1": 2 1 2 2 2 1 2 2 2 2 ...
$ SUCCESS : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
这是我的glm模型的生成:
cols = c("Gender1","Gender2","Gender3","UNDER_ANAESTHESIA",
"DOA","Multiples","CV","FatalArrhyth","OTHER_CAUSE",
"arrh1","arrh2","arrh3","arrh4","arrh5","arrh6",
"AfterHours","Mannitol","LIDO","FLUIDS","ABDCOMP",
"DOPA","DOB","STEROIDS","VASO","Lateral", "SUCCESS")
df[cols] <- lapply(df[cols], factor)
glm.fit=glm(SUCCESS~.,data=df,family=binomial)
glm fit运行良好,但是当我打电话给cv.glm(df,glm.fit)
时出现错误
Error in `contrasts<-`(`*tmp*`, value = contr.funs[1 + isOF[nn]]) :
contrasts can be applied only to factors with 2 or more levels
从我的数据帧输出中可以看到,所有因子变量都有2个级别。那我为什么会收到这个错误?