Skip to content

Commit

Permalink
Add chapter 4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
aaaakshat committed Oct 21, 2021
1 parent d85ba28 commit bd54518
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions ch04.r
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,41 @@ lines(x, F1, lwd=4, col="blue")
lines(x, F2, lwd=4, col="red")
legend(0, 1, legend=c(expression(paste(lambda, "=5")), expression(paste(lambda, "=2"))), col=c("red", "blue"), lty=1:1)

# Chapter 4.6

## PDF and CDF of a Gaussian random variable

# R code to generate a Gaussian PDF
x = seq(-10, 10, (10+10)/1000)
mu = 0; sigma = 1;
f = dnorm(x, mu, sigma)
plot(x, f, type="n")
lines(x, f, lwd=4, col="blue")

# R code to generate standard Gaussian PDF and CDF
x = seq(-5, 5, (5+5)/1000)
f = dnorm(x)
F = pnorm(x)
plot(x, f)
plot(x, F)

# R code to verify standardised Gaussian
x = seq(-5, 5, (5+5)/1000)
mu = 3; sigma = 2;
f1 = dnorm((x-mu)/sigma, 0, 1) # Standardised
f2 = dnorm(x, mu, sigma) # Raw

# R code to compute skewness and kurtosis
library(e1071)
X = rgamma(10000, 3, 5)
s = skewness(X)
k = kurtosis(X)

# R code to show the histogram of Z = X1 + X2 + X3
N = 10000
X1 = runif(N, 1, 6)
X2 = runif(N, 1, 6)
X3 = runif(N, 1, 6)
Z = X1 + X2 + X3
hist(Z, breaks=seq(2.5,17.5))

0 comments on commit bd54518

Please sign in to comment.