Skip to content

please show me simple example how to plot "Distance-Weighted Least Squares" fitting

5 messages · madr, Sarah Goslee, Peter Ehlers +1 more

#
I got simple x,y pairs of data and simple scatterplot and just cannot figure
how to do it , there are many examples but always there is error popping out

please show me an example stripped with additional data just core of what I
need to do to get this damn line
#
It's impossible to give you really good advice without an example of
your data, the R code you used and the error message.

But here's a simple scatterplot example:

fakedata <- data.frame(x=runif(15), y=runif(15))
plot(fakedata$x, fakedata$y)

or since you mentioned a line:

fakedata <- fakedata[order(fakedata$x),]
plot(fakedata$x, fakedata$y, type="l")

For anything more, we would need the information requested in the
R-help posting guide linked at the bottom of each and every R-help
message.

Sarah
On Tue, Dec 7, 2010 at 12:17 PM, madr <madrazel at interia.pl> wrote:

  
    
#
Well, maybe I didn't write it clear.
I know how to create scatterplot, and how to import data from csv file.
But I do not know how to add this fitting that mentioned in sumbject to a
plot.
I do not know for what function name to look for in R. I played some time
with ls, and it didn't create a line. I know the name for the fitting I ned
from Statistica, and this is from help from this program:

"A curve is fitted to the XY coordinate data according to the
distance-weighted least squares smoothing procedure (the influence of
individual points decreases with the horizontal distance from the respective
points on the curve). For more information, see Distance-Weighted Least
Squares."

Now I need to recreate it in R.

Sorry again for not being clear.
#
On 2010-12-07 09:37, madr wrote:
Sounds like loess() to me.

Peter Ehlers
#
Like Peter says, this sounds like loess, there are examples on the help page for scatter.smooth, you could also do this with lattice graphics using type=c('p','smooth'), or ggplot2 graphics (probably something like geom_smooth or geom_loess, I don't know ggplot2 that well yet).

If you want to learn more about how loess works then use loess.demo in the TeachingDemos package.  

There are also other smoothers available, but we would need more information before knowing where to point you.

For adding a general curve or line to a scatterplot also look at functions like "lines", "abline", and "curve", as well as the entire ggplot2 package.