Skip to content

Commit e2c31cb

Browse files
committed
protect against NaN when fitting fails
1 parent 7025068 commit e2c31cb

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

R/forward_selection_by_rank_class.R

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,16 @@ eval_loess=function(x,X,Y,k=10,p=0.66)
181181
yy2=Y[X %in% xx2]
182182

183183

184-
loessMod <- loess(yy ~ xx, span=x) # 25% smoothing span
184+
loessMod <- loess(yy ~ xx, span=x)
185+
186+
# check for NaN
187+
if (any(is.nan(loessMod$fitted))){
188+
residual[i]=99999
189+
} else {
190+
191+
smoothed=stats::predict(loessMod,newdata=xx2)
192+
residual[i]=sum((smoothed-yy2)^2)
193+
}
185194
smoothed=stats::predict(loessMod,newdata=xx2)
186195
residual[i]=sum((smoothed-yy2)^2)
187196
}

0 commit comments

Comments
 (0)