[R] Finding center of mass in a hydrologic time series

Thierry Onkelinx thierry.onkelinx at inbo.be
Sat Dec 16 17:32:41 CET 2017


Slightly faster: sum(cumsum(hyd) <= .5 * sum(hyd))

Best regards,

ir. Thierry Onkelinx
Statisticus / Statistician

Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE
AND FOREST
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry.onkelinx op inbo.be
Kliniekstraat 25, B-1070 Brussel
www.inbo.be

///////////////////////////////////////////////////////////////////////////////////////////
To call in the statistician after the experiment is done may be no
more than asking him to perform a post-mortem examination: he may be
able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does
not ensure that a reasonable answer can be extracted from a given body
of data. ~ John Tukey
///////////////////////////////////////////////////////////////////////////////////////////


Van 14 tot en met 19 december 2017 verhuizen we uit onze vestiging in
Brussel naar het Herman Teirlinckgebouw op de site Thurn & Taxis.
Vanaf dan ben je welkom op het nieuwe adres: Havenlaan 88 bus 73, 1000 Brussel.

///////////////////////////////////////////////////////////////////////////////////////////



2017-12-16 14:32 GMT+01:00 Eric Berger <ericjberger op gmail.com>:
> Hi Eric,
> How about
>
> match( TRUE, cumsum(hyd/sum(hyd)) > .5 ) - 1
>
> HTH,
> Eric
>
>
> On Sat, Dec 16, 2017 at 3:18 PM, Morway, Eric <emorway op usgs.gov> wrote:
>
>> The small bit of script below is an example of what I'm attempting to do -
>> find the day on which the 'center of mass' occurs.  In case that is the
>> wrong term, I'd like to know the day that essentially cuts the area under
>> the curve in to two equal parts:
>>
>> set.seed(4004)
>> Date <- seq(as.Date('2000-09-01'), as.Date('2000-09-30'), by='day')
>> hyd <- ((100*(sin(seq(0.5,4.5,length.out=30))+10) +
>> seq(45,1,length.out=30)) + rnorm(30)*8) - 800
>>
>> # View the example curve
>> plot(Date, hyd, las=1)
>>
>> # By trial-and-error, the day on which the center of mass occurs is the
>> 11th day:
>> # Add up the area under the curve for the first 11 days and compare
>> # with the last 19 days:
>>
>> sum(hyd[1:11])
>> # 3546.364
>> sum(hyd[12:30])
>> # 3947.553
>>
>> # Add up the area under the curve for the first 12 days and compare
>> # with the last 18 days:
>>
>> sum(hyd[1:12])
>> # 3875.753
>> sum(hyd[13:30])
>> # 3618.164
>>
>> By day 12, the halfway point has already been passed, so the answer that
>> would be returned would be:
>>
>> Date[11]
>> # "2000-09-11"
>>
>> For the larger problem, it'd be handy if the proposed function could
>> process a multi-year time series (a runoff hydrograph) and return the day
>> of the center of mass for each year in the time series.
>>
>> I appreciate any pointers...Eric
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help op r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.
>>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help op r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.



More information about the R-help mailing list