0

I have some data which I've undertaken a 7 order polynomial regression on using r; the plot resembles a bell curve.

I need to find the two steepest parts of the curve. So far I have managed to find and show the steepest ascending slope, now I need the steepest descending slope.

Here is what I have so far:

attach(DATA1)
names(DATA1)

"dist"  "ohms"

plot(dist,ohms)
reg<-lm(ohms~poly(dist,7))
summary(reg)
lines(smooth.spline(dist,predict(reg)))
xv<-seq(min(dist),max(dist),0.02)
yv<-predict(reg,list(dist=xv))
lines(xv,yv,lwd=2)
plot(xv,yv,type="l")
xv[which(abs(diff(yv))==max(abs(diff(yv))))]
abline(v=xv[which(abs(diff(yv))==max(abs(diff(yv))))])

Does anybody know how to find the steepest descending part of the slope?

Thanks

A.Benson
  • 465
  • 1
  • 6
  • 16
  • Posting code to load objects we don't have seems pointless, even annoying. For your task why not split the range over which you are doing you searching inot 2 sections below and above the maximum? – IRTFM May 22 '17 at 03:21

1 Answers1

0

I think that you have a problem here:

abs(diff(yv))==max(abs(diff(yv)))

In this line, diff(yv) is almost the derivative of yv. By taking the absolute value of it you are ignoring whether yv increases or decreases so you'll get either the steepest ascent or descent, but you will not know which one.

Since you are interested in finding the steepest ascent and descent try this instead:

diff(yv) == max(diff(yv))
diff(yv) == min(diff(yv))

The first should return true when the change in yv is maximum (steepest ascent) and the second one where it has the steepest descent.

R. Schifini
  • 9,085
  • 2
  • 26
  • 32
  • Great answer, this helped a lot. I have another query relating to the same topic. Some of the bell curve plots show a sharp descent/ascent at one or both ends of the curve. However, I am only interested in the steepness of the slope of the central region of the plot. Is there a way I can exclude certain x values from the command, i.e. search for the steepest parts of the slope within an upper and lower x limit? – A.Benson May 25 '17 at 23:24