Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot an exponential distribution

I want to plot an exponential distribution, something like this for example: enter image description here

But I only know how to simulate a data frame that follow a exponential distribution and plot it.

data =  data.frame(x=rexp(n = 100000, rate = .65))
m <- ggplot(data, aes(x=data$x))
m + geom_density()

From which I get: enter image description here

How can I plot the true exponential distribution instead of a sampled version of the distribution?

like image 978
Chubing Avatar asked Sep 21 '15 23:09

Chubing


People also ask

How do you do exponential distribution?

The formula for the exponential distribution: P ( X = x ) = m e - m x = 1 μ e - 1 μ x P ( X = x ) = m e - m x = 1 μ e - 1 μ x Where m = the rate parameter, or μ = average time between occurrences.

What is the graph of exponential distribution?

The exponential distribution graph is a graph of the probability density function which shows the distribution of distance or time taken between events. The two terms used in the exponential distribution graph is lambda (λ)and x. Here, lambda represents the events per unit time and x represents the time.

How do you plot an exponential function in R?

To create an exponential curve, we can use exp function inside the plot function for the variable that we want to plot. For example, if we have a vector x then the exponential curve for the vector x can be created by using plot(x,exp(x)).


1 Answers

The exponential distribution can be obtained with the dexp function, so you can plot it by sampling x values and processing them with that function:

x <- seq(0, 20, length.out=1000)
dat <- data.frame(x=x, px=dexp(x, rate=0.65))
library(ggplot2)
ggplot(dat, aes(x=x, y=px)) + geom_line()

enter image description here

like image 93
josliber Avatar answered Oct 18 '22 16:10

josliber