4

I have some data which I would like to fit with a model. For this example we have been using LOESS smoothing (<1.000 observations). We applied LOESS smoothing using the geom_smooth() function from the ggplot package. So far, so good.

The next step was to acquire a first derivative of the smoothed curve, and as far as we know this is not possible to extract from geom_smooth(). Thus, we sought to manually create our model using loess() and use this to extract our first derivative from this.

Strangely however, we observed that the plotted geom_smooth() curve is different from the manually constructed loess() curve. This can be observed in the figure which is shown underneath; in red the geom_smooth() and in orange the loess() function.

If somebody would be interested, a minimal working reproducible example can be found here.

Would somebody be able to pinpoint why the curves are different? Is this because of the optimization settings of both curves? In order to acquire a meaningful derivative we need to ensure that these curves are identical.

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
wptmdoorn
  • 160
  • 1
  • 12
  • 3
    `scale_y_log10(limits = c(1,50000))` removes certain values, which influences the fit done by `ggplot2`, remove it (or change the limits) and both curves are identical. – erc Aug 30 '18 at 13:09
  • Thanks you are totally correct, beetroot. Would there be any way to change the y-scale to a logaritmic format after statistical smoothing? As far as I know (and found), the cartesian coords system does not allow you to change the scaling type on your axes. – wptmdoorn Aug 30 '18 at 13:43
  • I think the general answer is to use ggplot2 for plotting and to do everything else beforehand. I have no specific answer to your question, maybe someone else does. – erc Aug 30 '18 at 16:22
  • Possible Duplicate: https://stackoverflow.com/questions/72325105/loess-vs-geom-smooth-giving-different-curves – vem325 May 11 '23 at 19:30

0 Answers0