Class 13

Between Class Sessions - Prep for Day 13

Please spend around 2 hours working between class sessions, focusing on the tasks below. Use any extra time to complete KnewtonAlta assignments and/or work on Project tasks.

Pick something from your prep today that you can share with your group in class. It might be something new that you learned. It might be questions you have that are still unanswered, or a question along with what helped you eventually answer it. It might be something tricky that you solved. It might be a review topic that helped you remember something. It might be a conversation you had with AI that was helpful. You will have a chance to share this with your peers during class. Come ready to articulate your thinking and questions.

Preparation

(1) Introduction to Probability and Random Variables

Watch the following videos are from mathispower4u.

(2) Explore Common Probability Functions

For each of the five functions below, complete the following:

  • Identify the domain.
  • Identify the parameters.
  • Plot the function in R.
  • Identify the range.
  • Consider what happens when you change the parameters in the model. Describe what changing each of the parameters does to the graph of \(f\). Come to class ready to teach your group what you did with at least one of these function.
  1. \(f_1(x; n,p) = \frac{n!}{x!(n-x)!}p^x(1-p)^{ (n-x)}\) with \(x = 0, 1, 2, 3, ... , n\) where \(n\) is a positive integer and \(0 \leq p \leq 1\).

  2. \(f_2(x; \lambda) = \lambda e^{-\lambda x}\) with \(x > 0\) where \(\lambda >0\).

  3. \(f_3(x; \mu, \sigma) = \frac{1}{\sqrt{2\pi\sigma^2}}e^{-\frac{(x-\mu)^2}{2\sigma^2}},\) where \(\mu\) is a real number and \(\sigma > 0\).

  4. \(f_4(x; \lambda) = \begin{cases}0 & x \leq 0 \\ \\1 - e^{-\lambda x} & x > 0\end{cases},\) where where \(\lambda >0\).

  5. \(f_5(x; a,b) =\begin{cases}0 & x < a \\ \\\frac{x-a}{b-a} & a \leq x \leq b \\ \\1 & x >b\end{cases},\) where \(a\) and \(b\) are real numbers with \(a < b\).

You can use the following code to define these functions in R.

f1 <- function(x,n=20,p=0.5){
# x must be an whole number between 0 and n, endpoints included
  factorial(n)/(factorial(x)*factorial(n-x))*p^x*(1-p)^(n-x)
}

f2 <- function(x,lambda=1){
# x must be positive
  lambda*exp(-lambda*x)
}

f3 <- function(x,mu=0,s=1){
  (1/sqrt(2*pi*s^2))*exp(-(x-mu)^2/(2*s^2))
}

f4 <- function(x,lambda=1){
  
  out <- rep(0,length(x))
  out[(x > 0)] <- 1 - exp(-lambda*x[(x > 0)])
  
  return(out)
}

f5 <- function(x,a=0,b=1){
  
  out <- rep(0,length(x))
  out[(a <= x) & (x <= b)] <- (x[(a <= x) & (x <= b)]-a)/(b-a)
  out[(x > b)] <- 1

  return(out)
}

Regular Reminders

Skill Practice (KA Homework)

  • Begin 3 – Probability Basics assignment

Applied Practice (Project Work)

  • Work on Project 1 Task 3

During Class

Brain Gains

  • For each function given below, identify power functions and operations used to build (or construct) the function. Remember there are many correct ways to do this.
    1. \(f(x) = 2\sqrt{3-x} + 7\)
    2. \(h(x) = -5x^2 - 10x - 5\)
  • Given \(h(x)\), find two functions \(f(x)\) and \(g(x)\) so that \((f \circ g)(x) = h(x)\). There are many correct ways to do this.
    1. \(h(x) = -5(x+1)^2\)
    2. \(h(x) = \sqrt{2x+6}\)
    3. \(h(x) =\frac{3}{x-2}\)
  • Using seed 123, the model \(f_4(x) = 100 - 0.000181x + 0.83\ln(0.005x+1)\) where \(x \geq 0\) provides a reasonable visual fit to the light bulb data. Use this model to predict the time at which the light bulb burns out (hits 80% of the original intensity). The code below will plot the model with the data. Update the code to solve \(f_4(t) = 80\).
