Random variables and expectation — Unit 2 Notes (Probability and Statistics for Computing)

BAS401 · Unit 2

Random variables and expectation notes — Unit 2

Free unit-wise study notes on random variables and expectation for Probability and Statistics for Computing, Semester 4 of B.Tech — Computer Science & Engineering — key concepts, examples, important questions and a revision checklist for semester exams.

Transitioning from sets to functions. Covers Discrete and Continuous Random Variables, Probability Mass Functions (PMF), Probability Density Functions (PDF), Cumulative Distribution Functions (CDF), and calculating Expected Value, Variance, and Moments.

Notebook — 11 pages

Page 1

Wink Notes

B.Tech CSE — 4th Semester

Probability and Statistics

Unit - 2

1. Random Variables

Sample spaces in probability are often sets of abstract objects like {Heads, Tails} or {Red, Blue, Green}. Mathematics, however, requires numbers.

1.1 The Definition

A Random Variable (RV) is not a variable at all. It is a strict mathematical function.

A Random Variable XX assigns a single real number to every possible outcome in the sample space SS.
X:SRX: S \rightarrow \mathbb{R}

Example: Toss two coins. S={HH,HT,TH,TT}S = \{HH, HT, TH, TT\}.
Let
XX be the function that counts the number of Heads.
X(HH)=2X(HH) = 2
X(HT)=1X(HT) = 1
X(TH)=1X(TH) = 1
X(TT)=0X(TT) = 0

Now, instead of talking about abstract sets of coins, we can ask questions mathematically: "What is P(X=1)P(X = 1)?" By mapping outcomes to numbers, we unlock Calculus.

Next — Discrete vs Continuous

1 of 11

Page 2

Wink Notes

B.Tech CSE — 4th Semester

Probability and Statistics

Unit - 2

2. Discrete vs Continuous Random Variables

Random variables are split into two completely separate mathematical universes, requiring different mathematical tools.

2.1 Discrete Random Variables

A random variable is Discrete if it can only take on a countable number of distinct values. These are usually integers.

Examples:
- The number of defective laptops in a shipment (0, 1, 2, 3...).
- The number of network packets dropped per minute.
Discrete math uses
Summations (\sum).

2.2 Continuous Random Variables

A random variable is Continuous if it can take on ANY infinitely precise real number within an interval. It represents physical measurements.

Examples:
- The exact temperature of a CPU (e.g.,
72.158349...72.158349...^\circC).
- The exact time it takes to download a file.
Because there are infinite fractions between 1 and 2, continuous math requires
Integration (\int).

Next — Probability Mass Function (PMF)

2 of 11

Page 3

Wink Notes

B.Tech CSE — 4th Semester

Probability and Statistics

Unit - 2

3. Probability Mass Function (PMF)

For a Discrete Random Variable XX, the Probability Mass Function p(x)p(x) gives the exact probability that XX will take a specific value xx.

p(x)=P(X=x)p(x) = P(X = x)

3.1 Properties of a Valid PMF

To be mathematically valid, a PMF must strictly satisfy two conditions:

  • 1. Non-negativity: p(x)0p(x) \ge 0 for all xx.
  • 2. Sums to 1: The sum of probabilities for all possible values of xx must equal exactly 1.
    p(x)=1\sum p(x) = 1

Example Check: Given the function p(x)=cxp(x) = cx for x=1,2,3x = 1, 2, 3. Find constant cc to make this a valid PMF.
We enforce the sum condition:
p(x)=p(1)+p(2)+p(3)=1\sum p(x) = p(1) + p(2) + p(3) = 1.
c(1)+c(2)+c(3)=1c(1) + c(2) + c(3) = 1
6c=16c = 1
Therefore,
c=1/6c = 1/6.

Next — Probability Density Function (PDF)

3 of 11

Page 4

Wink Notes

B.Tech CSE — 4th Semester

Probability and Statistics

Unit - 2

4. Probability Density Function (PDF)

For a Continuous Random Variable, things change drastically. The probability of hitting an infinitely precise, exact decimal number (e.g., P(X=72.158349)P(X = 72.158349)) is mathematically Zero.

Instead of probabilities at exact points, we use a Probability Density Function f(x)f(x) to calculate probabilities over an Interval (an area under a curve).

4.1 Area under the Curve

The probability that XX falls between aa and bb is the definite integral of the PDF from aa to bb:

P(aXb)=abf(x)dxP(a \le X \le b) = \int_{a}^{b} f(x) dx

