如何从 `locfit` 和 `locfit.robust` 中提取预测?

How to extract predictions from `locfit` and `locfit.robust`?

如何从 locfit.robust 的输出中提取预测?

我已经想出如何绘制它,但我不知道如何实际提取预测。示例数据如下。

df <-
structure(list(x = c(45.0166666666667, 2.93361111111111, 22.7677777777778, 
34.6702777777778, 38.9808333333333, 2.07138888888889, 49.3283333333333, 
19.3177777777778, 42.4305555555556, 11.5561111111111, 29.6677777777778, 
6.38222222222222, 30.5302777777778, 52.775, 35.5325, 56.3958333333333, 
25.3544444444444, 10.6936111111111, 44.155, 31.3919444444444, 
13.2811111111111, 58.9841666666667, 7.24444444444444, 20.1802777777778, 
15.0061111111111, 51.0508333333333, 8.96916666666667, 32.945, 
27.9430555555556, 28.8055555555556, 3.79611111111111, 18.4558333333333, 
8.10694444444444), y = c(17.1906619704517, 51.3682492415682, 
34.5954944745371, 33.1782496417985, 28.8639252539494, 67.2499473509127, 
15.5739106117996, 29.7082944904524, 19.5924660810231, 27.6320399707289, 
30.09868839615, 33.7360588582795, 31.0412412696196, 85.8932775978829, 
29.6595900511557, 14.006526734448, 36.4282036185057, 25.3450383921273, 
17.0527246335207, 33.306938081975, 27.5846864057136, 15.9395044691672, 
28.7380574036629, 27.2409001620039, 26.5896320563312, 15.9792323783856, 
29.1293971960009, 94.2788150401981, 32.613338976917, 30.9617968951112, 
43.3449335001097, 30.6310217270105, 29.7063251039514)), .Names = c("x", 
"y"), class = c("tbl_df", "data.frame"), row.names = c(NA, -33L
))

我可以用以下方法绘制数据:

library(locfit)
with(df, plot(x = x, y = y))
fit <- with(df, locfit.robust(x = x, y = y))
lines(fit)

但是我怎样才能为 x 的每个值提取预测?

> predict(fit)
[1] 46.70358 13.45021 32.58037 27.64739 20.74407

我不知道这些值是什么。

怎么样

predict(fit,df$x)

##  [1] 20.56971 44.27524 30.19321 30.03639 25.91535 46.70358 17.84494 28.27135
##  [9] 22.57487 29.62954 32.77769 36.43389 32.57954 15.95173 29.28375 14.32950
## [17] 31.72052 30.39511 21.16722 32.23446 28.49327 13.45021 34.91145 28.67745
## [25] 27.84376 16.86136 32.35024 31.34679 32.70253 32.81179 42.03931 27.94946
## [33] 33.55193

看看?predict.locfit?preplot.locfit:我同意它有点不透明,但它应该会给你一些线索......我认为 predict(fit) 给你的是 "direct fitting points" 处的值,即用于拟合的多项式的节点。