#set document(title: "3.5 Discrete and Continuous Probability Distributions", author: "OpenStax / XYZ Homework") #set page(width: 8.5in, height: auto, margin: 1in) #import "@preview/cetz:0.5.2" #set text(font: ("STIX Two Text", "Libertinus Serif", "New Computer Modern"), size: 10.5pt, lang: "en") #show math.equation: set text(font: ("STIX Two Math", "New Computer Modern Math")) #set par(justify: true, leading: 0.62em, spacing: 0.9em) #set enum(spacing: 1.1em) // room between list items so tall inline fractions don't collide #set list(spacing: 1.1em) #set table(stroke: 0.5pt + rgb("#c7ccd3")) #let BLUE = rgb("#183B6F") // brand navy — section bars + example/solution labels (white on navy 11.09:1) #let ORANGE = rgb("#A94509") // brand primary-700 — AA-safe deep orange for TEXT (5.93:1 on white; raw brand #F37021 is 2.94:1 and must never carry text) #let RED = rgb("#DC2626") // brand error-600 #let GREEN = rgb("#059669") // brand success-600 (decoration only; small green text uses green-text #007942) #show heading.where(level: 1): it => block(width: 100%, above: 0pt, below: 16pt, fill: gradient.linear(BLUE, rgb("#2C5AA0")), inset: (x: 14pt, y: 12pt), radius: 3pt, text(fill: white, weight: "bold", size: 19pt, it.body)) #show heading.where(level: 2): it => block(width: 100%, above: 18pt, below: 10pt, fill: BLUE, inset: (x: 10pt, y: 6pt), radius: 2pt, text(fill: white, weight: "bold", size: 12pt, it.body)) #show heading.where(level: 3): it => text(fill: ORANGE, weight: "bold", size: 12.5pt, it.body) #show heading.where(level: 4): it => text(fill: BLUE, weight: "bold", size: 10.5pt, it.body) #let examplebox(label, title, body) = block(width: 100%, breakable: true, fill: rgb("#EFF1F5"), stroke: 0.5pt + rgb("#CFDDF0"), radius: 4pt, inset: 10pt, above: 12pt, below: 12pt)[ #block(below: 6pt)[#box(fill: BLUE, inset: (x: 6pt, y: 2pt), radius: 2pt, text(fill: white, weight: "bold", size: 8.5pt, label)) #h(0.4em) #strong[#title]] #body] // rail = decorative left rule (raw brand token); labelcolor = AA-safe label text shade #let notebox(label, rail, labelcolor, tint, body) = block(width: 100%, breakable: true, fill: tint, stroke: (left: 3pt + rail), inset: (left: 10pt, rest: 8pt), radius: (right: 4pt), above: 11pt, below: 11pt)[ #text(fill: labelcolor, weight: "bold", size: 7.5pt, tracking: 0.5pt)[#upper(label)] #linebreak() #body] #let solutionbox(body) = block(above: 4pt, below: 8pt)[ #text(fill: BLUE, weight: "bold", size: 8.5pt)[Solution] #linebreak() #body] #let figph(msg) = block(width: 100%, height: 60pt, fill: rgb("#f6f7f9"), stroke: (paint: rgb("#c7ccd3"), dash: "dashed"), radius: 4pt, inset: 10pt)[ #align(center + horizon, text(fill: rgb("#889"), style: "italic", size: 9pt, msg))] // Standardize inlined figure sizes: measure the natural CeTZ canvas, then scale to a // consistent envelope (aspect-aware; see build_typst.py FIG_* constants). Unlike the // print preamble, dimensions are FLOORED: in an editor a user can trim a figure to a // degenerate 1-D shape (a bare line), and w/h or tw/w would then divide by zero. #let _STD_W = 3.5 #let _WIDE_W = 5.6 #let _MAX_H = 3.4 #let _ASPECT_WIDE = 2.2 #let _UPSCALE_MAX = 1.15 #let stdfig(body) = context { let m = measure(body) let w = calc.max(m.width / 1in, 0.01) let h = calc.max(m.height / 1in, 0.01) let tw = if w / h > _ASPECT_WIDE { _WIDE_W } else { _STD_W } let s = calc.min(tw / w, _MAX_H / h, _UPSCALE_MAX) align(center, box(scale(x: s * 100%, y: s * 100%, reflow: true, body))) } #show figure: set block(breakable: false) #set figure(gap: 8pt) #show figure.caption: set text(size: 8.5pt, fill: rgb("#555")) == 3.5#h(0.6em)Discrete and Continuous Probability Distributions === Learning Outcomes By the end of this section, you should be able to: - Describe fundamental aspects of probability distributions. - Apply discrete probability distributions including binomial and Poisson distributions. - Apply continuous probability distributions including exponential and normal distributions. - Use Python to apply various probability distributions for probability applications. #strong[Probability distribution]s are used to model various scenarios to help with probability analysis and predictions, and they are used extensively to help formulate probability-based decisions. For example, if a doctor knows that the weights of newborn infants follow a normal (bell-shaped) distribution, the doctor can use this information to help identify potentially underweight newborn infants, which might indicate a medical condition warranting further investigation. Using a normal distribution, the doctor can calculate that only a small percentage of babies have weights below a certain threshold, which might prompt the doctor to further investigate the cause of the low weight. Or a medical researcher might be interested in the probability that a person will have high blood pressure or the probability that a person will have type O blood. === Overview of Probability Distributions To begin our discussion of probability distributions, some terminology will be helpful: - #strong[Random variable]—a variable where a single numerical value is assigned to a specific outcome from an experiment. Typically the letter #math.equation(block: false, alt: "x")[$x$] is used to denote a random variable. For example, assign the numerical values 1, 2, 3, … 13 to the cards selected from a standard 52-card deck of Ace, 2, 3, … 10, Jack, Queen, King. Notice we cannot use “Jack” as the value of the random variable since by definition a random variable must be a numerical value. - #strong[Discrete random variable]—a random variable is considered discrete if there is a finite or countable number of values that the random variable can take on. (If there are infinitely many values, the number of values is countable if it possible to count them individually.) Typically, a discrete random variable is the result of a count of some kind. For example, if the random variable #math.equation(block: false, alt: "x")[$x$] represents the number of cars in a parking lot, then the values that #emph[x] can take on can only be whole numbers since it would not make sense to have #math.equation(block: false, alt: "x equals 15.37")[$x = 15.37$] cars in the parking lot. - #strong[Continuous random variable]—a random variable is considered continuous if the value of the random variable can take on any value within an interval. Typically, a continuous random variable is the result of a measurement of some kind. For example, if the random variable #math.equation(block: false, alt: "x")[$x$] represents the weight of a bag of apples, then #math.equation(block: false, alt: "x")[$x$] can take on any value such as #math.equation(block: false, alt: "x equals 2.45734")[$x = 2.45734$] pounds of apples. To summarize, the difference between discrete and continuous probability distributions has to do with the nature of the random variables they represent. #strong[Discrete probability distributions] are associated with variables that take on a finite or countably infinite number of distinct values. #strong[Continuous probability distributions] deal with random variables that can take on any value within a given range or interval. It is important to identify and distinguish between discrete and continuous random variables since different statistical methods are used to analyze each type. #examplebox("Example 1")[][ A coin is flipped three times. Determine a possible random variable that can be assigned to represent the number of heads observed in this experiment. #solutionbox[ One possible random variable assignment could be to let #math.equation(block: false, alt: "x")[$x$] count the number of heads observed in each possible outcome in the sample space. When flipping a coin three times, there are eight possible outcomes, and #math.equation(block: false, alt: "x")[$x$] will be the numerical count corresponding to the number of heads observed for each outcome. Notice that the possible values for the random variable #math.equation(block: false, alt: "x")[$x$] are 0, 1, 2 and 3, as shown. #figure(table( columns: 4, align: left, inset: 6pt, table.header([#strong[Result for Flip \#1]], [#strong[Result for Flip \#2]], [#strong[Result for Flip \#3]], [#strong[Value of Random Variable #math.equation(block: false, alt: "x")[$x$]]]), [Heads], [Heads], [Heads], [3], [Heads], [Heads], [Tails], [2], [Heads], [Tails], [Heads], [2], [Heads], [Tails], [Tails], [1], [Tails], [Heads], [Heads], [2], [Tails], [Heads], [Tails], [1], [Tails], [Tails], [Heads], [1], [Tails], [Tails], [Tails], [0], )) ] ] #examplebox("Example 2")[][ Identify the following random variables as either discrete or continuous random variables: + The amount of gas, in gallons, used to fill a gas tank + Number of children per household in a certain neighborhood + Number of text messages sent by a certain student during a particular day + Number of hurricanes affecting Florida in a given year + The amount of rain, in inches, in Detroit, Michigan, in a certain month #solutionbox[ + The number of gallons of gas used to fill a gas tank can take on any value, such as 12.3489, so this represents a continuous random variable. + The number of children per household in a certain neighborhood can only take on certain discrete values such as 0, 1, 2, 3, etc., so this represents a discrete random variable. + The number of text messages sent by a certain student during a particular day can only take on certain discrete values such as 26, 10, 17, etc., so this represents a discrete random variable. + The number of hurricanes affecting Florida in a given year can only take on certain values such as 0, 1, 2, 3, etc., so this represents a discrete random variable. + The number of inches of rain in Detroit, Michigan, in a certain month can take on any value, such as 2.0563, so this represents a continuous random variable. ] ] === Discrete Probability Distributions: Binomial and Poisson Discrete random variables are of interest in many data science applications, and there are several probability distributions that apply to discrete random variables. In this chapter, we present the binomial distribution and the Poisson distribution, which are two commonly used probability distributions used to model discrete random variables for different types of events. ==== Binomial Distribution The #strong[binomial distribution] is used in applications where there are two possible outcomes for each trial in an experiment and the two possible outcomes can be considered as success or failure. For example, when a baseball player is at-bat, the player either gets a hit or does not get a hit. There are many applications of binomial experiments that occur in medicine, psychology, engineering, science, marketing, and other fields. There are many statistical experiments where the results of each trial can be considered as either a success or a failure. For example, when flipping a coin, the two outcomes are heads or tails. When rolling a die, the two outcomes can be considered to be an even number appears on the face of the die or an odd number appears on the face of the die. When conducting a marketing study, a customer can be asked if they like or dislike a certain product. Note that the word “success” here does not necessarily imply a good outcome. For example, if a survey was conducted of adults and each adult was asked if they smoke, we can consider the answer “yes” to be a success and the answer “no” to be a failure. This means that the researcher can define success and failure in any way; however, the binomial distribution is applicable when there are only two outcomes in each trial of an experiment. The requirements to identify a #strong[binomial experiment] and apply the binomial distribution include: - The experiment of interest is repeated for a fixed number of trials, and each trial is independent of other trials. For example, a market researcher might select a sample of 20 people to be surveyed where each respondent will reply with a “yes” or “no” answer. This experiment consists of 20 trials, and each person’s response to the survey question can be considered as independent of another person’s response. - There are only two possible outcomes for each trial, which can be labeled as “success” or “failure.” - The probability of success remains the same for each trial of the experiment. For example, from past data we know that 35% of people prefer vanilla as their favorite ice cream flavor. If a group of 15 individuals are surveyed to ask if vanilla is their favorite ice cream flavor, the probability of success for each trial will be 0.35. - The random variable #math.equation(block: false, alt: "x")[$x$] will count the number of successes in the experiment. Notice that since #math.equation(block: false, alt: "x")[$x$] will count the number of successes, this implies that #math.equation(block: false, alt: "x")[$x$] will be a discrete random variable. For example, if the researcher is counting the number of people in the group of 15 that respond to say vanilla is their favorite ice cream flavor, then #math.equation(block: false, alt: "x")[$x$] can take on values such as 3 or 7 or 12, but #math.equation(block: false, alt: "x")[$x$] could not equal 5.28 since #math.equation(block: false, alt: "x")[$x$] is counting the number of people. When working with a binomial experiment, it is useful to identify two specific parameters in a binomial experiment: + The number of trials in the experiment. Label this as #math.equation(block: false, alt: "n")[$n$]. + The probability of success for each trial (which is a constant value). Label this as #math.equation(block: false, alt: "p")[$p$]. We then count the number of successes of interest as the value of the discrete random variable. #linebreak() Label this as #math.equation(block: false, alt: "x")[$x$]. #examplebox("Example 3")[][ A medical researcher is conducting a study related to a certain type of shoulder surgery. A sample of 20 patients who have recently undergone the surgery is selected, and the researcher wants to determine the probability that 18 of the 20 patients had a successful result from the surgery. From past data, the researcher knows that the probability of success for this type of surgery is 92%. + Does this experiment meet the requirements for a binomial experiment? + If so, identify the values of #math.equation(block: false, alt: "n")[$n$], #math.equation(block: false, alt: "p")[$p$], and #math.equation(block: false, alt: "x")[$x$] in the experiment. #solutionbox[ + This experiment does meet the requirements for a binomial experiment since the experiment will be repeated for 20 trials, and each response from a patient will be independent of other responses. Each reply from a patient will be one of two responses—the surgery was successful or the surgery was not successful. The probability of success remains the same for each trial at 92%. The random variable #math.equation(block: false, alt: "x")[$x$] can be used to count the number of patients who respond that the surgery was successful. + The number of trials is 20 since 20 patients are being surveyed, so #math.equation(block: false, alt: "n equals 20")[$n = 20$]. #linebreak() The probability of success for each surgery is 92%, so #math.equation(block: false, alt: "p equals 0.92")[$p = 0.92$]. #linebreak() The number of successes of interest is 18 since the researcher wants to determine the probability that 18 of the 20 patients had a successful result from the surgery, so #math.equation(block: false, alt: "x equals 18")[$x = 18$]. ] ] When calculating the probability for #math.equation(block: false, alt: "x")[$x$] successes in a binomial experiment, a binomial probability formula can be used, but in many cases technology is used instead to streamline the calculations. The #strong[probability mass function (PMF)] for the binomial distribution describes the probability of getting exactly #math.equation(block: false, alt: "x")[$x$] successes in #math.equation(block: false, alt: "n")[$n$] independent #strong[Bernoulli trials], each with a probability #math.equation(block: false, alt: "p")[$p$] of success. The PMF is given by the formula: #math.equation(block: true, alt: "P open parenthesis X close parenthesis equals x equals open parenthesis the fraction n over k close parenthesis p to the power x open parenthesis 1 minus p close parenthesis to the power n minus x")[$P ( X ) = x = ( binom(n, k) ) p^(x) attach(( 1 − p ), t: n − x)$] Where: #linebreak() #math.equation(block: false, alt: "P open parenthesis X equals x close parenthesis")[$P ( X = x )$] is the probability that the random variable #math.equation(block: false, alt: "X")[$X$] takes on the value of exactly #math.equation(block: false, alt: "x")[$x$] successes #linebreak() #math.equation(block: false, alt: "n")[$n$] is the number of trials in the experiment #linebreak() #math.equation(block: false, alt: "p")[$p$] is the probability of success #linebreak() #math.equation(block: false, alt: "x")[$x$] is the number of successes in the experiment #math.equation(block: false, alt: "open parenthesis the fraction n over k close parenthesis")[$( binom(n, k) )$] refers to the number of ways to choose #math.equation(block: false, alt: "x")[$x$] successes from #math.equation(block: false, alt: "open parenthesis the fraction n over k close parenthesis equals the fraction n ! over open parenthesis n minus x close parenthesis ! x !")[$( binom(n, k) ) = frac(n !, ( n − x ) ! x !)$] Note: The notation #math.equation(block: false, alt: "n !")[$n !$] is read as #math.equation(block: false, alt: "n")[$n$] factorial and is a mathematical notation used to express the multiplication of #math.equation(block: false, alt: "n open parenthesis n minus 1 close parenthesis open parenthesis n minus 2 close parenthesis and so on open parenthesis 3 close parenthesis open parenthesis 2 close parenthesis open parenthesis 1 close parenthesis")[$n ( n − 1 ) ( n − 2 ) … ( 3 ) ( 2 ) ( 1 )$]. For example, #math.equation(block: false, alt: "5 ! equals open parenthesis 5 close parenthesis open parenthesis 4 close parenthesis open parenthesis 3 close parenthesis open parenthesis 2 close parenthesis open parenthesis 1 close parenthesis equals 120")[$5 ! = ( 5 ) ( 4 ) ( 3 ) ( 2 ) ( 1 ) = 120$]. #examplebox("Example 4")[][ For the binomial experiment discussed in Example 3, calculate the probability that 18 out of the 20 patients will respond to indicate that the surgery was successful. Also, show a graph of the binomial distribution to show the probability distribution for all values of the random variable #math.equation(block: false, alt: "x")[$x$]. #solutionbox[ In Example 3, the parameters of the binomial experiment are: #linebreak() #math.equation(block: false, alt: "n equals 20")[$n = 20$] #linebreak() #math.equation(block: false, alt: "p equals 0.92")[$p = 0.92$] #linebreak() #math.equation(block: false, alt: "x equals 18")[$x = 18$] Substituting these values into the binomial probability formula, the probability for 18 successes can be calculated as follows: #math.equation(block: true, alt: "P open parenthesis x close parenthesis, equals, the fraction n ! over open parenthesis n minus x close parenthesis ! x ! p to the power x open parenthesis 1 minus p close parenthesis to the power n minus x; P open parenthesis 18 close parenthesis, equals, the fraction 20 ! over open parenthesis 20 minus 18 close parenthesis ! 18 ! 0.92 to the power 18 open parenthesis 1 minus 0.92 close parenthesis to the power 20 minus 18; P open parenthesis 18 close parenthesis, equals, the fraction 20 ! over 2 ! 18 ! 0.92 to the power 18 open parenthesis 0.18 close parenthesis squared; P open parenthesis 18 close parenthesis, equals, 190 open parenthesis 0.223 close parenthesis open parenthesis 0.032 close parenthesis; P open parenthesis 18 close parenthesis, equals, 0.271")[$P ( x ) & = & frac(n !, ( n − x ) ! x !) p^(x) attach(( 1 − p ), t: n − x) \ P ( 18 ) & = & frac(20 !, ( 20 − 18 ) ! 18 !) 0.92^(18) attach(( 1 − 0.92 ), t: 20 − 18) \ P ( 18 ) & = & frac(20 !, 2 ! 18 !) 0.92^(18) attach(( 0.18 ), t: 2) \ P ( 18 ) & = & 190 ( 0.223 ) ( 0.032 ) \ P ( 18 ) & = & 0.271$] Based on this result, the probability that 18 out of the 20 patients will respond to indicate that the surgery was successful is 0.271, or approximately 27%. illustrates this binomial distribution, where the horizontal axis shows the values of the random variable #math.equation(block: false, alt: "x")[$x$], and the vertical axis shows the binomial probability for each value of #math.equation(block: false, alt: "x")[$x$]. Note that values of #math.equation(block: false, alt: "x")[$x$] less than 14 are not shown on the graph since these corresponding probabilities are very close to zero. #figure(figph[A bar graph of a probability distribution over a discrete variable x, with values 14, 16, 18, and 20. The probabilities range from 0 to 0.35. At x=14, the probability is just above 0. At x=16, it’s about 0.05. The probability peaks at x=19, exceeding 0.3.], alt: "A bar graph of a probability distribution over a discrete variable x, with values 14, 16, 18, and 20. The probabilities range from 0 to 0.35. At x=14, the probability is just above 0. At x=16, it’s about 0.05. The probability peaks at x=19, exceeding 0.3.", caption: [Graph of the Binomial Distribution for #math.equation(block: false, alt: "n equals 20")[$n = 20$] and #math.equation(block: false, alt: "p equals 0.92")[$p = 0.92$]]) ] ] Since these computations tend to be complicated and time-consuming, most data scientists will use technology (such as Python, #strong[R], #strong[Excel], or others) to calculate binomial probabilities. ==== Poisson Distribution The goal of a binomial experiment is to calculate the probability of a certain number of successes in a specific number of trials. However, there are certain scenarios where a data scientist might be interested to know the probability of a certain number of occurrences for a random variable in a specific interval, such as an interval of time. For example, a website developer might be interested in knowing the probability that a certain number of users visit a website per minute. Or a traffic engineer might be interested in calculating the probability of a certain number of accidents per month at a busy intersection. The #strong[Poisson distribution] is applied when counting the number of occurrences in a certain interval. The random variable then counts the number of occurrences in the interval. A common application for the Poisson distribution is to model arrivals of customers for a queue, such as when there might be 6 customers per minute arriving at a checkout lane in the grocery store and the store manager wants to ensure that customers are serviced within a certain amount of time. The Poisson distribution is a discrete probability distribution used in these types of situations where the interest is in a specific certain number of occurrences for a random variable in a certain interval such as time or area. The Poisson distribution is used where the following conditions are met: - The experiment is based on counting the number of occurrences in a specific interval where the interval could represent time, area, volume, etc. - The number of occurrences in one specific interval is independent of the number of occurrences in a different interval. Notice that when we count the number of occurrences that a random variable #math.equation(block: false, alt: "x")[$x$] occurs in a specific interval, this will represent a discrete random variable. For example, the count of the number of customers that arrive per hour to a queue for a bank teller might be 21 or 15, but the count could not be 13.32 since we are counting the number of customers and hence the random variable will be discrete. To calculate the probability of #math.equation(block: false, alt: "x")[$x$] successes, the Poisson probability formula can be used, as follows: #math.equation(block: true, alt: "P open parenthesis x close parenthesis equals the fraction μ to the power x e to the power minus μ over x ! , where x equals 0 , 1 , 2 , and so on")[$P ( x ) = frac(μ^(x) e^(− μ), x !) , " where " x = 0 , 1 , 2 , …$] Where: #linebreak() #math.equation(block: false, alt: "µ")[$µ$] is the average or mean number of occurrences per interval #linebreak() #math.equation(block: false, alt: "e")[$e$] is the constant 2.71828… #examplebox("Example 5")[][ From past data, a traffic engineer determines the mean number of vehicles entering a parking garage is 7 per 10-minute period. Calculate the probability that the number of vehicles entering the garage is 9 in a certain 10-minute period. Also, show a graph of the Poisson distribution to show the probability distribution for various values of the random variable #math.equation(block: false, alt: "x")[$x$]. #solutionbox[ This example represents a Poisson distribution in that the random variable #math.equation(block: false, alt: "x")[$x$] is based on the number of vehicles entering a parking garage per time interval (in this example, the time interval of interest is 10 minutes). Since the average is 7 vehicles per 10-minute interval, we label the mean #math.equation(block: false, alt: "µ")[$µ$] as 7. Since the engineer want to know the probability that 9 vehicles enter the garage in the same time period, the value of the random variable #math.equation(block: false, alt: "x")[$x$] is 9. Thus, in this example, the parameters of the Poisson distribution are: #math.equation(block: true, alt: "µ equals 7 x equals 9")[$µ = 7 x = 9$] Substituting these values into the Poisson probability formula, the probability for 9 vehicles entering the garage in a 10-minute interval can be calculated as follows: #math.equation(block: true, alt: "P open parenthesis x close parenthesis, equals, the fraction μ to the power x e to the power minus μ over x !; P open parenthesis 9 close parenthesis, equals, the fraction 7 to the power 9 e to the power minus 7 over 9 ! equals 0.101")[$P ( x ) & = & frac(μ^(x) e^(− μ), x !) \ P ( 9 ) & = & frac(7^(9) e^(− 7), 9 !) = 0.101$] Thus, there is about a 10% probability of 9 vehicles entering the garage in a 10-minute interval. illustrates this Poisson distribution, where the horizontal axis shows the values of the random variable #math.equation(block: false, alt: "x")[$x$] and the vertical axis shows the Poisson probability for each value of #math.equation(block: false, alt: "x")[$x$]. #figure(figph[A bar graph of a probability distribution function. The x-axis has values 5, 10, 15, and 20; the y-axis ranges from 0 to 0.15. The highest probability, at 0.15, occurs around x=6 and x =7, and probabilities decrease away from this peak.], alt: "A bar graph of a probability distribution function. The x-axis has values 5, 10, 15, and 20; the y-axis ranges from 0 to 0.15. The highest probability, at 0.15, occurs around x=6 and x =7, and probabilities decrease away from this peak.", caption: [Poisson Distribution for #math.equation(block: false, alt: "µ equals 7")[$µ = 7$]]) ] ] As with calculations involving the binomial distribution, data scientists will typically use technology to solve problems involving the Poisson distribution. === Normal Continuous Probability Distributions Recall that a random variable is considered continuous if the value of the random variable can take on any of infinitely many values. We used the example about that if the random variable #math.equation(block: false, alt: "x")[$x$] represents the weight of a bag of apples, then #math.equation(block: false, alt: "x")[$x$] can take on any value such as #math.equation(block: false, alt: "x equals 2.45734")[$italic(x) = 2.45734$] pounds of apples. Many probability distributions apply to continuous random variables. These distributions rely on determining the probability that the random variable falls within a distinct range of values, which can be calculated using a probability density function (PDF). The #strong[probability density function (PDF)] calculates the corresponding area under the probability density curve to determine the probability that the random variable will fall within this specific range of values. For example, to determine the probability that a salary falls between \$50,000 and \$70,000, we can calculate the area under the probability density function between these two salaries. Note that the total area under the probability density function will always equal 1. The probability that a continuous random variable takes on a specific value #math.equation(block: false, alt: "x")[$x$] is 0, so we will always calculate the probability for a random variable falling within some interval of values. In this section, we will examine an important continuous probability distribution that relies on the probability density function, namely the #emph[normal distribution]. Many variables, such as heights, weights, salaries, and blood pressure measurements, follow a normal distribution, making it especially important in statistical analysis. In addition, the normal distribution forms the basis for more advanced statistical analysis such as #strong[confidence intervals] and #strong[hypothesis testing], which are discussed in Inferential Statistics and Regression Analysis. The #strong[normal distribution] is a continuous probability distribution that is symmetrical and bell-shaped. It is used when the frequency of data values decreases with data values above and below the mean. The normal distribution has applications in many fields including engineering, science, finance, medicine, marketing, and psychology. The normal distribution has two parameters: the mean, #math.equation(block: false, alt: "µ")[$µ$], and the standard deviation, #math.equation(block: false, alt: "σ")[$σ$]. The mean represents the center of the distribution, and the standard deviation measures the spread, or dispersion, of the distribution. The variable #math.equation(block: false, alt: "x")[$x$] represents the realization, or observed value, of the random variable #math.equation(block: false, alt: "X")[$X$] that follows a normal distribution. The typical notation used to indicate that a random variable follows a normal distribution is as follows: #linebreak() #math.equation(block: false, alt: "X ~ N open parenthesis µ , σ close parenthesis")[$X ∼ N ( µ , σ )$]. For example, the notation #math.equation(block: false, alt: "X ~ N open parenthesis 5.2, 3.7 close parenthesis")[$X ∼ N ( 5.2, 3.7 )$] indicates that the random variable follows a normal distribution with mean of 5.2 and standard deviation of 3.7. A normal distribution with mean of 0 and standard deviation of 1 is called the #strong[standard normal distribution] and can be notated as #math.equation(block: false, alt: "X ~ N open parenthesis 0 , 1 close parenthesis")[$X ∼ N ( 0 , 1 )$]. Any normal distribution can be standardized by converting its values to #linebreak() #math.equation(block: false, alt: "z")[$z$]-scores. Recall that a #math.equation(block: false, alt: "z")[$z$]-score tells you how many standard deviations from the mean there are for a given measurement. #figure(figph[A symmetrical, bell-shaped curve is centered around the mean (µ) on the x-axis. The equation “X~N(µ, s)” signifies that X follows this distribution with mean µ and standard deviation s. The dashed line intersects the curve’s peak at the mean. ], alt: "A symmetrical, bell-shaped curve is centered around the mean (µ) on the x-axis. The equation “X~N(µ, s)” signifies that X follows this distribution with mean µ and standard deviation s. The dashed line intersects the curve’s peak at the mean.", caption: [Graph of the Normal (Bell-Shaped) Distribution]) The curve in is symmetric on either side of a vertical line drawn through the mean, #math.equation(block: false, alt: "µ")[$µ$]. The mean is the same as the median, which is the same as the mode, because the graph is symmetric about #math.equation(block: false, alt: "µ")[$µ$]. As the notation indicates, the normal distribution depends only on the mean and the standard deviation. Because the area under the curve must equal 1, a change in the standard deviation, #math.equation(block: false, alt: "σ")[$σ$], causes a change in the shape of the normal curve; the curve becomes fatter and wider or skinnier and taller depending on #math.equation(block: false, alt: "σ")[$σ$]. A change in #math.equation(block: false, alt: "µ")[$µ$] causes the graph to shift to the left or right. This means there are an infinite number of normal probability distributions. To determine probabilities associated with the normal distribution, we find specific areas under the normal curve. There are several methods for finding this area under the normal curve, and we typically use some form of technology. #strong[Python], #strong[Excel], and #strong[R] all provide built-in functions for calculating areas under the normal curve. #examplebox("Example 6")[][ Suppose that at a software company, the mean employee salary is \$60,000 with a standard deviation of \$7,500. Assume salaries at this company follow a normal distribution. Use Python to calculate the probability that a random employee earns more than \$68,000. #solutionbox[ A normal curve can be drawn to represent this scenario, in which the mean of \$60,000 would be plotted on the horizontal axis, corresponding to the peak of the curve. Then, to find the probability that an employee earns more than \$68,000, calculate the area under the normal curve to the right of the data value \$68,000. illustrates the area under the normal curve to the right of a salary of \$68,000 as the shaded-in region. #figure(figph[A normal distribution curve with values from 40,000 to 80,000 on the x-axis. The curve peaks at 60,000, the mean value, and a shaded area highlights values from 68,000 and higher.], alt: "A normal distribution curve with values from 40,000 to 80,000 on the x-axis. The curve peaks at 60,000, the mean value, and a shaded area highlights values from 68,000 and higher.", caption: [Bell-Shaped Distribution for Example 6. The shaded region under the normal curve corresponds to the probability that an employee earns more than \$68,000.]) To find the actual area under the curve, a Python command can be used to find the area under the normal probability density curve to the right of the data value of \$68,000. See Using Python with Probability Distributions for the specific Python program and results. The resulting probability is calculated as 0.143. Thus, there is a probability of about 14% that a random employee has a salary greater than \$75,000. ] ] The #strong[empirical rule] is a method for determining approximate areas under the normal curve for measurements that fall within one, two, and three standard deviations from the mean for the normal (bell-shaped) distribution.. #figure(figph[A symmetric, bell-shaped curve is centered around the mean (µ), with values from -3s to +3s on the x-axis. Data clusters around the mean, with observations decreasing in both directions as they move away. The peak at µ is the most common value; the tails capture extreme values.], alt: "A symmetric, bell-shaped curve is centered around the mean (µ), with values from -3s to +3s on the x-axis. Data clusters around the mean, with observations decreasing in both directions as they move away. The peak at µ is the most common value; the tails capture extreme values.", caption: [Normal Distribution Showing Mean and Increments of Standard Deviation]) If #math.equation(block: false, alt: "x")[$x$] is a continuous random variable and has a normal distribution with mean #math.equation(block: false, alt: "µ")[$µ$] and standard deviation #math.equation(block: false, alt: "σ")[$σ$], then the empirical rule states that: - About 68% of the #math.equation(block: false, alt: "x")[$x$]-values lie between #math.equation(block: false, alt: "minus 1 σ")[$− 1 σ$] and #math.equation(block: false, alt: "plus 1 σ")[$+ 1 σ$] units from the mean #math.equation(block: false, alt: "µ")[$µ$] (within one standard deviation of the mean). - About 95% of the #math.equation(block: false, alt: "x")[$x$]-values lie between #math.equation(block: false, alt: "minus 2 σ")[$− 2 σ$] and #math.equation(block: false, alt: "plus 2 σ")[$+ 2 σ$] units from the mean #math.equation(block: false, alt: "µ")[$µ$] (within two standard deviations of the mean). - About 99.7% of the #math.equation(block: false, alt: "x")[$x$]-values lie between #math.equation(block: false, alt: "minus 3 σ")[$− 3 σ$] and #math.equation(block: false, alt: "plus 3 σ")[$+ 3 σ$] units from the mean #math.equation(block: false, alt: "µ")[$µ$] (within three standard deviations of the mean). #emph[Notice that almost all the x-values lie within three standard deviations of the mean]. - The #math.equation(block: false, alt: "z")[$z$]-scores for #math.equation(block: false, alt: "plus 1 σ")[$+ 1 σ$] and #math.equation(block: false, alt: "minus 1 σ")[$− 1 σ$] are #math.equation(block: false, alt: "plus 1")[$+ 1$] and #math.equation(block: false, alt: "minus 1")[$− 1$], respectively. - The #math.equation(block: false, alt: "z")[$z$]-scores for #math.equation(block: false, alt: "plus 2 σ")[$+ 2 σ$] and #math.equation(block: false, alt: "minus 2 σ")[$− 2 σ$] are #math.equation(block: false, alt: "plus 2")[$+ 2$] and #math.equation(block: false, alt: "minus 2")[$− 2$], respectively. - The #math.equation(block: false, alt: "z")[$z$]-scores for #math.equation(block: false, alt: "plus 3 σ")[$+ 3 σ$] and #math.equation(block: false, alt: "minus 3 σ")[$− 3 σ$] are #math.equation(block: false, alt: "plus 3")[$+ 3$] and #math.equation(block: false, alt: "minus 3")[$− 3$], respectively. #examplebox("Example 7")[][ An automotive designer is interested in designing automotive seats to accommodate the heights for about 95% of customers. Assume the heights of adults follow a normal distribution with mean of 68 inches and standard deviation of 3 inches. For what range of heights should the designer model the car seats to accommodate 95% of drivers? #solutionbox[ According to the empirical rule, the area under the normal curve within two standard deviations of the mean is 95%. Thus, the designer should design the seats to accommodate heights that are two standard deviations away from the mean. The lower bound of heights would be #math.equation(block: false, alt: "68 minus 2 open parenthesis 3 close parenthesis")[$68 − 2 ( 3 )$] inches, and the upper bound of heights would be #math.equation(block: false, alt: "68 plus 2 open parenthesis 3 close parenthesis")[$68 + 2 ( 3 )$] inches. Thus, the car seats should be designed to accommodate driver heights between 62 and 74 inches. ] ] #notebox("Note", rgb("#8a94a6"), rgb("#556666"), rgb("#f7f8fa"))[ #emph[Statistical Applets to Explore Statistical Concepts] Applets are very useful tools to help visualize statistical concepts in action. Many applets can simulate statistical concepts such as probabilities for the normal distribution, use of the empirical rule, creating box plots, etc. Visit the #link("https://openstax.org/r/usu")[Utah State University applet website] and experiment with various statistical tools. ] === Using Python with Probability Distributions Python provides a number of built-in functions for calculating probabilities associated with both discrete and continuous probability distributions such as binomial distribution and the normal distribution. These functions are part of a library called #link("https://openstax.org/r/scipy")[#strong[scipy.stats]]. Here are a few of these probability density functions available within Python: - binom()—calculate probabilities associated with the binomial distribution - #strong[poisson] —calculate probabilities associated with the Poisson distribution - #strong[expon] —calculate probabilities associated with the exponential distribution - norm()—calculate probabilities associated with the normal distribution To import these probability density functions within Python, use the import command. For example, to import the binom() function use the following command: #linebreak() from scipy.stats import binom ==== Using Python with the Binomial Distribution The #strong[binom() function] in Python allows calculations of binomial probabilities. The probability mass function for the binomial distribution within Python is referred to as binom.pmf(). The syntax for using this function is binom.pmf(x, n, p) Where: #linebreak() #math.equation(block: false, alt: "n")[$n$] is the number of trials in the experiment #linebreak() #math.equation(block: false, alt: "p")[$p$] is the probability of success #linebreak() #math.equation(block: false, alt: "x")[$x$] is the number of successes in the experiment Consider the previous Example 3 worked out using the Python binom.pmf() function. A medical researcher is conducting a study related to a certain type of shoulder surgery. A sample of 20 patients who have recently undergone the surgery is selected, and the researcher wants to determine the probability that 18 of the 20 patients had a successful result from the surgery. From past data, the researcher knows that the probability of success for this type of surgery is 92%. Round your answer to 3 decimal places. In this example: #linebreak() #math.equation(block: false, alt: "n")[$n$] is the number of trials in the experiment #math.equation(block: false, alt: "equals 20")[$= 20$] #linebreak() #math.equation(block: false, alt: "p")[$p$] is the probability of success #math.equation(block: false, alt: "equals 0.92")[$= 0.92$] #linebreak() #math.equation(block: false, alt: "x")[$x$] is the number of successes in the experiment #math.equation(block: false, alt: "equals 18")[$= 18$] The corresponding function in Python is written as: binom.pmf (18, 20, 0.92) The #strong[round() function] is then used to round the probability result to 3 decimal places. Here is the input and output of this Python program: #notebox("Note", rgb("#8a94a6"), rgb("#556666"), rgb("#f7f8fa"))[ \# import the binom function from the scipy.stats library from scipy.stats import binom \# define parameters x, n, and p: x = 18 n = 20 p = 0.92 \# use binom.pmf() function to calculate binomial probability \# use round() function to round answer to 3 decimal places round (binom.pmf(x, n, p), 3) The resulting output will look like this: 0.271 ] ==== Using Python with the Normal Distribution The #strong[norm()] function in Python allows calculations of normal probabilities. The probability density function is sometimes called the cumulative density function, and so this is referred to as norm.cdf() within Python. The #strong[norm.cdf()] function returns the area under the normal probability density function to the left of a specified measurement. The syntax for using this function is #linebreak() norm.cdf(x, mean, standard\_deviation) Where: #linebreak() #emph[x] is the measurement of interest #linebreak() mean is the mean of the normal distribution #linebreak() standard\_deviation is the standard deviation of the normal distribution Let’s work out the previous Example 6 using the Python norm.cdf() function. Suppose that at a software company, the mean employee salary is \$60,000 with a standard deviation of \$7,500. Use Python to calculate the probability that a random employee earns more than \$68,000. In this example: #linebreak() #math.equation(block: false, alt: "x")[$x$] is the measurement of interest #math.equation(block: false, alt: "equals 68,000")[$= 68,000$] #linebreak() mean is the mean of the normal distribution #math.equation(block: false, alt: "equals 60,000")[$= 60,000$] #linebreak() standard deviation is the standard deviation of the normal distribution #math.equation(block: false, alt: "equals 7,500")[$= 7,500$] The corresponding function in Python is written as: #linebreak() norm.cdf(68000, 60000, 7500) The round() function is then used to round the probability result to 3 decimal places. Notice that since this example asks to find the area to the right of a salary of \$68,000, we can first find the area to the left using the norm.cdf() function and subtract this area from 1 to then calculate the desired area to the right. Here is the input and output of the Python program: #notebox("Note", rgb("#8a94a6"), rgb("#556666"), rgb("#f7f8fa"))[ \# import the norm function from the scipy.stats library from scipy.stats import norm \# define parameters x, mean and standard\_deviation: x = 68000 mean = 60000 standard\_deviation = 7500 \# use norm.cdf() function to calculate normal probability - note this is \# the area to the left \# subtract this result from 1 to obtain area to the right of the x-value \# use round() function to round answer to 3 decimal places round (1 - norm.cdf(x, mean, standard\_deviation), 3) The resulting output will look like this: 0.143 ] ==== Analysis of Salary Data by Gender There are many sources of salary data where median salaries for a certain year are published by gender. One source for data on earnings by demographics is the #link("https://openstax.org/r/bls")[Bureau of Labor Statistics]. As a group: - Research salary data by gender for a certain year. - Compile descriptive statistics where available for statistical measurements including the mean, median, quartiles, and standard deviation by gender. - Create graphical presentations for this data using histograms, side-by-side box plots, and time series graphs. - Discuss the following: + From your analysis, does there appear to be a wage gap for men’s vs. women’s salaries? + If so, is the wage gap improving over time or worsening over time?