Statistical Functions

Harold Nelson

2023-03-23

Setup

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.1     ✔ purrr   0.3.4
## ✔ tibble  3.2.1     ✔ dplyr   1.1.1
## ✔ tidyr   1.2.1     ✔ stringr 1.4.1
## ✔ readr   2.1.2     ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()

First, let’s get immersed in a 19th century method of computing probabilities using a normal curve table.

Watch https://www.youtube.com/watch?v=xI9ZHGOSaCg

It’s only 11 minutes.

The Modern Method

What is the probability that a pizza will be less than 16 inches in diameter if the diameters of pizzas is normal with a mmean of 16.3 and a standard deviation of .2?

Solution

pnorm(16,mean =  16.3, sd = .2)
## [1] 0.0668072

Do this using rdrr.io

The point is that anyone who can connect to the internet has immediate access to this level of R functionality. There is no need to install R. Do this with your phone.

Another Problem

Given the same assumptions as above, find the probability that a pizza has a diameter greater than 16.5?

Solution

1 - pnorm(16.5, mean = 16.3, sd = .2)
## [1] 0.1586553

YAP (Yet Another Problem)

Given the same assumption as above, what is the probability that a pizza has a diameter between 15.95 and 16.63?

pnorm(16.63, mean = 16.3, sd = .2) - pnorm(15.95, mean = 16.3, sd = .2)
## [1] 0.9104694

ChatGPT

I asked ChatGPT to solve the problem. Here is the conversation.

https://sharegpt.com/c/A506DPO.

ChatGPT produced the correct code, but the numerical answer was different.

Other Distributions

The functions p, d, q, and r exist for every theoretical distribution. The “norm” is replaced by something else for another distribution.

For example, in the case of the binomial distribution, we have the following.