0
votes

I have a graph that was smoothed using Scatter.Smooth function. I need to get the co-ordinates given the X-axis being the date.

The smoothed curve is generated in Knime R Node. I want the points so as to use it in a Line Plot node.

Is there any other method to get the values from the generated graph to line plot in Knime?

Update

I have added the R code that I used to generate the smooth curve in R node

 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
2
can you provide an example of that smoothed curve code?cory
I could add the code that I used for generating the smoothed curve. Check the UpdateVini
If you want to use the actual results from a smooth you're probably better off using a function such as locfit or a spline to generate the data. This will give you a lot more control to ensure you're developing a model that fits your data well and minimizes bias. The scatter.smooth function implements a smoothing function behind the scenes but it gives you minimal control on how the function is implemented. You can then plot the results from the the smooths on top of your scatter if you'd like.admccurdy
I tried Spline, but for some reason i am not getting it the right way.. :(Vini

2 Answers

0
votes

This is the function definition for R's 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()
}

It would seem that

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

will contain what you need.

0
votes

Using either scatter.smooth() or loess.smooth() to get points from a regression line is the wrong way to go about it. Loess.smooth() is only providing enough points to plot a line it's not meant for predicting values. You want to create an equation and then use that to predict on your original x points or a new set of points. There are tons of ways to do this loess.smooth (and thus scatter.smooth) both implement a local polynomial regression. To actually implement the regression and get an equation you might do something like this:

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

If you'd like we can compare this to the results from loess.smooth():

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

You'll notice the two methods produce slightly different results. Neither is better or worse it is very dependent on the nature of your data and what your goals are. There a number of ways to evaluate regressions to try and assess both their accuracy and their validity.