0
    ggplot(test,aes(x=timepoints,y= mean,ymax = mean + sde, ymin = mean  - sde)) + 
       geom_errorbar(width=2) +
       geom_point() +
       geom_line() +
       stat_smooth(method='loess') + 
       xlab('Time (min)') +
       ylab('Fold Induction') +          
       opts(title = 'yo')   

enter image description here

I can plot the blue 'loess'-ed line. But is there a way to find the mathematical function of the blue 'loess'-ed line?

3
  • it's not easy. The results of a generalized additive model (geom_smooth(method="gcv")) are a little bit easier to formally define, but even there it would be hard. If you want to fit a particular parametric curve, that's a lot harder and not as easily automated. If you say a little more about what you want to do with the results (e.g. make predictions for novel data? Compare fits across different data sets? Test specific hypotheses?) you might get more help ...
    – Ben Bolker
    Sep 18, 2012 at 19:56
  • I think i would actually get less help were i to include some ambiguous future motives
    – Doug
    Sep 18, 2012 at 21:22
  • OK, then, can you be more specific about what you mean by "the mathematical function"? We could point you toward the definition of locally weighted regressions, and you could (a) inspect the output of loess (as suggested by @DWin below), (b) get predictions - but I suspect you want a parametric model. One way or another, a little more detail would help.
    – Ben Bolker
    Sep 18, 2012 at 21:27

3 Answers 3

0

You can get the predictions for a regular sequence:

 fit <-loess( mean ~ timepoints, data=test)
 fit.points <- predict(fit, newdata=  data.frame(
                  speed = seq(min(timepoints), max(timepoints), length=100)), 
              se = FALSE)
 fitdf <- dataframe(x = seq(min(timepoints), max(timepoints), length=100)
                    y = fit.points)

You can then fit to that set of points with splines of an appropriate degree. Cubic spline fits can be described with greater ease than can loess fits.It would be easier to synchronize an answer to variable names it you had offered a data example to work with. The plot does not seem to be created with that code.

4
  • why do you make the first 'fit' loess?
    – Doug
    Sep 18, 2012 at 21:25
  • ... because that was the method you used in your example. I meant to change the argument to predict.loess. Sorry for the confusion.
    – IRTFM
    Sep 18, 2012 at 21:28
  • predict.loess() isn't a function?
    – Doug
    Sep 18, 2012 at 21:49
  • I meant that to be interpreted as "I meant to change the argument [given] to predict.loess". The original was a "cars" data argument.
    – IRTFM
    Sep 18, 2012 at 22:03
0

Rule Number One: not all distributions have a (closed-form) function which generates them. Yes, you can create a close fit by way of splines, or calculating moments (mean, variance, skew, etc) and building the series, so your choice depends on whether you intend to interpolate, extrapolate, or just "view" the resultant function.

In the scientific world, it's more common to have a theory, or premise, about the behavior behind your data. You can then do standard (e.g. nls) fitting methods to see how well the proposed fit function can be made to match your data.

0

To understand how the loess line is computed see the loess.demo function in the TeachingDemos package. This is an interactive graphical demonstration that will show how the y-value at each point is computed for each x-value based on the data and bandwidth parameter (it also shows the difference in the raw loess fit and the spline that is often fit to the loess estimates).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.