TRANSFORMATION

Sums and Mixtures

  1. X ~ N(1, 5)
  2. Y ~ N(2, 3)
  3. Z = X + Y ~ N(3, 8)$
  1. v ~𝛘²₂
  2. u ~𝛘²₆
  3. z = v + u ~𝛘²₈
  1. w ~ Gamma(2, 4)
  2. z ~ Gamma(7, 4)
  3. s = w + z ~ Gamma(9, 4)
  • If the random variable X has a distribution as a weighted sum 𝐹(𝑥)=Σ𝜃ᵢ𝐹(𝑋ᵢ) for some sequence of Xᵢ’s and 𝜃ᵢ>0 such that Σ𝜃ᵢ=1, then X is a discrete mixture. The constant 𝜃ᵢ’s are called as mixing weights.
  • If the distribution of X is 𝐹(𝑥)=∫𝐹{𝑋|𝑌=𝑦}(𝑥)𝑓(𝑦)𝑑𝑦
  1. X ~ N(1, 5)
  2. Y ~ N(2, 3)
  3. 3. Z = 0.5X + 0.5Y
  1. w ~ Gamma(2, 4)
  2. z ~Gamma(7, 4)
  3. s = 0.7w + 0.3z

Transformation Methods

Example 1)

Generating Random Variables from Gamma Distribution.

set.seed(361)

#parameters
n <- 10^4
t <- 4
lambda <- 9


U <- matrix(runif(n*t),nrow = t, ncol = n) #since we will take sum, we define a matrix
Screen%20Shot%202022-03-30%20at%206.20.32%20PM.png
logU <- -log(U) / lambda # inverse transform method

gamma_y <- apply(logU,2,sum) # col sums of matrix logU

hist(gamma_y, prob=TRUE, main ="Gamma Distribution (4,9)")
y = seq(0,2.5,0.01)
lines(y,dgamma(y,t,lambda),col="red",lwd = 2.5)
png
#theoratical parameters
theoratical_mean <- t/lambda
theoratical_var <- t/lambda^2

#sample statistics
est_mean <- mean(gamma_y)
est_var <- var(gamma_y)

control <- matrix(round(c(theoratical_mean,theoratical_var, est_mean,est_var),5), nrow = 2, byrow = T)


colnames(control) <- c("Mean","Variance")
rownames(control) <- c("Theoritical", "Estimated")
control

Example 2)

library(sads)set.seed(361)

#parameters
n <- 10^5
t <- 18
lambda <- 8

U <- matrix(runif(n*t),nrow = t, ncol = n)

exponential <- -log(U) / lambda # inverse transform method
erlang <- apply(exponential,2,sum) # col sums of matrix logU

pareto = (exponential/erlang) + 1

hist(pareto, prob=TRUE, xlim = c(0, 10),
breaks = 100,
main = "Pareto(1, 18)")
y = seq(0,10,0.01)
lines(y, dpareto(y, scale = 1, shape=t, log = FALSE),col="red",lwd = 1.5)
png

Example 3)

We can use the fact that the chi-square distribution with V degrees of freedom is the sum of V squared independent standard normal;

set.seed(361)
n <- 10^5
v <- 10


Z <- matrix(rnorm(v*n,0,1),nrow = v, ncol = n)
SquaredZ <- Z^2

X <- colSums(SquaredZ)

hist(X, prob=TRUE, main ="Chi-Square Distribution")
y = seq(0,35,0.01)
lines(y,dchisq(y,v),col="red",lwd = 2.5)
png
#theoratical parameters
theoratical_mean <- v
theoratical_var <- 2*v

#sample statistics
est_mean <- mean(X)
est_var <- var(X)

control <- matrix(round(c(theoratical_mean,theoratical_var, est_mean,est_var),5), nrow = 2, byrow = T)


colnames(control) <- c("Mean","Variance")
rownames(control) <- c("Theoritical", "Estimated")
control

Example 4)

set.seed(361)
n <- 10^5
v <- 40


Z1 <- rnorm(n) #standard normal dist

Z2 <- matrix(rnorm(n*v),v,n)
Z2_sqr <- Z2^2
V <- colSums(Z2_sqr) #chi-square dist with 40 dof


t <- Z1 / (sqrt(V / v))

hist(t, prob = TRUE, main = "Student-T Distribution")
y <- seq(-4,4,0.01)
lines(y, dt(y,v),col = "Red", lwd = 2.5)
png

Example 5)

Remember that

Inverse transform of Exponential distribution is

set.seed(361)

n<- 10^5
lambda <- 1
mu = 5
s = 7

u1 <- runif(n)
x <- -log(u1) / lambda # inverse transform method for first exponnetial variable


u2 <- runif(n)
y <- -log(u2) / lambda # inverse transform method for second exponnetial variable




logistic <- mu-(s*log(x/y))




hist(logistic, prob = TRUE, main = "Logistic(5, 7)")
a <- seq(-100,100,0.01)
lines(a, (exp(-(a-mu)/s) / (s*(1 + exp(-(a-mu)/s))^2)),col = "Red", lwd = 2.5)
png

Example 6)

Remember that

N <- 10^5
m <- 2
n <- 8


z1 <- matrix(rnorm(m*N),m,N) #standard normal matrix
z2 <- matrix(rnorm(n*N),n,N) #standard normal matrix

squared_z1 <- z1^2 #chi-square 1 dof matrix
squared_z2 <- z2^2 #chi-square 1 dof matrix

U <- colSums(squared_z1) #chi-square 2 dof
V <- colSums(squared_z2) #chi-square 8 dof

Rv.F <- (U/m)/(V/n) # F(2,8)

hist(Rv.F, prob = T, main = "F-distribution(2,8)")

a <- seq(0,50,0.01)
lines(a,df(a,m,n), col = "red", lwd = 2.5)
png

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store