1

So I was asked to write a code that generates 100 randomly uniform distributed numbers x between 0 and 1, and use those values in our distribution function F(x)=1-e^(-x) for x=>0. And then plot a histogram.

Now I want to conclude if it appears to be distributed according to a exponential distribtuion.

1.So I though that I could overlay my histogram with the graph of the exponential distribtuion, but I have no clue in how I do that. Could anyone help me?

Im new to R and this is my first course in statistics, thanks in advance.

Biggiez
  • 33
  • 4
  • Possible dupes: http://stackoverflow.com/q/22704047/903061, http://stackoverflow.com/q/20078107/903061, http://stackoverflow.com/q/19103582/903061, plenty more in the "Related" questions in the sidebar. – Gregor Thomas Sep 22 '16 at 19:38

1 Answers1

0

For (2), you can show that y is exponentially distributed with mean (rate) 1 as follows (using the pdf of random variable Y of the transformed random variable X):

enter image description here

For (1) You can try this (draw 100 random samples from an exponential distribution of rate 1 and create a vector z, then compare histograms of y and z by overlaying, as you can see the shape of the histograms are quite similar):

hist(y, col='red', alpha=0.2, main='comparing the histograms of y and z')
z <- rexp(100) # draw 100 random samples from an exponential distribution with rate 1
hist(z, add=T, col=rgb(0, 1, 0, 0.5))
legend("topright", c('hist y', 'hist z'), lwd=c(2,2), col=c('red',rgb(0, 1, 0, 0.5)))

enter image description here

You can also compare the distribution of the random variable Y with the exponential random variable Z with qqplot as shown below:

qqplot(y,z, ylab='z')
qqline(y)

enter image description here

Sandipan Dey
  • 21,482
  • 2
  • 51
  • 63
  • Oh thanks very much for your answer. I think I formulated myself wrong regarding (1). I want to overlay my histogram with the curve of the exponential-function. Is there a way to overlay my histogram with the curve? – Biggiez Sep 22 '16 at 19:19