Random Variables

  • Example1 Assume a sample space which consists of six names. Assume that probability function, , assigns uniform probability to each of the names. Let now, , be the function that counts the number of letters in each name. Then question is then finding:
  • The function represents the probability distribution of the random variable . Since measures the length of names, is a discrete random variable, and its probability distribution may be represented by Probability Mass Function (PMF), such as
  • Simulation by Julia
using StatsBase, Plots

names = ["Mary", "Mel", "David", "John", "Kaylay", "Anderson"]
randomName() = rand(names)
X = 3:8
N = 10^6
sampleLengths = [length(randomName()) for _ in 1:N]

bar(X, counts(sampleLengths)/N, ylims=(0,0.35),
    xlabel="Name Length", ylabel="Estimated p(x)", legend=:none)

Types of Random Variables

  • Discrete Random Variable i.e. The number of letters of one's name.
  • Continuous Random Variable i.e. The weights of people randomly selected from a big population.
  • In describing the probability distribution of a continuous random variable, the probability mass function, , is no longer applicable. This is because for a continuous random variable , for any particular value of is . Hence, in this case, the Probability Density Function (PDF), is used, where
  • Here the approximate becomes exact as
  • Three examples of distributions
    • Discrete Distribution:
    • Continuous Distribution:
  • Simulation by Julia
using Plots, Measures;pyplot()

pDiscrete = [0.25, 0.25, 0.5]
xGridD = 0:2

pContinous(x) = 3/4*(1-x^2)
xGridC = -1:0.01:1

pContinous2(x) = x < 0 ? x+1 : 1-x

p1 = plot(xGridD, line=:stem, pDiscrete, marker=:circle, c=:blue, ms=6, msw=0)
p2 = plot(xGridC, pContinous.(xGridC), c=:blue)
p3 = plot(xGridC, pContinous2.(xGridC),c=:blue)

plot(p1,p2,p3, layout=(1,3), legend=false, ylims=(0,1.1), xlabel="x", 
    ylabel=["Probability" "Density" "Density"], size=(1200,400), margin=5mm)

results matching ""

    No results matching ""