# moving distance between two sets of data

6 messages
Open this post in threaded view
|
Report Content as Inappropriate

## moving distance between two sets of data

 On the surface this seems pretty simple, but I flummoxed. I have two sets of numbers they bounce around zero, positive one and negative one. They have a relationship between them, where one diverges away from the other. I want create a second set of numbers that tracks that divergence. #Lets make some data like mine, kinda Firstset <- runif(100, min = -1 , max =1) Secondset <- runif(100, min = -1 , max =1) #So something like: Divergence <- abs (Firstset - Secondset) #but this doesn't work because when Firstset is at .5 and Secondset is at  -.25 it returns .25 instead of .75 #another possibility is: Divergence <- abs (Firstset) - abs (Secondset) #but when Firstset is at .5 and Secondset is at -.5 it returns 0 instead of 1 #It seems like there is a better way to do this. Any ideas? ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: moving distance between two sets of data

 On Aug 19, 2012, at 12:04 PM, White, William Patrick wrote: > On the surface this seems pretty simple, but I flummoxed. I have two   > sets of numbers they bounce around zero, positive one and negative   > one. They have a relationship between them, where one diverges away   > from the other. I want create a second set of numbers that tracks   > that divergence. > > #Lets make some data like mine, kinda > Firstset <- runif(100, min = -1 , max =1) > Secondset <- runif(100, min = -1 , max =1) > > #So something like: > Divergence <- abs (Firstset - Secondset) > > #but this doesn't work because when Firstset is at .5 and Secondset   > is at  -.25 it returns .25 instead of .75    abs( .5 - (-.25) ) should NOT return .25 so you need to produce a   better example or point to specifics in the example you offered. If   what you wanting what you are getting, then use set.seed(123) and   refer to specific values.  > abs( .5 - (-.25) ) [1] 0.75 -- David. > > #another possibility is: > > Divergence <- abs (Firstset) - abs (Secondset) > > #but when Firstset is at .5 and Secondset is at -.5 it returns 0   > instead of 1 > > #It seems like there is a better way to do this. Any ideas? > ______________________________________________ > [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. David Winsemius, MD Alameda, CA, USA ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: moving distance between two sets of data

 On Aug 19, 2012, at 12:58 PM, David Winsemius wrote: > > On Aug 19, 2012, at 12:04 PM, White, William Patrick wrote: > >> On the surface this seems pretty simple, but I flummoxed. I have   >> two sets of numbers they bounce around zero, positive one and   >> negative one. They have a relationship between them, where one   >> diverges away from the other. I want create a second set of numbers   >> that tracks that divergence. >> >> #Lets make some data like mine, kinda >> Firstset <- runif(100, min = -1 , max =1) >> Secondset <- runif(100, min = -1 , max =1) >> >> #So something like: >> Divergence <- abs (Firstset - Secondset) >> >> #but this doesn't work because when Firstset is at .5 and Secondset   >> is at  -.25 it returns .25 instead of .75 > >  abs( .5 - (-.25) ) should NOT return .25 so you need to produce a   > better example or point to specifics in the example you offered. If   > what you wanting what you are getting, then use set.seed(123) and   > refer to specific values. I meant to write:  "If you are not getting what you are wanting .... " > > > abs( .5 - (-.25) ) > [1] 0.75 > > -- > David. > >> >> #another possibility is: >> >> Divergence <- abs (Firstset) - abs (Secondset) >> >> #but when Firstset is at .5 and Secondset is at -.5 it returns 0   >> instead of 1 >> >> #It seems like there is a better way to do this. Any ideas? >> ______________________________________________ >> [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. > > David Winsemius, MD > Alameda, CA, USA > > ______________________________________________ > [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. David Winsemius, MD Alameda, CA, USA ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: moving distance between two sets of data

 In reply to this post by David Winsemius The first method described produces a value other than the desired output every time the Firstset value is positive and the Secondset is negative, such as the second instance when seed is set to 123. The second method described produces a value other than the desired output every time the Firstset is negative and Secondset is positive, such as the first value derived from seed 123. ________________________________________ From: David Winsemius [[hidden email]] Sent: Sunday, August 19, 2012 3:58 PM To: White, William Patrick Cc: [hidden email] Subject: Re: [R] moving distance between two sets of data On Aug 19, 2012, at 12:04 PM, White, William Patrick wrote: > On the surface this seems pretty simple, but I flummoxed. I have two > sets of numbers they bounce around zero, positive one and negative > one. They have a relationship between them, where one diverges away > from the other. I want create a second set of numbers that tracks > that divergence. > > #Lets make some data like mine, kinda > Firstset <- runif(100, min = -1 , max =1) > Secondset <- runif(100, min = -1 , max =1) > > #So something like: > Divergence <- abs (Firstset - Secondset) > > #but this doesn't work because when Firstset is at .5 and Secondset > is at  -.25 it returns .25 instead of .75    abs( .5 - (-.25) ) should NOT return .25 so you need to produce a better example or point to specifics in the example you offered. If what you wanting what you are getting, then use set.seed(123) and refer to specific values.  > abs( .5 - (-.25) ) [1] 0.75 -- David. > > #another possibility is: > > Divergence <- abs (Firstset) - abs (Secondset) > > #but when Firstset is at .5 and Secondset is at -.5 it returns 0 > instead of 1 > > #It seems like there is a better way to do this. Any ideas? > ______________________________________________ > [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. David Winsemius, MD Alameda, CA, USA ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|
Report Content as Inappropriate

## Re: moving distance between two sets of data

 In reply to this post by David Winsemius Also it occurred to me that my initial explanation was not explicitly clear as to what the desired output is. What I am trying to get is a moving absolute deviation between the two sets of numbers. This is not to be confused with the mean absolute deviation, or the median absolute deviation which are both something different and not what i am after. ________________________________________ From: David Winsemius [[hidden email]] Sent: Sunday, August 19, 2012 4:03 PM To: David Winsemius Cc: White, William Patrick; [hidden email] Subject: Re: [R] moving distance between two sets of data On Aug 19, 2012, at 12:58 PM, David Winsemius wrote: > > On Aug 19, 2012, at 12:04 PM, White, William Patrick wrote: > >> On the surface this seems pretty simple, but I flummoxed. I have >> two sets of numbers they bounce around zero, positive one and >> negative one. They have a relationship between them, where one >> diverges away from the other. I want create a second set of numbers >> that tracks that divergence. >> >> #Lets make some data like mine, kinda >> Firstset <- runif(100, min = -1 , max =1) >> Secondset <- runif(100, min = -1 , max =1) >> >> #So something like: >> Divergence <- abs (Firstset - Secondset) >> >> #but this doesn't work because when Firstset is at .5 and Secondset >> is at  -.25 it returns .25 instead of .75 > >  abs( .5 - (-.25) ) should NOT return .25 so you need to produce a > better example or point to specifics in the example you offered. If > what you wanting what you are getting, then use set.seed(123) and > refer to specific values. I meant to write:  "If you are not getting what you are wanting .... " > > > abs( .5 - (-.25) ) > [1] 0.75 > > -- > David. > >> >> #another possibility is: >> >> Divergence <- abs (Firstset) - abs (Secondset) >> >> #but when Firstset is at .5 and Secondset is at -.5 it returns 0 >> instead of 1 >> >> #It seems like there is a better way to do this. Any ideas? >> ______________________________________________ >> [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. > > David Winsemius, MD > Alameda, CA, USA > > ______________________________________________ > [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. David Winsemius, MD Alameda, CA, USA ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.