Grabbing Indexes of a certain standard deviation

classic Classic list List threaded Threaded
7 messages Options
ccm
Reply | Threaded
Open this post in threaded view
|

Grabbing Indexes of a certain standard deviation

ccm
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Grabbing Indexes of a certain standard deviation

Adams, Jean
I wrote a little function called first() to help with situations like
this.  It returns a 1 every time an element of a vector is different from
the previous element, and a 0 otherwise.

first <- function(x) {
    L <- length(x)
    c(1, 1-(x[-1]==x[-L]))
    }

sd <- 1
residuals <- c(1, 2.1, 3, 4, 3, 1, 0, -4, -1)
# logical, indicating if the residual exceeds 2 standard deviations
exceed <- abs(residuals) > (2*sd)
# indices of the first exceeding residual of a series
which(first(exceed) & exceed)

Jean


gcm <[hidden email]> wrote on 07/12/2012 11:07:49 AM:

> I have a graph of residuals and I am attempting to get a list of the
indexes
> of each time the residual is greater than 2 standard deviations or less
than
> -2 standard deviations, but only the first point of the section. And
then
> I'd also need the first point where the point returns to the range
between
> +/- 2 standard deviations.
> So basically if my standard deviation=1 and my residuals=c(1, 2.1, 3, 4,
3,
> 1, 0, -4, -1) I want it to grab the second number, where it exceeds 2
> standard deviations and the 6th where it returns to less than 2 standard
> deviations. Also, it would grab -4 (or residuals[ 8]) and -1
(residuals[9])

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
ccm
Reply | Threaded
Open this post in threaded view
|

RE: Grabbing Indexes of a certain standard deviation

ccm
This post has NOT been accepted by the mailing list yet.
CONTENTS DELETED
The author has deleted this message.
ccm
Reply | Threaded
Open this post in threaded view
|

RE: Grabbing Indexes of a certain standard deviation

ccm
This post was updated on .
In reply to this post by Adams, Jean
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Grabbing Indexes of a certain standard deviation

Adams, Jean
residuals[abs(residuals) > (2*sd)]


gcm <[hidden email]> wrote on 07/16/2012 07:07:31 AM:

> Jean, how would you modify your function to grab all the selected
> and not just the first?
> Thank you so much!
>
> From: Jean V Adams [via R] [
mailto:[hidden email]]
> Sent: Thursday, July 12, 2012 4:59 PM
> To: Lauren Vogric
> Subject: Re: Grabbing Indexes of a certain standard deviation
>
> I wrote a little function called first() to help with situations like
> this.  It returns a 1 every time an element of a vector is different
from

> the previous element, and a 0 otherwise.
>
> first <- function(x) {
>     L <- length(x)
>     c(1, 1-(x[-1]==x[-L]))
>     }
>
> sd <- 1
> residuals <- c(1, 2.1, 3, 4, 3, 1, 0, -4, -1)
> # logical, indicating if the residual exceeds 2 standard deviations
> exceed <- abs(residuals) > (2*sd)
> # indices of the first exceeding residual of a series
> which(first(exceed) & exceed)
>
> Jean
>
>
> gcm <[hidden email]</user/SendEmail.jtp?type=node&node=4636370&i=0>>
> wrote on 07/12/2012 11:07:49 AM:
>
> > I have a graph of residuals and I am attempting to get a list of the
> indexes
> > of each time the residual is greater than 2 standard deviations or
less
> than
> > -2 standard deviations, but only the first point of the section. And
> then
> > I'd also need the first point where the point returns to the range
> between
> > +/- 2 standard deviations.
> > So basically if my standard deviation=1 and my residuals=c(1, 2.1, 3,
4,
> 3,
> > 1, 0, -4, -1) I want it to grab the second number, where it exceeds 2
> > standard deviations and the 6th where it returns to less than 2
standard
> > deviations. Also, it would grab -4 (or residuals[ 8]) and -1
> (residuals[9])

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
ccm
Reply | Threaded
Open this post in threaded view
|

RE: Grabbing Indexes of a certain standard deviation

ccm
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Grabbing Indexes of a certain standard deviation

Adams, Jean
seq(residuals)[abs(residuals) > (2*sd)]


gcm <[hidden email]> wrote on 07/16/2012 07:39:20 AM:

> But I'll need the indexes and that gives me the values. I need to
> then be able to make the indexes into a list of numbers.
>
> From: Jean V Adams [via R] [
mailto:[hidden email]]

> Sent: Monday, July 16, 2012 8:38 AM
> To: Lauren Vogric
> Subject: Re: Grabbing Indexes of a certain standard deviation
>
> residuals[abs(residuals) > (2*sd)]
>
>
> gcm <[hidden email]</user/SendEmail.jtp?type=node&node=4636641&i=0>>
> wrote on 07/16/2012 07:07:31 AM:
>
> > Jean, how would you modify your function to grab all the selected
> > and not just the first?
> > Thank you so much!
> >
> > From: Jean V Adams [via R] [
> mailto:[hidden email]</user/SendEmail.jtp?type=node&node=4636641&i=1>]
> > Sent: Thursday, July 12, 2012 4:59 PM
> > To: Lauren Vogric
> > Subject: Re: Grabbing Indexes of a certain standard deviation
> >
> > I wrote a little function called first() to help with situations like
> > this.  It returns a 1 every time an element of a vector is different
> from
>
> > the previous element, and a 0 otherwise.
> >
> > first <- function(x) {
> >     L <- length(x)
> >     c(1, 1-(x[-1]==x[-L]))
> >     }
> >
> > sd <- 1
> > residuals <- c(1, 2.1, 3, 4, 3, 1, 0, -4, -1)
> > # logical, indicating if the residual exceeds 2 standard deviations
> > exceed <- abs(residuals) > (2*sd)
> > # indices of the first exceeding residual of a series
> > which(first(exceed) & exceed)
> >
> > Jean
> >
> >
> > gcm <[hidden email]</user/SendEmail.jtp?type=node&node=4636370&i=0>>
> > wrote on 07/12/2012 11:07:49 AM:
> >
> > > I have a graph of residuals and I am attempting to get a list of the
> > indexes
> > > of each time the residual is greater than 2 standard deviations or
> less
> > than
> > > -2 standard deviations, but only the first point of the section. And
> > then
> > > I'd also need the first point where the point returns to the range
> > between
> > > +/- 2 standard deviations.
> > > So basically if my standard deviation=1 and my residuals=c(1, 2.1,
3,
> 4,
> > 3,
> > > 1, 0, -4, -1) I want it to grab the second number, where it exceeds
2
> > > standard deviations and the 6th where it returns to less than 2
> standard
> > > deviations. Also, it would grab -4 (or residuals[ 8]) and -1
> > (residuals[9])

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.