Here is a test code to calculate the derivative of a curve in sliding windows. I generated a linear example, and it should plot the derivative in a straight line. But, it does not?!
-------------- x = seq(0,10,by=0.1) y = x * 0.5 + 0.1 window=15; half = floor( window/2) x2 = half: (length(x)-half) ; slope = half: (length(x)-half) ; count = 1; for( i in half: (length(x)-half) ) { pos = (i-half):(i+half) m = lm( y[pos] ~ x[pos]) x2[count] = x[i] slope[count] = m$coeff[2]; count = count + 1; } plot( slope ~ x2, type='l' ) #does not give a straight line, why? [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.