Hello, Can you please help me with this? I am also stack in the same problem. Sam -- View this message in context: http://r.789695.n4.nabble.com/Difference-between-two-time-series-tp819843p4073800.html Sent from the R help mailing list archive at Nabble.com.
Difference between two time series
6 messages · R. Michael Weylandt, Sarwarul Chy
It's not clear what it means for the differences to be "of increasing order" but if you simply mean the differences are increasing, perhaps something like this will work: library(caTools) X = cumsum( 2*(runif(5e4) > 0.5) - 1) # Create a random Walk Y = runmean(X, 30, endrule = "mean", align = "right") D = X - Y # Create the difference series: # Now we need to find the ranges of increasing: to do this, we can just lag D sign(D - c(0, D[1:(length(D)-1)])) If you want to find the length of each run or to find runs of a certain length, try rle(). Michael
On Tue, Nov 15, 2011 at 2:18 PM, Sarwarul Chy <sarwar.shabuj at gmail.com> wrote:
Hello, Can you please help me with this? I am also stack in the same problem. Sam -- View this message in context: http://r.789695.n4.nabble.com/Difference-between-two-time-series-tp819843p4073800.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org 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.
Hello Michael, Thanks for your reply. What I want to do is something like this? For example, I have a continuous time series y=x(t), and another discrete time series z=w(t). Xdiff(i)=Max. difference between x(t) and w(t) in interval i Ndiff(i)=Min. difference between x(t) and w(t) in interval i And predict the min/max error between x(t) and w(t) over the period between time(t) and (t+1) Thanks again. Sam -- View this message in context: http://r.789695.n4.nabble.com/Difference-between-two-time-series-tp819843p4074303.html Sent from the R help mailing list archive at Nabble.com.
Can you post working examples of your data using the dput() function? There are so many types of time series in R and so many different things you could mean that it's just easier to work with real data. Michael
On Tue, Nov 15, 2011 at 4:28 PM, Sarwarul Chy <sarwar.shabuj at gmail.com> wrote:
Hello Michael, Thanks for your reply. What I want to do is something like this? For example, I have a continuous time series y=x(t), and another discrete time series z=w(t). Xdiff(i)=Max. difference between x(t) and w(t) in interval i Ndiff(i)=Min. difference between x(t) and w(t) in interval i And predict the min/max error between x(t) and w(t) over the period ?between time(t) and (t+1) Thanks again. Sam -- View this message in context: http://r.789695.n4.nabble.com/Difference-between-two-time-series-tp819843p4074303.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org 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.
1 day later
Hello Michael,
Thanks again for your reply. Actually, I am working with wind data.
I have some sample data for actual load.
scan("/home/sam/Desktop/tt.dat") ->tt ## This is the input for the actual
output of the generation
t = ts(tt, start=8, end=24, frequency=1,)
I have another random sequence for Generator Dispatch
scan("/home/sam/Desktop/ss.dat") ->ss## Input for the Generator Dispatch
s= ts(ss, start=10,end=22, frequency=1)
What I want to do now to take the Max and Min difference of this two
sequence (t and s) over a fixed time interval.
Something like, X=max(t-s, start=10, end=12) # I have an error here, I want
he difference between two over an interval
Y=min(t-sx, start=10, end=12)
Then predict the max and min error between time t and t+1 on the basis of
information that I have at t-1. Thanks again.
Sam
--
View this message in context: http://r.789695.n4.nabble.com/Difference-between-two-time-series-tp819843p4080672.html
Sent from the R help mailing list archive at Nabble.com.
3 days later
As I said before: please dput() some working data and I'll try to work
something up.
Without it, the only thing I can reasonably suggest is that perhaps
you are looking for the window() function to be applied before
min/max. Something like:
X <- ts(1:48, start = 1, frequency = 4)
Y <- ts(1:12, start = 1, frequency = 1)
for(i in seq_along(time(Y))){
X.temp <- window(X, start = i, end = i +1)
Y.temp <- window(Y, start = i, end = i )
print(max(as.numeric(X.temp)-as.numeric(Y.temp)))
}
It may be possible to do this more elegantly, but since you haven't
even said how your intervals are defined nor what the relationship
between the time stamps of X and Y are, I can't tell you.
Going forward, I'd probably recommend that you don't use the native ts
class of R, in favor of zoo or xts: ts can be a little unwieldy (to
say the least) and zoo and xts are two responses to difficulties
people have had with ts. This would so something similar in xts:
library(xts)
X <- xts(1:192, Sys.Date()+1:192)
Y <- xts(1:24, Sys.Date() + (1:24)*8)
Y.temp <- X; Y.temp[] <- NA; Y.temp[time(Y)] <- Y; Y.temp <-
na.locf(Y.temp); Diff = X - Y.temp
# create a copy of X to hold Y at a higher frequency, then fill NA's
with previous values
And then you can look at the difference on whatever frequency you want.
You're going to have to say more than "predict" the future error:
there are approximately 7.3 umpityjillion different time series models
in the world -- you'll need to decide which ones are appropriate for
your problem domain, taking into account any fundamental relationship
between the two series as well as their own dynamics.
Michael
On Thu, Nov 17, 2011 at 11:56 AM, Sarwarul Chy <sarwar.shabuj at gmail.com> wrote:
Hello Michael,
Thanks again for your reply. Actually, I am working with wind data.
I have some sample data for actual load.
scan("/home/sam/Desktop/tt.dat") ->tt ? ## This is the input for the ?actual
output of the generation
t = ts(tt, start=8, end=24, frequency=1,)
I have another random sequence for Generator Dispatch
scan("/home/sam/Desktop/ss.dat") ->ss## Input for the Generator Dispatch
s= ts(ss, start=10,end=22, frequency=1)
What I want to do now to take the Max and Min difference ?of this two
sequence (t and s) over a fixed ?time interval.
?Something like, X=max(t-s, start=10, end=12) # I have an error here, I want
he difference between two over an interval
? ? ? ? ? ? ? ? ? ? ? ?Y=min(t-sx, start=10, end=12)
Then predict the max and min error between time t and t+1 on the basis of
information that I have at t-1. Thanks again.
Sam
--
View this message in context: http://r.789695.n4.nabble.com/Difference-between-two-time-series-tp819843p4080672.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org 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.