library(data4led)
bulb <- led_bulb(1,seed = 123)
t <- bulb$hours
y <- bulb$percent_intensity

f4 <- function(x,a0=100,a1=-1.81e-4,a2=0.83){a0+a1*x+a2*log(0.005*x+1)}

x <- seq(-10,80001,2)
y4 <- f4(x)

par(mfrow=c(1,2),mar=c(2,2,3,0.25),oma=rep(0.5,4))
plot(t,y,xlab="Hour ", ylab="Intensity(%) ", pch=16,main='f4')
lines(x,y4,col=2)
plot(t,y,xlab="Hour ", ylab="Intensity(%) ", pch=16, xlim = c(-10,80000),ylim = c(-10,120))
lines(x,y4,col=2)

Group Meeting

Start by giving each person a moment to share what they chose to prepare for class. Help each other address any questions. When each person has had a chance to share, move on the other activities.

Exploring new functions

The prep for today involved exploring the 5 new functions below.

  1. \(f_1(x; n,p) = \frac{n!}{x!(n-x)!}p^x(1-p)^{ (n-x)}\) with \(x = 0, 1, 2, 3, ... , n\) where \(n\) is a positive integer and \(0 \leq p \leq 1\).

  2. \(f_2(x; \lambda) = \lambda e^{-\lambda x}\) with \(x > 0\) where \(\lambda >0\).

  3. \(f_3(x; \mu, \sigma) = \frac{1}{\sqrt{2\pi\sigma^2}}e^{-\frac{(x-\mu)^2}{2\sigma^2}},\) where \(\mu\) is a real number and \(\sigma > 0\).

  4. \(f_4(x; \lambda) = \begin{cases}0 & x \leq 0 \\ \\1 - e^{-\lambda x} & x > 0\end{cases},\) where where \(\lambda >0\).

  5. \(f_5(x; a,b) =\begin{cases}0 & x < a \\ \\\frac{x-a}{b-a} & a \leq x \leq b \\ \\1 & x >b\end{cases},\) where \(a\) and \(b\) are real numbers with \(a < b\).

What do you do when you encounter a new function? One option is to start plotting it and changing parameters to get a feel for how the parameters affect a graph of the function. It’s OK if you don’t initially know what a function is useful for. You can gain intuition and sometimes discover the use as you explore changing parameters of the function.

As a group, spend 5-10 minutes exploring what the parameters control in a graph of the functions above. The code below defines each function and generates a few plots to help you get started. Explore the functions.

Code for functions and some plots.
f1 <- function(x,n=20,p=0.5){
  # x must be an whole number between 0 and n, endpoints included
  factorial(n)/(factorial(x)*factorial(n-x))*p^x*(1-p)^(n-x)
}

f2 <- function(x,lambda=1){
  # x must be positive
  lambda*exp(-lambda*x)
}

f3 <- function(x,mu=0,s=1){
  (1/sqrt(2*pi*s^2))*exp(-(x-mu)^2/(2*s^2))
}

f4 <- function(x,lambda=1){
  out <- rep(0,length(x))
  out[(x > 0)] <- 1 - exp(-lambda*x[(x > 0)])
  return(out)
}

f5 <- function(x,a=0,b=1){
  out <- rep(0,length(x))
  out[(a <= x) & (x <= b)] <- (x[(a <= x) & (x <= b)]-a)/(b-a)
  out[(x > b)] <- 1
  return(out)
}

# Plots for f1
# Note that the input must be an integer. 
x <- seq(0,20,1)
plot(x,f1(x))
plot(x,f1(x,n=10))
plot(x,f1(x,n=30,p=0.2))

# Plots for f2
# Note that the input cannot be negative.
x <- seq(0,10,0.1)
plot(x,f2(x), type = "l")
plot(x,f2(x, lambda=3), type = "l")
plot(x,f2(x, lambda=0.5), type = "l")

