1

I'm using the distr package in R for a research project that involves the convolution of multiple i.i.d. uniform random variables.

The details of the project are not important, but sometimes the min and max of the distributions are very close to each other, like .999 and 1. This is a valid continuous random variable, and I can create the abstract distribution using Unif(.999,1) without trouble.

But when I try to use the convpow function to get the convolution of two or more of these random variables, I get the error "Error in xy.coords(x, y, setLab = FALSE) : 'x' and 'y' lengths differ."

I can't figure out anything that would cause this. My question is two-fold: 1. Am I making a mistake and if so, how can I fix it? 2. If there is something in the package that's causing this, is there a related package that I could use that won't have this issue?

The convpow function works just fine when I use it with bounds that aren't so close together, but for some reason it doesn't work when the boundaries are very close.

library(distr)

z <- Unif(.999,1)
conv_z <- convpow(z, 2)
fraz1
  • 11
  • 2
  • I would guess it could be rounding in the Discrete Fourier Transform. For example trying something like the apparently similar `z <- Unif(0.9990234375,1); conv_z <- convpow(z, 2)` does not seem to give a similar error but this has a range of exactly `2^(-10)` – Henry Jan 17 '19 at 23:45
  • @Henry thanks! You seem to be right. If I change the parameter DefaultNrFFTGridPointsExponent from 12 to 8 with `distroptions("DefaultNrFFTGridPointsExponent" = 8)`, then I no longer get an error, although the output is less accurate. I wonder if there is a way to avoid this issue without losing accuracy? – fraz1 Jan 18 '19 at 02:01

0 Answers0