For part 1: It took a bit of tracking, but if you do this:
loess.smooth(x, y, family = "guassian")
the model will do. This is due to the different defaults of loess.smooth and loess ; the former has family = c("symmetric", "gaussian") , while the latter has the opposite side. If you go through the code for loess and loess.smooth , you will see that when family = "gaussian" iterations set to 1 . Otherwise, it takes on the value loess.control()$iterations . If you iterate over simpleLoess , the following function call returns the NaN vector:
pseudovalues <- .Fortran(R_lowesp, as.integer(N), as.double(y), as.double(z$fitted.values), as.double(weights), as.double(robust), integer(N), pseudovalues = double(N))$pseudovalues
Which causes the following function call to throw the error you saw:
zz <- .C(R_loess_raw, as.double(pseudovalues), as.double(x), as.double(weights), as.double(weights), as.integer(D), as.integer(N), as.double(span), as.integer(degree), as.integer(nonparametric), as.integer(order.drop.sqr), as.integer(sum.drop.sqr), as.double(span * cell), as.character(surf.stat), temp = double(N), parameter = integer(7), a = integer(max.kd), xi = double(max.kd), vert = double(2 * D), vval = double((D + 1) * max.kd), diagonal = double(N), trL = double(1), delta1 = double(1), delta2 = double(1), as.integer(0L))
All this relates to a reliable installation in Loess (method). If you don't want / need a reliable fit, use family = "gaussian" in your loess.smooth call.
Also note that the default values for loess.smooth are different from loess values, for example. for 'span' and 'degree' . Therefore, carefully check which models you want to fit and configure the appropriate default values.
For part 2:
DF <- data.frame(x = 0:50, y = rep(0,51)) mod <- loess(y ~ x, data = DF) pred <- predict(mod, newdata = data.frame(x = c(-1, 10, 15, 55))) mod2 <- loess(y ~ x, data = DF, control = loess.control(surface = "direct")) pred2 <- predict(mod2, newdata = data.frame(x = c(-1, 10, 15, 55)))
What gives:
> pred 1 2 3 4 NA 0 0 NA > pred2 1 2 3 4 0 0 0 0
The default value will not be extrapolated if that was what you had in mind. I do not see that there is a problem with using predict at all.
For part 3: Look at ?try Try and ?tryCatch , which you can wrap around the loess selection function ( loess.smooth say), which will allow you to continue the calculation if an error occurs in loess.smooth .
You need to handle the output of try or tryCatch by including something like this (if you do this in a loop:
mod <- try(loess.smooth(x, y)) if(inherits(mod, "try-error")) next ## if here, model work, do something with `mod`
I would probably combine try or tryCatch with installation via loess and using predict for such a problem.