# Plots for f3
# The input can be negative, so let's allow that.
x <- seq(-10,10,0.1)
plot(x,f3(x), type = "l")
plot(x,f3(x, mu=3), type = "l")
plot(x,f3(x, s=0.5), type = "l")
plot(x,f3(x, s=3), type = "l")
plot(x,f3(x, s=1), type = "l", ylim = c(0,1))
plot(x,f3(x, s=3), type = "l", ylim = c(0,1))
plot(x,f3(x, s=0.5), type = "l", ylim = c(0,1))

# Plots for f4
# The input cannot be negative.
x <- seq(0,10,0.1)
plot(x,f4(x), type = "l")
plot(x,f4(x, lambda=3), type = "l")
plot(x,f4(x, lambda=0.5), type = "l")

# Plots for f5
x <- seq(0,10,0.1)
plot(x,f5(x), type = "l")
plot(x,f5(x, a=3, b=7), type = "l")
plot(x,f5(x, a=1, b=3), type = "l")
x <- seq(-20,20,0.1)
plot(x,f5(x, a=-3, b=15), type = "l")

Activity - Practice with Probability

Here are some of the key definitions related to probability. Read these definitions, and then use them to tackle the problems that follow.

Definition: Probability
  • An experiment is a process that produces an observation.
  • An outcome is a possible observation.
  • The set of all possible outcomes is called the sample space.
  • An event is a subset of the sample space.

The probability of any outcome is the long-term relative frequency of that outcome.

Source: These definitions are taken from OpenStax Introductory Statistics and Foundations of Statistics with R by Speegle & Clair.

Definition: Random (or Stochastic) Variable
  1. A random variable is a function that associates a number with each outcome of the sample space of a chance experiment.

  2. Let \(S\) be the sample space of an experiment. A random variable is a function from \(S\) to the real line. Random variables are usually denoted by a capital letter. Individual observed values of a random variable are usually denoted by the corresponding lower case letter. Example: We toss a fair coin three times. Let \(X\) be the random variable that counts the number of heads. If we conduct this experiment once and see we had 2 heads in that individual observation of the experiment, we write \(x = 2\). We could ask the questions, “What is the probability that \(X = 2\)?” or “What is the probability that \(X = x\)?”

Source: These definitions are from Probability & Statistics with R by Akritas and Foundations of Statistics with R by Speegle & Clair.

Definition: Rules (or Axioms) of Probability
  • If \(S\) is the samples space, \(P(S) = 1\).
  • For any event \(A\), \(0 \leq P(A) \leq 1\).
  • If \(A\) and \(B\) are mutually exclusive events, \(P(A \text{ or } B) = P(A) + P(B)\).
    • If \(A^c\) is the complement of \(A\), then \(P(A^c) = 1 - P(A)\).

If two events \(A\) and \(B\) do not share any outcomes, \(P(A \text{ and } B) = 0\), then they are mutually exclusive events (the events cannot occur at the same time).

Source: These definitions are taken from OpenStax Introductory Statistics and Statistics for Engineers and Scientists by Navidi.

Definition: Conditional Probability

The conditional probability of \(A\) given \(B\) is written \(P(A | B)\). Conditional probability is used to compute the probability of one event conditional on knowing that another even occurred.

The probability of \(A\) given \(B\) is \(P(A | B) = \frac{P(A \text{ and } B)}{P(B)}\) where \(P(B) \neq 0\).

Source: These definitions are taken from OpenStax Introductory Statistics and Modeling the Dynamics of Life by Adler.

Definition: Independent Events

Two events \(A\) and \(B\) are independent if the knowledge that one occurred does not affect the chance the other occurs. This means:

  • \(P(A | B) = P(A)\)
  • \(P(B | A) = P(B)\)
  • \(P(A \text{ and } B) = P(A)P(B)\)

Source: This definition is taken from OpenStax Introductory Statistics.

Example 1

