set.seed(26)
### randomised data:
x = rbridge(1, 1000)
### the main functions:
pv = pvar(x, 2)
print(pv)
summary(pv)
plot(pv)
### By taking only change point, we get the same results:
CP = ChangePointsId(x)
x.CP = x[CP]
pv.CP = pvar(x.CP, TimeLabel=time(x)[CP], 2)
pv.CP == pv
### We can drop out some points withs any lost as well:
DM = DropMidAllB(x.CP, 2, dn=7)
x.DM = x.CP[DM]
pv.DM = pvar(x.DM, TimeLabel=time(x)[CP][DM], 2)
pv.DM == pv
### We can witness the efectivness of each trick by the length of x
c(length(x), length(x.CP), length(x.DM))
### we olso can splti vector in independent samples by finding the extremums
SP = which.max(x)
pv.SP = MergePvar(pvar(x[1:SP],2), pvar(x[SP:length(x)],2))
pv.SP == pv
### Finly, all we must be concern is partition ponts.
pv; Sum_p(x[pv$Partition], 2) #direct calculus
pv.PP = pvar(x[pv$Partition], TimeLabel=time(x)[pv$Partition], 2)
pv == pv.PP
op <- par(mfrow = c(2, 1))
plot(pv, main="pvar with original data")
plot(pv.PP, main="the same pvar without meaningless points")
par(op)
### the illustration of bad form for p-variation calculation
N = 2000
x = c(-N-1000, (1001:(1000+N-2))*((-1)^(0:(N-3))), N+1000)
plot(x, type = "p", pch=19)
# the recursion is too deep:
var(x, p = 2)
### the problem might be solved by reversing x
rx = rev(x)
plot(rx, type = "p", pch=19)
pvar(rx, p = 2) #now it is OK
Run the code above in your browser using DataLab