4.2 Properties of a Valid PDF

  • 1. Non-negativity: f(x)0f(x) \ge 0 for all real xx. (The curve must never dip below the x-axis).
  • 2. Total Area is 1: The integral across the entire real number line must equal exactly 1.
    f(x)dx=1\int_{-\infty}^{\infty} f(x) dx = 1

*(Note: The value of f(x)f(x) itself is a density, NOT a probability. It is possible for f(x)>1f(x) > 1, as long as the total area under the curve remains 1).*

Next — Cumulative Distribution Function (CDF)

4 of 11

Page 5

Wink Notes

B.Tech CSE — 4th Semester

Probability and Statistics

Unit - 2

5. Cumulative Distribution Function (CDF)

The CDF, denoted as F(x)F(x), is a universal function that applies to BOTH discrete and continuous variables. It acts as a running total.

5.1 The Definition

The CDF specifies the probability that the random variable XX will take a value less than or equal to a specific number xx.

F(x)=P(Xx)F(x) = P(X \le x)

For Discrete: F(x)=txp(t)F(x) = \sum_{t \le x} p(t) (A step function that jumps up at each value).

For Continuous: F(x)=xf(t)dtF(x) = \int_{-\infty}^{x} f(t) dt (A smooth, non-decreasing curve).

5.2 Using the CDF

The CDF makes finding interval probabilities extremely easy via simple subtraction:
P(a<Xb)=F(b)F(a)P(a < X \le b) = F(b) - F(a)

By the Fundamental Theorem of Calculus, the derivative of the continuous CDF gives you back the PDF:
f(x)=ddxF(x)f(x) = \frac{d}{dx} F(x)

Next — Mathematical Expectation (Mean)

5 of 11

Page 6

Wink Notes

B.Tech CSE — 4th Semester

Probability and Statistics

Unit - 2

6. Mathematical Expectation (Mean)

The Expected Value, denoted as E[X]E[X] or μ\mu, is the "center of mass" of a random variable. It represents the long-term, theoretical average value you would get if you repeated the random experiment millions of times.

6.1 The Formulas

You calculate it by multiplying every possible value by its probability (weight) and summing them.

Discrete: μ=E[X]=xxp(x)\mu = E[X] = \sum_{x} x \cdot p(x)

Continuous: μ=E[X]=xf(x)dx\mu = E[X] = \int_{-\infty}^{\infty} x \cdot f(x) dx

6.2 Expectation of a Function

If you apply a function g()g() to a random variable, the expectation changes:

E[g(X)]=xg(x)p(x)E[g(X)] = \sum_{x} g(x) \cdot p(x) (Discrete)

Example: A casino game pays you X2X^2 dollars, where X is the roll of a die.
E[X^2] = (1^2)(1/6) + (2^2)(1/6) + ... + (6^2)(1/6) = 91/6 \approx \15.16$.
This is the fair price to play the game.

Next — Properties of Expectation

6 of 11

Page 7

Wink Notes

B.Tech CSE — 4th Semester

Probability and Statistics

Unit - 2

7. Properties of Expectation

The Expected Value operator E[]E[\cdot] is a mathematically Linear Operator. This makes algebraic manipulation extremely easy.

7.1 Linearity Rules

Let aa and bb be numeric constants, and let XX and YY be random variables.

  • E[c]=cE[c] = c: The expected value of a constant is just the constant.
  • E[aX]=aE[X]E[aX] = a \cdot E[X]: Constants can be pulled outside the expectation.
  • E[aX+b]=aE[X]+bE[aX + b] = a \cdot E[X] + b: Linearity applies to shifts.
  • E[X+Y]=E[X]+E[Y]E[X + Y] = E[X] + E[Y]: This is ALWAYS true, absolutely regardless of whether XX and YY are independent or heavily dependent.

7.2 Multiplication Rule

E[XY]=E[X]E[Y]E[XY] = E[X] \cdot E[Y]

CRITICAL WARNING: This multiplication rule is ONLY true if XX and YY are mathematically Independent. If they are dependent, this equation fails.

Next — Variance and Standard Deviation

7 of 11

Page 8

Wink Notes

B.Tech CSE — 4th Semester

Probability and Statistics

Unit - 2

8. Variance and Standard Deviation

Expectation only tells us the center. It tells us nothing about how widely the data is spread out. A stock that fluctuates between 49and49 and 51 has the same mean (50)asastockthatviolentlyswingsbetween50) as a stock that violently swings between 10 and $90.

Variance (σ2\sigma^2) measures this spread. It is the average squared distance from the mean.

8.1 The Formula

