# The code for the function moments must include a section
# that computes the r th moment to an arbitrary number of bits
# of precision nbits using the R package Rmpfr for the particular
# weight function f of interest.
# Suppose that the weight function f is the probability density
# function of a random variable with the same probability
# distribution as R divided by the square root of m, where R has a
# chi distribution with m degrees of freedom.
# The code for the function moments includes the following:
#
# if (which.f$name == "scaled.chi.pdf"){
# m <- which.f$parameters
# if (r == 0){
# return(mpfr(1, nbits))
# }
# mp.2 <- mpfr(2, nbits)
# mp.r <- mpfr(r, nbits)
# mp.m <- mpfr(m, nbits)
# term1 <- (mp.r/ mp.2) * log(mp.2 / mp.m)
# term2 <- lgamma((mp.r + mp.m) / mp.2)
# term3 <- lgamma(mp.m / mp.2)
# return(exp(term1 + term2 - term3))
# }
Run the code above in your browser using DataLab