需要应用分支定界法来选择最佳模型。leaps()
来自 jumps 包的效果很好,只有当数据没有NA
值时,否则会引发错误:
#dummy data
x<-matrix(rnorm(100),ncol=4)
#convert to 0,1,2 - this is a genetic data, NA=NoCall
x<-matrix(round(runif(100)*10) %% 3,ncol=4)
#introduce NA=NoCall
x[1,1] <-NA
#response, case or control
y<-rep(c(0,1,1,0,1),5)
leaps(x,y)
Error in leaps.setup(x, y, wt = wt, nbest = nbest, nvmax = NCOL(x) + int, :
NA/NaN/Inf in foreign function call (arg 4)
仅使用complete.cases()
不是一种选择,因为我丢失了 80% 的数据。
leap
可以处理NA
s的替代方法是什么?我正在编写自己的函数来做类似的事情,但它变得又大又笨重,我觉得我正在重新发明轮子......
更新:
我尝试过使用stepAIC()
,面临同样的数据丢失问题:
Error in stepAIC(fit) :
number of rows in use has changed: remove missing values?