LISTSERV mailing list manager LISTSERV 16.0

Help for R-USERS-L Archives


R-USERS-L Archives

R-USERS-L Archives


R-USERS-L@LISTS.UFL.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

R-USERS-L Home

R-USERS-L Home

R-USERS-L  2014

R-USERS-L 2014

Subject:

Re: Need help on Rolling standard deviation with jump

From:

Forrest Stevens <[log in to unmask]>

Reply-To:

UF R Users List <[log in to unmask]>

Date:

Sun, 31 Aug 2014 12:15:18 -0400

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (127 lines)

Well, if you change the rollapply() function call's by= argument to 1 then
you will have a sliding window analysis.  I guess I misunderstood your
original description.

s <- rollapply(dz[,1], width=5, by=1, FUN=sd, na.rm=TRUE)

da <- merge(dz, s)

Each date in the resulting series will consist of the SD of the labeled
date and the 4 previous.  If you need that shifted it should be trivial to
just shift the values and create a new time series with the shifted dates
but values from the rollapply().

Sincerely,
Forrest


--
Forrest R. Stevens
Ph.D. Candidate, QSE3 IGERT Fellow
Department of Geography
Land Use and Environmental Change Institute
University of Florida
www.clas.ufl.edu/users/forrest


On Sun, Aug 31, 2014 at 12:05 PM, Bhattacharya,Souvik <[log in to unmask]>
wrote:

> Hi Forrest,
>
> Thanks for your suggestions. But this rolling sd computes the sd for the
> rows, 1:5, 6:11, 12:17,....What I want is to calculate the sd for the rows
> 1:5, 2:6, 3:7, likewise
> Thanks
> Souvik
>
>
>
>
> On Sun, 31 Aug 2014 10:25:23 -0400, Forrest Stevens wrote:
>
>> I think that rollapply() is actually what you want unless I'm
>> misunderstanding your data structure. For example, this is what I think
>> you're trying to accomplish:
>>
>>
>> require(xts)
>>
>> d <- zooreg(rnorm(50), order.by=as.Date(1:50), deltat=1/365)
>>
>> ## Make an irregular time series out of it:
>> di <- sample(d, 40)
>>
>> ## This I think approximates the data you have:
>> ds <- xts(di)
>> dz <- merge(ds, d)
>>
>> s <- rollapply(dz[,1], width=5, by=5, FUN=sd, na.rm=TRUE)
>>
>>
>> It would help if you supplied a full sample of your data and the code
>> you're using to prepare it, or at least something like the above.  But
>> hopefully this gets you part of the way there.
>>
>> Sincerely,
>> Forrest
>>
>> --
>> Forrest R. Stevens
>> Ph.D. Candidate, QSE3 IGERT Fellow
>> Department of Geography
>> Land Use and Environmental Change Institute
>> University of Florida
>> www.clas.ufl.edu/users/forrest
>>
>>
>> On Sun, Aug 31, 2014 at 7:10 AM, Bhattacharya,Souvik <[log in to unmask]>
>> wrote:
>>
>>  Hi Guys,
>>>
>>> I have a time series dataframe which looks like
>>>
>>> 2014-02-05 2014-02-06 2014-02-07 2014-02-12 2014-02-14 2014-02-17
>>> 2014-02-18 2014-02-19 ......
>>>     0.0379    -0.0008     0.0352     0.0379     0.0392     0.0173
>>>  0.0360     0.0371
>>>
>>> I want to compute moving standard deviation for every 5th day data from
>>> this list. What I mean is that, I wish to select a sample in the form
>>> such
>>> that sample1[1] = 2014-02-05  0.0379 , sample1[2] =2014-02-12
>>> 0.0379.....and then find the std dev of this sample and then use a
>>> rolling
>>> standard deviation to move on to the next date i.e. sample2[1]
>>> =2014-02-06
>>> -0.0008 , sample2[2] =2014-02-12 0.0379 and find the standard deviation
>>> of
>>> this list and so on. Since day available is irregular, I cannot use
>>> seq(1:l, by = ). In rollapply, the function would take every consecutive
>>> numbers to compute the standard deviation. Is there a way to sample every
>>> 5th day data from this list in an efficient way, or modify the standard
>>> deviation function somehow, to make it select every 5th day data and then
>>> compute the standard deviation on the available data. Any suggestion in
>>> this regard will be highly appreciated.
>>>
>>> Thanks
>>> Souvik
>>>
>>> This list strives to be beginner friendly.  However, we still ask that
>>> you
>>> PLEASE do read the posting guide http://www.R-project.org/
>>> posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>> This list strives to be beginner friendly.  However, we still ask that you
>> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>

This list strives to be beginner friendly.  However, we still ask that you
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

2019
2018
2017
2016
2015
2014
2013
2012
2011
2010
2009
2008

ATOM RSS1 RSS2



LISTS.UFL.EDU

CataList Email List Search Powered by the LISTSERV Email List Manager