Alberto,
I think the functions below do what you want:
> vanDerCorput(12,6)
[1] 0.16666667 0.33333333 0.50000000 0.66666667 0.83333333 0.02777778
[7] 0.19444444 0.36111111 0.52777778 0.69444444 0.86111111 0.05555556
Regards,
Carlos
number2digits=function(n,base){
#first digit in output is the least significant
digit=n%%base
if (n<base)
digit
else
c(digit,number2digits((n-digit)/base,base))
}
digits2number=function(digits,base){
#first digit in input should be the most significant
result=0
for (digit in digits)
result=(base*result)+digit
result
}
vanDerCorput=function(n,base=2){
#generate n first digits of the van der Corput sequence
output=NA*1:n
for(i in 1:n){
digits=number2digits(i,base)
output[i]=digits2number(digits,base)/base^length(digits)
}
output
}
-----------------
In package fOptions, there are functions that generate
Halton sequences.
The van der Corput sequence for base 2 is a particular case
of the Halton sequence generated by:
n <- 8 # anything here...
x <- runif.halton(n, 1)
In fact, x <- runif.halton(n, dim) will generate the van der Corput
sequences for the base b as the i-th prime number in x[,i].
(in other words, if I want the van der Corput sequence for
base b = 5, I do x <- runif.halton(n, 3) and take x[,3]).
However, it's possible to have van der Corput sequences for
non-prime basis, like (for b = 10):
0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 0.01, 0.11, 0.21, 0.31, 0.41,
0.51, 0.61, 0.71, 0.81, 0.91, 0.02, 0.12, 0.22, 0.32,
Is there any R function that generates those sequences?
Alberto Monteiro