Fatih Pense's Blog

Using Julia instead of the Z table

Monday, December 12th, 2022

Z table (or standard normal table, unit normal table) is helpful while doing statistical calculations.

When I was a student, statistics was sometimes confusing to understand. I could understand the logic behind the Z table, but it felt like there is some magic that left unexplained. It clicks much better when I see the code, and Julia is a promising and clean scientific language.

Z Table is basically a helper tool to use CDF(cumulative distribution function). You can ask the question: “If I take the population from the mean with X times standard deviation, how much of a population I get?” Also, you can ask the reverse question: “I know it is 95% of population, how many standard deviations that is far from the mean?”

There is positive and negative Z tables, but the resulting value is the same as CDF.

Let’s start.

What is the value for Z=1.96 ?

using Distributions
 
dn = Normal(0,1)
println(cdf(dn,1.96))
# 0.9750021048517795

So it left out 0.025 from the right tail. Or 2.5%.

When we remove 2.5% from both tails we get 95%. That is also 95% confidence interval!

What if we only have the confidence interval and want to learn Z score?

using Distributions
 
dn = Normal(0,1)
# Wrong: It is not 95% confidence interval! It is 90%
println(quantile(dn,0.95))
# 1.6448536269514717

But it is different! This is because when we get 95% from the start (left-side) to the right tail. We leave out 5% on one-tail. That calculates 90% confidence interval z value from the center(mean) to both tails.

using Distributions
 
dn = Normal(0,1)
# We expect 1.96
println(quantile(dn,0.975))
# 1.9599639845400576

We get the same value when we leave out 2.5% from the right tail. This is the Z value for 95% confidence interval.