R - loess prediction returns NA

后端 未结 2 1130
旧时难觅i
旧时难觅i 2021-01-04 11:52

I am struggling with "out-of-sample" prediction using loess. I get NA values for new x that are outside the original sample. Can I get th

2条回答
  •  日久生厌
    2021-01-04 12:34

    From the manual page of predict.loess:

    When the fit was made using surface = "interpolate" (the default), predict.loess will not extrapolate – so points outside an axis-aligned hypercube enclosing the original data will have missing (NA) predictions and standard errors

    If you change the surface parameter to "direct" you can extrapolate values.

    For instance, this will work (on a side note: after plotting the prediction, my feeling is that you should increase the span parameter in the loess call a little bit):

    lo <- loess(y~x, control=loess.control(surface="direct"))
    predict(lo, newdata=x.all)
    

提交回复
热议问题