# All functions in this script are Core R (no package needed).

# Example - The p-q-r-d Functions for a N(0,1) Distribution
########################################################################################

# Area of blue-shaded left tail
pnorm(q = -0.6744897502, mean = 0, sd = 1)   # Probability
# X-axis value defining blue-shaded left tail
qnorm(p = .25, mean = 0, sd = 1)             # Quantile
# 3 random numbers from N(0,1) Distribution
rnorm(n = 3, mean = 0, sd = 1)               # Random
# Height of vertical blue line = f(0) value from Probability Density Function
dnorm(x = 0, mean = 0, sd = 1)               # Density


# Example - z-score for a Random Observation
########################################################################################

set.seed(7)   # Same random number as in the book

x <- rnorm(1, mean=-7.37, sd=0.88)   # 1 random number from N(-7.37,(.88)^2)
z <- (x - -7.37)/0.88                # z-score for x
cat("Random Observation x:", x, "  Calculated z-score:", z)

# Percentile of the random value: about the 99th
pnorm(-5.36, mean=-7.37, sd=0.88)