Let \(R\) be the random variable that represents that value of the roll of a fair 6-sided die. So \(R\) is a function whose domain is the possible outcomes that can result from rolling a fair 6-sided die, and the range is the values of any possible roll, or \(\{1,2,3,4,5,6\}\). Note that we use \(R\) to represent the random variable, but we use \(r=3\) to represent an observation where the outcome resulted in a value of 3. The probability mass function (pmf) describing the random variable \(R\) is given by \(f(r) = \frac{1}{6}\) for \(r\) in \(\{1,2,3,4,5,6 \}\). The inputs (or domain) of the pmf are the possible values of \(R\), or \(\{1,2,3,4,5,6\}\). The outputs of the pmf are the probabilities corresponding to each outcome when \(R=r\).

  1. What is the domain of \(f\) (the collection of inputs)?

  2. What is the range of \(f\) (the collection of outputs)?

  3. Compute each of the following:

    1. \(P(R=1)\)
    2. \(P(R=2)\)
    3. \(P(R=9)\)
    4. \(P(R \neq 6)\)
    5. \(P(R > 4)\)
    6. \(P(R\leq 0)\)
    7. \(P(R\leq 2)\)
    8. \(P(R\leq 4.5)\)
    9. \(P(R\leq 5.1)\)
    10. \(P(R\leq 8)\)
  4. Given \(A\) is the event that \(R\) is an odd number, calculate \(P(A)\).

Answers
  1. The domain of \(f\) is the set \(\{ 1, 2, 3, 4, 5, 6 \}\), so the collection of possible outcomes of the random variable \(R\).

  2. The range of \(f\) is the set \(\{ \frac{1}{6} \}\).

    1. \(P(R=1) = \frac{1}{6}\)
    2. \(P(R=2) = \frac{1}{6}\)
    3. \(P(R=9) = 0\)
    4. \(P(R \neq 6) = 1 - P(R = 6) = 1 - \frac{1}{6} = \frac{5}{6}\)
    5. \(P(R > 4) = P(R = 5) + P(R = 6) = \sum_{i=5}^6 P(R = i) = \frac{1}{6} + \frac{1}{6} = \frac{2}{6} = \frac{1}{3}\)
    6. \(P(R \leq 0) = 0\)
    7. \(P(R \leq 2) = P(R = 1) + P(R = 2) = \frac{1}{6} + \frac{1}{6} = \frac{1}{3}\)
    8. \(P(R \leq 4.5) = P(R=1) + P(R=2) + P(R=3) + P(R=4) = \frac{1}{6} + \frac{1}{6} + \frac{1}{6} + \frac{1}{6} = \frac{2}{3}\)
    9. \(P(R \leq 5.1) = \sum_{i=1}^5P(R=i) = \sum_{i=1}^5\frac{1}{6} = 5(\frac{1}{6}) = \frac{5}{6}\)
    10. \(P(R\leq 8) = \sum_{i=1}^8P(R=i) = \sum_{i=1}^6\frac{1}{6} + \sum_{i=7}^8 0 = 6(\frac{1}{6}) + 0 = 1\)
  3. \(P(A) = P(R = 1) + P(R = 3) + P(R = 5) = 3\left(\frac{1}{6}\right) = \frac{1}{2}\)

Example 2

Suppose the probability distribution (or probability model) for the random variable \(X\) is \[f(x) = \begin{cases} 0.4 & \quad x = 0 \\ \\ 0.18 & \quad x = 3 \\ \\ 0.19 & \quad x = 6 \\ \\ 0.03 & \quad x = 9 \\ \\ 0.2 & \quad x=12 \end{cases}\] Compute the probabilities requested below:

  1. \(P(x \leq 6)\)

  2. \(P(x = 9)\)

  3. \(P(x = 7)\)

  4. \(P(x \leq 7)\)

  5. \(P(x \geq 10)\)

  6. \(P(x \leq 12)\)

Answers
  1. \(P(x \leq 6) = 0.77\)

  2. \(P(x = 9) = 0.03\)

  3. \(P(x = 7) = 0\)

  4. \(P(x \leq 7) = 0.77\)

  5. \(P(x \geq 10) = 0.2\)

  6. \(P(x \leq 12) = 1\)

Example 3

