0
$\begingroup$

Please advise if the approach i am taking below is correct, I don't see how else to go about solving this problem.

import numpy as np

# generate data
np.random.seed(0)
dataset = np.random.exponential(scale =1/5, size = (30,1))
n = len(dataset)

# for an exponential distribution E[x] = 1/lambda = mean and var = 1/lambda**2
expected_value = 1/(1/5) # reciprocal of lambda we are given as 5 in this instance
standard_deviation = np.sqrt(1/(1/5)**2)

# Z = (X_bar - E[X_bar])/sd(X_bar) using CLT.
Z = ((dataset.mean() - expected_value)/standard_deviation)*np.sqrt(n)

# Calculate z_score for the dataset z_score = (sample - sample_mean)/sample_deviation
z_scores  = (dataset - dataset.mean())/(dataset.std())

# Check dataset where z_score > Z random variable
condition = z_scores > Z

# Probability is number of desired outcome condition/ total outcomes
prob = len(dataset[condition])/len(dataset)
print(prob)
$\endgroup$
9
  • $\begingroup$ Your $Z$ does not appear to consider the sample size, $n$. $\endgroup$
    – Dave
    Jun 26 at 20:24
  • $\begingroup$ @Dave thanks i will add it, i was just not sure if i needed to divide by $\sqrt(n)$ for $Z$ if i am using the population parameter to obtain the standard deviation. I however see that i need to add it when calculating the z_scores. $\endgroup$
    – HappyFeet
    Jun 26 at 21:02
  • 1
    $\begingroup$ I do not follow what you say about the population parameter (do you mean $n$ vs $n-1$?), but the central limit theorem concerns $Z=\sqrt{n}\dfrac{\bar{X}_n-\mu} {\sigma}$. $\endgroup$
    – Dave
    Jun 26 at 22:09
  • $\begingroup$ I understand what you mean now, i have edited the calculation for $Z$ above, any other comments with regards to the approach? $\endgroup$
    – HappyFeet
    Jun 27 at 7:01
  • $\begingroup$ It is impossible to tell what the question really is, because it appears to be a combination of coding problems and conceptual ones--but everything is expressed in code only. Could you back up a little and explain, in words, what your problem is? $\endgroup$
    – whuber
    Jun 28 at 19:57
1
$\begingroup$

Comment:

Suppose $X_i$ are IID $\mathsf{Exp}(\mathrm{rate}=\lambda=1/3)\equiv \mathsf{Exp}(\mu = 3)$ and $Z = \frac{\bar X - \mu}{\sigma/\sqrt{n}}.$ Then $Z$ is not well modeled by a normal distribution unless $n$ is in the hundreds. This is because of the skewness of the exponential distribution and the consequent slowness of the convergence of the CLT.

Illustrations by simulation in R for $\mu = 3$ and for $n=36, n=400.$

set.seed(2021)
a.36 = replicate(10^5, mean(rexp(36, 1/3)))
z.36 = (a.36-3)/(3/sqrt(36))
summary(z.36);  sd(z.36)

     Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
-3.234041 -0.701673 -0.057333 -0.000163  0.643720  5.548458 
[1] 1.00098  # SD 

set.seed(620)
a.400 = replicate(10^5, mean(rexp(400, 1/3)))
z.400 = (a.400-3)/(3/sqrt(400))
summary(z.400);  sd(z.400)
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
-4.092648 -0.686992 -0.019076 -0.001976  0.663559  4.777723 
[1] 0.9988278

enter image description here

R code for figure:

par(mfrow=c(1,2))
hdr = "n=36: z-Scores of Exponential Means"
hist(z.36, prob=T, col="skyblue2", main=hdr)
 curve(dnorm(x), add=T, col="brown", lwd=2)
hdr = "n=400: z-Scores of Exponential Means"
hist(z.400, prob=T, col="skyblue2", main=hdr)
 curve(dnorm(x), add=T, col="brown", lwd=2)
par(mfrow=c(1,1))

By contrast, for any $n,$ exponential means are exactly distributed according to the ratios $\frac{\bar X}{\mu} \sim \mathsf{Gamma}(\mathrm{shape}=n, \mathrm{rate}=n).$ This is easy to show, using moment generating functions. (Appropriate gamma density functions are superimposed on histograms below.)

enter image description here

par(mfrow=c(1,2))
hdr = "n=36: Distn's of Exponential Mean Ratios"
hist(a.36/3, prob=T, br=30, col="skyblue2", main=hdr)
 curve(dgamma(x,36,36), add=T, col="brown", lwd=2)
hdr = "n=400: Distn's of Exponential Mean Ratios"
hist(a.400/3, prob=T, col="skyblue2", main=hdr)
 curve(dgamma(x, 400,400), add=T, col="brown", lwd=2)
par(mfrow=c(1,1))

Answers for $X_i \stackrel{iid}{\sim} \mathsf{Exp}(\lambda=.2)$ with $E(X_i) = SD(X_i) = 5.$

We have the normal approximation $P(\bar X_n \le 5) = P\left(Z_n = \frac{\bar X_n-5}{5/\sqrt{n}} \le 0\right) \approx 0.5,$ for all $n>1.$

By contrast, we have the values $P(Z_n \le 0) = P(\bar X_n \le 5) = P\left(\frac{\bar X_n}{5} \le \frac 5 5 = 1\right),$ which can be evaluated exactly using the distribution $\mathsf{Gamma}(n,n)$ for all $n>0.$ Values for $n = 10, 36, 100, 400$ are shown below.

pgamma(1, 10, 10)
[1] 0.5420703
pgamma(1, 36, 36)
[1] 0.5221667
pgamma(1, 100, 100)
[1] 0.5132988
pgamma(1, 400, 400)
[1] 0.5066491
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.