[R] deconstructing curve into rising and falling limbs

chuck.01 CharlieTheBrown77 at gmail.com
Fri Oct 26 16:07:33 CEST 2012


Thanks Jean, 
Your 1st solution was one I've tried, w/o great success.  The 2nd works a
lot better (on real, and more messy, data), especially when I set span to a
much smaller number than 1/10.   
Thank you greatly. 
-Chuck


Jean V Adams wrote
> Using the data you provided, a combination of slope and height comes 
> close:
> 
> X <- seq(Y)
> high <- Y > 0.6
> 
> upslope <- c(FALSE, diff(Y) > 0)
> section <- rep(1, length(Y))
> section[upslope==TRUE & high==TRUE] <- 2
> section[upslope==FALSE & high==TRUE] <- 3
> plot(X, Y, col=section)
> 
> 
> Or you could base the slope on the a smooth fit of the data rather than Y 
> itself:
> 
> P <- loess(Y ~ X, degree=2, span=1/10)$fitted
> 
> upslope <- c(FALSE, diff(P) > 0)
> section <- rep(1, length(Y))
> section[upslope==TRUE & high==TRUE] <- 2
> section[upslope==FALSE & high==TRUE] <- 3
> plot(X, Y, col=section)
> 
> Jean
> 
> 
> 
> "chuck.01" <

> CharlieTheBrown77@

> > wrote on 10/26/2012 03:14:29 AM:
>> 
>> hello, 
>> I have some data that looks similar to this (only not as nice as this):
>> 
>> Y <- c(abs(rnorm(100, 0.10, .1)), seq(.10, 1.0, .3)+rnorm(1, 0, .5) , 
>> seq(0.8, 4.0, .31)+rnorm(1, 0, .5)
>> , seq(3.9, .20, -.2)+rnorm(1, 0, .5) , abs(rnorm(100, 0.13, .1)) , 
> seq(.10,
>> 1.2, .35)+rnorm(1, 0, .5)
>> , seq(0.7, 6.0, .31)+rnorm(1, 0, .5) , seq(5.9, .23, -.18)+rnorm(1, 0, 
> .5) ,
>> abs(rnorm(50, 0.18, .1)) )
>> 
>> plot(Y~c(1:length(Y)))  # it is water level through time
>> 
>> I am trying to find a way to divide these data into 3 sections , 1) the
>> rising limbs, 2) falling limbs, and 3) not #1 or #2. 
>> I'll spare you the list of things I've tried, just know that the data is
>> generally too noisy to use something as simple as which(diff(Y) > b), 
> where
>> b is some threshold. 
>> Please let me know if you have an idea of how to tackle this. 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________

> R-help@

>  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.





--
View this message in context: http://r.789695.n4.nabble.com/deconstructing-curve-into-rising-and-falling-limbs-tp4647512p4647550.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list