Random Variables

A random variable has numerical values with random outcomes. Individual outcomes are unpredictable, but the distribution of outcomes can often be determined or estimated.

A discrete random variable has a finite set of possible outcomes.

A continuous random variable has an infinite set of outcomes, often distributed across a range of possible values.

Expected values and variances

The expected value of a discrete random variable is the average of the possible values weighted by their probabilities.

For large samples, the expected value predicts the mean value of the random variable. This is the law of large numbers.

The expected variance of a discrete random variable is the average of the squared difference from the mean, weighted by the probabilities.

Rules for calculating mean and variance from a random variable

Assume that X and Y are random variables and c is a constant.

  • The mean of X + c = meanx + c
  • The variance of X + c = varx (adding a constant to a random variable does not change its variance)
  • The mean of c * X = c * meanx
  • The variance of c * X = c2 * varx
  • The mean of X + Y = meanx + meany
  • The variance of X + Y = varx + vary

We will use the last rule the most. You can use the variance rules to find standard deviation by taking the square-root of the variance.

R Code

Starting R code for simulating random variables

With the R code, we will demonstrate the central limit theorem, which states that a random variable constructed from the sum (or mean) of N random variables (N should be sufficiently large) has a normal distribution.