0

我有一个使用Scatter.Smooth函数平滑的图表。鉴于 X 轴是日期,我需要获取坐标。

平滑曲线在 Knime R 节点中生成。我想要这些点以便在 Line Plot 节点中使用它。

有没有其他方法可以从生成的图表中获取值到 Knime 中的线图?

更新

我添加了用于在 R 节点中生成平滑曲线的 R 代码

 plot(x,y)
 scatter.smooth(x,y)

 //x<- Date
 //y <- Frequency
 //Basically the values are from the Data file in another node. For simplicity I have mentioned it as comments
4

2 回答 2

0

这是 R 的函数定义scatter.smooth

function (x, y = NULL, span = 2/3, degree = 1, family = c("symmetric", 
    "gaussian"), xlab = NULL, ylab = NULL, ylim = range(y, pred$y, 
    na.rm = TRUE), evaluation = 50, ..., lpars = list()) 
{
    xlabel <- if (!missing(x)) 
        deparse(substitute(x))
    ylabel <- if (!missing(y)) 
        deparse(substitute(y))
    xy <- xy.coords(x, y, xlabel, ylabel)
    x <- xy$x
    y <- xy$y
    xlab <- if (is.null(xlab)) 
        xy$xlab
    else xlab
    ylab <- if (is.null(ylab)) 
        xy$ylab
    else ylab
    pred <- loess.smooth(x, y, span, degree, family, evaluation)
    plot(x, y, ylim = ylim, xlab = xlab, ylab = ylab, ...)
    do.call(lines, c(list(pred), lpars))
    invisible()
}

看起来

pred <- loess.smooth(x, y, span, degree, family, evaluation)

将包含您需要的内容。

于 2016-03-02T15:13:00.897 回答
0

使用 scatter.smooth() 或 loess.smooth() 从回归线获取点是错误的方法。Loess.smooth() 仅提供足够的点来绘制一条不用于预测值的线。您想创建一个方程,然后使用它来预测您的原始 x 点或一组新点。有很多方法可以做到这一点 loess.smooth(以及 scatter.smooth)都实现了局部多项式回归。要实际实现回归并获得方程,您可能会执行以下操作:

library(locfit)
x <- rnorm(50, 20, 2)
y <- rnorm(50, x, 1)
myLoc <- locfit(x~y)
predPoints <- predict(myLoc, x)

如果您愿意,我们可以将其与以下结果进行比较loess.smooth()

mySmooth <- loess.smooth(x,y)
plot(x,y)
points(x, predPoints, col = 'red')
points(mySmooth$x, mySmooth$y, col = 'blue')

您会注意到这两种方法产生的结果略有不同。两者都不是更好或更坏,它在很大程度上取决于您的数据的性质和您的目标是什么。有许多方法可以评估回归,以尝试评估它们的准确性和有效性。

于 2016-03-02T15:54:46.560 回答