I have a time series that looks like a jagged shape. I want to know the positive or negative slope of the jagged depression. Sometimes the noise in this time series can be heavy, so it is difficult to clearly see the positive or negative. I used a simple linear fitting to calculate the global slope and rregard it with the positive or negative slope. However, it is obvious that many times this did not work. Thank you. One example of the data in R is attached as follows, thank you.
`aa <-c(seq(1,50,1),seq(51,5,-10),seq(1,50,1),seq(51,5,-10),seq(1,50,1),seq(51,5,-10),seq(1,50,1),seq(51,5,-10),seq(1,50,1),seq(51,5,-10),seq(1,50,1),seq(51,5,-10))
bb <- scale(aa)+0.5*rnorm(length(aa))`
To be specific, I would like know if the sign of the slope of the parts (created by seq(1,50,1)) is positive or negative. Thanks
this is the code in R that I used to take its sign by simply using linear fitting,
t <- seq(1,length(aa),1) v <- lm(bb~t,na.action=na.omit) v_sign <- v$coefficients[2]
This did not work in many cases, therefore I would like to see any suggestions or help from the community to help resolve this issue. Thanks