# R: [R] slope estimations of teeth like data

Vito Muggeo vito.muggeo at giustizia.it
Tue Jun 15 13:52:34 CEST 2004

```Dear Petr,
Probably I don't understand exactly what you are looking for.

However your "plot(x,c(y,z))" suggests a broken-line model for the response
"c(y,x)" versus the variables x. Therefore you could estimate a segmented
model to obtain (different) slope (and breakpoint) estimates. See the
package segmented.

best,
vito

----- Original Message -----
From: Petr Pikal <petr.pikal at precheza.cz>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, June 15, 2004 1:11 PM
Subject: [R] slope estimations of teeth like data

> Dear all
>
> Suppose I have teeth like data similar like
>
> x <- 1:200
> y <- 0.03*x[1:100]+rnorm(100, mean=.001, sd=.03)
> z <- 3-rep(seq(1,100,10),each=10)*.03+rnorm(100,mean=.001, sd=.03)
> plot(x,c(y,z))
>
> and I want to have a gradient estimations for some values from increasing
part of
> data
>
> like
>
> y.agg <- aggregate(diff(c(y,z)), list(rep(seq(1,200,10),each=10)[1:199]),
mean)
>
> y.agg[1:10,]  ##is OK, I want that
> y.agg[11:20,] ##is not OK, I do not want that
>
> actual data are similar but more irregular and have subsequent gradual
increases
> and decreases, more like
>
> set.seed(1)
> yy<-NULL
> for( i in 1:10) yy <- c(yy,c(y,z)[1:floor(runif(1)*200)])
> length(yy)
>  1098
>
> plot(1:1098,yy)
>
> Is there anybody who has some experience with such data, mainly how to
extract
> only increasing portions or to filter values of "yy" such as only
aggregated slopes
> from increasing parts are computed and other parts are set to NA.
Sometimes
> actual data have so long parts of steady or even slightly increasing
values at
> decreasing part that aggregated values are slightly positive although they
are
> actually from decreasing portion of data.
>
> Thank you
> Petr Pikal
> petr.pikal at precheza.cz
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help