Suppose we toss two fair six-sided dice once. We will record the value that appears on each of the dice, and let \(X_1\) represent the outcome for the first die and \(X_2\) represent the outcome for the second die. Note the events from random variable \(X_1\) and the events from \(X_2\) are independent. Compute the following:

  1. \(P(X_1 = 3)\)

  2. \(P(X_2 = 1)\)

  3. \(P(X_1 = 4 | X_1 \text{ is even})\)

  4. \(P(X_1 = 2 | X_2 \text{ is even})\)

  5. \(P(X_1 = 3 \text{ and } X_2 = 1)\)

  6. \(P(X_1 = 3 \text{ and } X_1 = 1)\)

  7. \(P(X_1 \leq 2 \text{ and } X_2 > 2)\)

Answers

The probability model for the random variable \(X_1\) is \(f_1(x_1) = \begin{cases} \frac{1}{6} & \quad x_1 = 1, 2, 3, 4, 5, 6 \\ \\ 0 & \quad \text{otherwise}, \end{cases}\) similarily, the probability model for the random variable \(X_2\) is \(f_2(x_2) = \begin{cases} \frac{1}{6} & \quad x_2 = 1, 2, 3, 4, 5, 6 \\ \\ 0 & \quad \text{otherwise}. \end{cases}\)

  1. \(P(X_1 = 3) = f_1(3) = \frac{1}{6}\)

  2. \(P(X_2 = 1) = f_2(1) = \frac{1}{6}\)

  3. \(P(X_1 = 4 | X_1 \text{ is even}) = \frac{P(X_1 = 4 \text{ and } X_1 \text{ is even})}{P(X_1 \text{ is even})}= \frac{1/6}{3/6} = \frac{1}{3}\)

  4. \(P(X_1 = 2 | X_2 \text{ is even}) = P(X_1 = 2) = \frac{1}{6}\) (The random variables are independent, so knowledge about \(X_2\) does not affect \(X_1\).)

  5. \(P(X_1 = 3 \text{ and } X_2 = 1) = P(X_1=3)P(X_2=1) = \frac{1}{6}(\frac{1}{6}) = \frac{1}{36}\)

    • We can multiply the probabilities because \(X_1\) and \(X_2\) are independent.
  6. \(P(X_1 = 3 \text{ and } X_1 = 1) = 0\), as it is impossible for an observed value to be both 3 and 1 at the same time. We do not multiply probabilities unless the events are independent.

  7. \(P(X_1 \leq 2 \text{ and } X_2 > 2) = P(X_1 \leq 2)P(X_2 > 2) = (\sum_{i=1}^2P(X_1=i))(\sum_{i=3}^6P(X_2=i)) = (\frac{1}{3})(\frac{2}{3}) = \frac{2}{9}\)

Example 4

Suppose we toss seven fair six-sided dice once. We will record the value that appears on each of the dice, and let \(X_i\) represent the outcome for the \(i\)th die with \(i = 1, 2, ..., 7\). Note the events from random variables \(X_1\), \(X_2\), … \(X_7\) are independent. Compute the following:

  1. \(P(X_1 = 1)\)

  2. \(P(X_6 = 4)\)

  3. \(P(X_3 > 2)\)

  4. \(P(\text{all the dice have values greater than 2})\)

Answers

The probability model for the random variable \(X_1\) is \(f_i(x_i) = \begin{cases} \frac{1}{6} & \quad x_i = 1, 2, 3, 4, 5, 6 \\ \\ 0 & \quad \text{otherwise}, \end{cases}\) for \(i = 1, 2, ..., 7\).

  1. \(P(X_1 = 1) = \frac{1}{6}\)

  2. \(P(X_6 = 4) = \frac{1}{6}\)

  3. \(P(X_3 > 2) = \sum_{j=3}^6P(X_3=j) = 4\left(\frac{1}{6}\right) = \frac{2}{3}\)

  4. \(P(\text{all the dice have values greater than 2}) = \prod_{i=1}^7P(X_i > 2) = \prod_{i=1}^7(\sum_{j=3}^6P(X_i=j)) = \prod_{i=1}^7(\frac{2}{3}) = (\frac{2}{3})^7 = \frac{128}{2187} \approx 0.059\)


Source: Class.13 on byuimath.com