fft: characteristic function to distribution

View: New views
4 Messages — Rating Filter:   Alert me  

fft: characteristic function to distribution

by Thomas Steiner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The characteristic function is the inverse Fourier transform of the
distribution function. The characteristic function of a normaly
distributed random variable is exp(-t^2/2).

x=seq(-2,2,length=100)
fft(pnorm(x),inverse=T)/length(x)
exp(-x^2/2)

Why aren't the inverse fft and the mentioned function the same?
Thanks for help,
Thomas

______________________________________________
R-help@... mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: fft: characteristic function to distribution

by Prof Brian Ripley :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, 30 Apr 2008, Thomas Steiner wrote:

> The characteristic function is the inverse Fourier transform of the
> distribution function. The characteristic function of a normaly
> distributed random variable is exp(-t^2/2).

The fft is a discrete Fourier transforn, not a continuous one.
Further in each case where the normalizing constants are placed and the
units of frequecy differ from source to source.

?fft has references to exactly what it computes: please consult them.

>
> x=seq(-2,2,length=100)
> fft(pnorm(x),inverse=T)/length(x)
> exp(-x^2/2)
>
> Why aren't the inverse fft and the mentioned function the same?
> Thanks for help,
> Thomas
>
> ______________________________________________
> R-help@... mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

--
Brian D. Ripley,                  ripley@...
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@... mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: fft: characteristic function to distribution

by Thomas Steiner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you Prof Ripley for your answer.

> > The characteristic function is the inverse Fourier transform of the
> > distribution function. The characteristic function of a normaly
> > distributed random variable is exp(-t^2/2).
> >
>
> The fft is a discrete Fourier transforn, not a continuous one.

This is correct. I try to approximate the continous normal
distribution with infinite support by a set of discrete and bounded
points. A real discrete baby example would be the bernoulli
distribution:

p=0.4
t=seq(-0.01,1.001,length=100)
char=1-p+p*exp(1i*t)
cdf=stepfun(c(0,1),c(0,1-p,1))
plot(t,cdf(t),type="l",col="red",ylim=range(cdf(t),Re(fft(char)[2:99])))
lines(t,fft(char),col="blue")

This is more or less like the normal example.

> Further in each case where the normalizing constants are placed and the
> units of frequecy differ from source to source.
>
> ?fft has references to exactly what it computes: please consult them.

I read the documentation/help page. More details there would be
helpful. For example an example (it says "example*s*") something where
explicit expressions are known (as I tried it here).
Another possible improvement could be to make for example the
following sentence nicer/clearer: "(the inverse has a + in the
exponent of e, but here, we do not divide by 1/length(x))."
I did not consult the two given references (two old but surely valuable books).

Enough prattled. Can you give a working example where the cummulative
distribution function and the fourier transform are explicitly known?

I cannot add any value neither to wonderful R nor to this helpful
function. But perhaps my question isn't that stupid and you can give a
hint to proceed. Thank you very much in advance,
Thomas

______________________________________________
R-help@... mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Parent Message unknown Re: fft: characteristic function to distribution

by Thomas Steiner :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Matthias Kohl was so kind and provided me the following lines in this issue:

library(distrEx)
chf <- function(t, D){
  E(D, function(x){exp(1i*t*x)}, useApply = FALSE)
}

## Normalverteilung
D <- Norm()
t <- seq(-3, 3, by = 0.05)
chf.norm <- sapply(t, chf, D = D)
chf.exakt <- exp(-t^2/2)
chf.diff <- chf.norm - chf.exakt
plot(chf.diff)
abs(chf.diff)


This is nice BUT:
* Only built-in distributions can be used
* I want to understand the fft() function, instead here you used E()
of the distrEx package.

Apart from this it was exactly what i was looking for: I know the
characteristic function and want to get the distribution. (My porposal
was to use fft(,inverse=T).)
Any help appreciated,
Thomas

______________________________________________
R-help@... mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.