Learn R Programming

pvar (version 1.0.9)

pvar: p-variation calculation

Description

Calculates p-variation of the sample.

Usage

pvar(x, p, TimeLabel=as.vector(time(x)), info = TRUE, sizeN = 7)

## S3 method for class 'pvar':
summary(object, ...)

## S3 method for class 'pvar':
plot(x, main = "p-variation", ylab = x$dname, 
	sub="p="\%.\%round(x$p,5)%.%", p-variation: "%.% formatC(x$value, 5, format = "f"), 
	col.PP = 3, cex.PP = 0.5, col.SP = 2, cex.SP = 1,	...)

Arguments

x
a (non-empty) numeric vector of data values or an object of the class pvar.
p
a positive number indicating the power p in p-variation.
TimeLabel
numeric, a time index of x. Used only for plotting.
info
logical. If TRUE (the default) the results will be an object of the class pvar with all the information included. Otherwise it will be only the p-variation value.
sizeN
a positive and odd number. This is inner parameter that may significantly influence the speed of calculation. 7 is recommended for randomized processes (for example Wiener process).
object
an object of class pvar.
main
a main parameter in plot function.
ylab
a ylab parameter in plot function.
sub
a sub parameter in plot function.
col.PP
the color of partition points.
cex.PP
the cex of partition points.
col.SP
the color of split points.
cex.SP
the cex of split points.
...
further arguments.

Value

  • If info=TRUE then function returns the object of the class pvar. It contains the list with information, namely:
  • valuea value of p-variation.
  • xa vector of original data x.
  • pthe value of p.
  • dnamea name of data vector.
  • TimeLabela time label of x.
  • Partitiona vector of indexes that indicates the partition that achieves the maximum.
  • SplitPointsthe indexes of x that indicates the points where x might be spited and analysed separately.
  • infothe list of extra information about the calculation.
  • The info is a vector that contains:
  • PartitionNthe length of the partition.
  • AnalysedPointsNthe length of the prepared x, i.e. after removing monotonic points and meaningless points in small intervals.
  • SegmentsNthe number of segments the x was splinted.
  • sizeNthe inner sizeN parameter.
  • TakesTimethe total time taken for p-variation calculation. If it has negative value -1, this means, that this information is not available.

Warning

Unfortunately pvar is recursive function. Therefore, for large data sets this might by real limitation. For a randomised samples this function works just fine. The problem arise then x has very special kind of form.

Details

To make it clear lets star with the definitions. Originally p-variation is defined for a functions. For a function $f:[0,1] \rightarrow R$ and $0 < p < \infty$ p-variation is defined as $$v_p(f) = \sup \left{ \sum_{i=1}^m |f(t_i) - f(t_{i-1})|^p : 0=t_0pvar calculates p-variation for a sequence of values $X_0, X_1,\dots, X_n$ that are written in the numeric vector x. This function also finds extra information that concerns the calculation of the p-variation. For example it also indicates the partition ($j_0, j_1,\dots, j_k$) that achieves the maximum. The main principle of the algorithm: pvar maximises function Sum_p. Firstly, it removes all monotonic points with function ChangePointsId. After that, some points are drop out by function DropMidAll. Moreover, vector is spited by SplitByExtremum and each part is calculated independently by pvarPseudoMonotonic. The variable sizeN is inner parameter that may influence the speed of calculation. Before the real maximisation of the function $|X_{j_i}-X_{j_{i-1}}|^p$ starts, some of the points may be drooped out by analysing small intervals (see DropMidAll). The sizeN defines the length of 'small' interval. For randomised samples it is recommended to set sizeN=7. But if x has special form the optimal sizeN value might be different.

References

[1] R. M. Dudley, R. Norvaisa. An Introduction to p-variation and Young Integrals, Cambridge, Mass., 1998. [2] R. M. Dudley, R. Norvaisa. Differentiability of Six Operators on Nonsmooth Functions and p-Variation, Springer Berlin Heidelberg, Print ISBN 978-3-540-65975-4, Lecture Notes in Mathematics Vol. 1703, 1999. [3] R. Norvaisa, A. Rackauskas. Convergence in law of partial sum processes in p-variation norm. Lth. Math. J., 2008., Vol. 48, No. 2, 212-227. [4] J. Qian. The p-variation of Partial Sum Processes and the Empirical Process. The Annals of Probability, 1998, Vol. 26, No. 3, 1370-1383.

See Also

In some points pvar objects migth be merged with function MergePvar. One of the p-variations application is realized in PvarBreakTest function.

Examples

Run this code
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