diff --git a/ch04.r b/ch04.r index 22a4fc6..0c922d8 100644 --- a/ch04.r +++ b/ch04.r @@ -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) @@ -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) @@ -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