Skip to content

Commit

Permalink
Add Gaussian CDF/PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
aaaakshat committed Oct 22, 2021
1 parent 800e401 commit c296bca
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions ch04.r
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
#############
# Chapter 4.3 (Cumulative Distribution Function)

## 4.10 CDF of a Uniform Random Variable
## CDF of a Gaussian Mixture
# R code to generate the PDF and CDF
library(EnvStats)
x = seq(-5, 10, (5+10)/1000)
x = sort(x)
f = dnormMix(x, 0, 1, 5, 1, p.mix=c(0.7))
plot(x,f, xlim=c(-5,10), ylim=c(0,0.4), type="n")
grid()
lines(x, f, lwd=4, col="blue")
polygon(c(min(x), x[x<=0.8]), c(f[x<=0.8], 0), col="lightblue")

F = pnormMix(x, 0, 1, 5, 1, p.mix=c(0.7))
plot(x, F, xlim=c(-5,10), ylim=c(0,0.4), type="n")

# R code to generate the PDF and CDF

## CDF of a Uniform randow variable

# R code to generate the PDF and CDF
x = seq(-5, 10, (5+10)/1500)
Expand All @@ -11,7 +28,7 @@ lines(x, f, lwd=5)
plot(x, F, type="n")
lines(x, F, lwd=5)

## 4.11 CDF of an exponential random variable
## CDF of an exponential random variable

# R code to generate the PDF and CDF
x = seq(-5, 10, (5+10)/1500)
Expand All @@ -22,6 +39,7 @@ lines(x, f, lwd=5)
plot(x, F, type="n")
lines(x, F, lwd=5)

#############
# Chapter 4.5

# Generate a uniform random variable
Expand Down

0 comments on commit c296bca

Please sign in to comment.