Definition: Var(X)=E[(Xμ)2]Var(X) = E[(X - \mu)^2]

However, this is difficult to compute. The universally preferred computational formula is derived via algebra:

Var(X)=E[X2](E[X])2Var(X) = E[X^2] - (E[X])^2
(The expected value of the squares, minus the square of the expected value).

8.2 Standard Deviation (σ\sigma)

Because variance is squared, its units are physically meaningless (e.g., "squared dollars"). Standard Deviation brings the measurement back to the original units by taking the square root.

σ=Var(X)\sigma = \sqrt{Var(X)}

Next — Properties of Variance

8 of 11

Page 9

Wink Notes

B.Tech CSE — 4th Semester

Probability and Statistics

Unit - 2

9. Properties of Variance

Unlike Expectation, the Variance operator Var()Var(\cdot) is NOT linear. It behaves very differently with constants.

9.1 Variance Rules

  • Var(c)=0Var(c) = 0: A constant never varies. Its spread is zero.
  • Var(X+b)=Var(X)Var(X + b) = Var(X): Shifting the entire graph to the right by bb units changes the mean, but it does NOT change how spread out the data is.
  • Var(aX)=a2Var(X)Var(aX) = a^2 \cdot Var(X): CRITICAL RULE. If you multiply a random variable by a constant aa, its variance scales by aa squared.
  • Var(aX+b)=a2Var(X)Var(aX + b) = a^2 \cdot Var(X): Combining the two rules above.

9.2 Adding Variances

Var(X+Y)=Var(X)+Var(Y)Var(X + Y) = Var(X) + Var(Y)

CRITICAL WARNING: This equation is ONLY true if XX and YY are mathematically Independent. (If they are dependent, you must add the Covariance term).

Next — Moments and MGF

9 of 11

Page 10

Wink Notes

B.Tech CSE — 4th Semester

Probability and Statistics

Unit - 2

10. Moments and Moment Generating Functions

Mean and Variance are just the first two "Moments" of a distribution. There are infinite moments that describe skewness, kurtosis (peakiness), and the entire mathematical shape of the curve.

10.1 Definitions of Moments

  • nn-th Moment about the Origin: μn=E[Xn]\mu_n' = E[X^n]
    (Note:
    E[X1]E[X^1] is the Mean).
  • nn-th Central Moment (about the Mean): μn=E[(Xμ)n]\mu_n = E[(X - \mu)^n]
    (Note:
    E[(Xμ)2]E[(X - \mu)^2] is the Variance).

10.2 The Moment Generating Function (MGF)

The MGF, denoted as MX(t)M_X(t), is a single, massive algebraic function that encodes absolutely every moment of the distribution.

Definition: MX(t)=E[etX]M_X(t) = E[e^{tX}]

To extract the nn-th moment E[Xn]E[X^n] from the MGF, you simply calculate the nn-th derivative of the MGF with respect to tt, and then evaluate that derivative at t=0t=0.

E[Xn]=MX(n)(0)E[X^n] = M_X^{(n)}(0)

This beautiful property completely eliminates the need to calculate complex summations or integrals when finding higher-order moments.

Next — Summary Checklist

10 of 11

Page 11

Wink Notes

B.Tech CSE — 4th Semester

Probability and Statistics

Unit - 2

11. Summary Checklist

Unit 2 bridges probability and calculus. You must be comfortable with both discrete summations and continuous integrals.

11.1 University Exam Checklist

  • Define a Random Variable mathematically.
  • Differentiate between Discrete and Continuous random variables, giving two examples of each.
  • State the two mathematical properties required for a valid PMF (p(x)p(x)) and a valid PDF (f(x)f(x)).
  • Given a PDF f(x)=cx2f(x) = cx^2 over [0,2][0, 2], use integration to solve for the constant cc, and then calculate P(X>1)P(X > 1).
  • Define the Cumulative Distribution Function (CDF). Calculate the CDF by integrating a given PDF.
  • Write the formulas for Expected Value E[X]E[X] for both discrete and continuous cases.
  • State the Linearity of Expectation rules. Calculate E[3X+5]E[3X + 5].
  • Write the computational formula for Variance: Var(X)=E[X2](E[X])2Var(X) = E[X^2] - (E[X])^2.
  • State the variance scaling rule. Calculate Var(2X+7)Var(-2X + 7) given Var(X)=4Var(X) = 4.
  • Define the Moment Generating Function (MGF). Use it to find the Mean and Variance by taking the first and second derivatives.

11 of 11

Continue in this subject