[1] 0.8132671
\[ f(x; \mu, \sigma) = \frac{1}{\sigma \sqrt{2\pi}} e^{-\frac{(x - \mu)^2}{2\sigma^2}} \]
Where:
\(x\) is the random variable.
\(\mu\) is the mean of the distribution.
\(\sigma\) is the standard deviation of the distribution.
generate a sample from a Gaussian distribution:
rnorm(n, mean = 0, sd = 1)
Example:
y <- rnorm(n = 100000, mean = 5, sd = sqrt(2))
hist(y, freq = F, ylim = c(0, 0.3))
curve(dnorm(x, mean = 5, sd = sqrt(2)), col = 2, add = T)
Calculate pdf of Normal distribution:
dnorm(x, mean = 0, sd = 1)y <- rnorm(n = 100000, mean = 0,sd = 1)
hist(y, freq=F, ylim = c(0, 0.4),breaks = 100)
dnorm(-1)
hist(y, freq = F, ylim = c(0, 0.4), breaks = 100)
abline(v = -1, lty = 2)
abline(h = dnorm(-1), lty=2)[1] 0.2419707

Calculate pdf of Normal distribution:
pnorm(q, mean = 0, sd = 1)[1] 0.1586553

[1] 0.1586553
library(tigerstats)
plot(ecdf(y),main = "Empirical Cumulative Distribution Function")
abline(v= quantile(ecdf(y),0.158655254), lty = 2)
abline(h= pnorm(-1), lty = 2)
text(x = -0.15, y = 0.2,labels = "(-1,0.159)")
qnorm(p, mean = 0, sd = 1)qnorm(0.158655254)
quantile(ecdf(y),0.158655254)
plot(ecdf(y), main = "Empirical Cumulative Distribution Function")
abline(v = quantile(ecdf(y), 0.158655254), lty = 2)
abline(h = pnorm(-1), lty = 2)
text(x = -0.15, y = 0.2,labels = "(-1,0.159)")[1] -1
15.86553%
-0.9955969

Consider \(X \sim N(0,1)\). It is very easy to compute the following probabilities with R:
[1] 0.8132671
[1] 0.1131394
[1] 0.1131394
[1] 0.6424272

[1] 0.6424272
[1] 0.266999
[1] 0.266999
We can use other distributions like the Normal distribution, for example - binomial: rbinom, dbinom, pbinom, qbinom
uniform: runif, dunif, punif, qunif
Student’s t: rt, dt, pt, qt
…
dplyr and data.table