I am working with high frequent data, which is a vector X of decimal numbers.
I would like to code the following in R, but am at complete loss where to start:
n decides how big intervals we are looking at. This can be any value, this is not so important, since I need to experiment with different values.
I have tried a lot of things, amongst the following:
X <- runif(10000) # 5000 obs. pr. second, with 20 mill obs in total
for(i in 1:length(X){
sum? * (-1)^??
*(for (n in 0:i) print(choose(n, k = 0:n)))
x <- ??
mat[1:length(X)] <- x
}
But I am miles from anything working. Any help is greatly appreciated. I've edited the equation, missed an equal sign.
I've written something that hopefully should make it more clear:
Maybe this can get you started. I think it is what you expressed. However I think it would make more sense with an initialization like rnorm(nx,1,0.01) - i.e. something smoother. It might also make sense to have xsub interpolate between the generated points (i.e. make it a continuous function).
It could obviously be made more efficient but it should be verified to be correct first.
Also I really don't know how to interpret the results or I would have done a plot.
nx <- 100
secs <- 2
x <- runif(nx)
obspersec <- nx/secs
xsub <- function(t){
i <- trunc(t*obspersec)+1
if (i<=0) return(0)
if (i>nx) return(0)
return(x[i])
}
x_njk <- function (n,i,k){
if (i<k){
return (0)
}
sum <- 0
for (j in 0:k){
term <- ((-1)^j)*choose(k,j)*xsub((i-j)/n)
sum <- sum + term
}
return(sum)
}
n <- 100
for (k in 1:2){
for (i in k:10){
print(sprintf("n:%d i:%d k:%d x_njk:%.5f",n,i,k,x_njk(n,i,k)))
}
}