# Do the data look normal?

set.seed(1892)
w <- rnorm(n = 1000, mean = 3, sd = 2)
mean(w)
sd(w)
# set.seed(1892)
# w <- rexp(n = 1000, rate = 1/3)
# curve(expr = dexp(x = x, rate = 1/3), col = "red", xlim = c(0,10), xlab = "w", ylab = "f(w)")

################################################################################
# Histogram

  hist(x = w)

  # y-axis is rescaled so a probability distribution can be drawn on the plot
  #   y-axis = (frequency for class) / ((sample size) * (class width))
  hist(x = w, main = "Histogram", xlab = "w", freq = FALSE)
  curve(expr = dnorm(x = x, mean = mean(w), sd = sd(w)), col = "red", add = TRUE)


################################################################################
# QQ plot

  n <- length(w)
  prob <- seq(from = 1/(n+1), to = 1-1/(n+1), by = 1/(n+1))
  norm.quant <- qnorm(p = prob, mean = mean(w), sd = sd(w))
  head(norm.quant)
  tail(norm.quant)

  norm.set <- data.frame(w.sort = sort(w), prob = prob, norm.quant = norm.quant)
  norm.set[prob > 0.495 & prob < 0.505,]

  plot(x = sort(w), y = norm.quant, main = "QQ plot", xlab = "w", ylab = "Normal quantiles")
  abline(a = 0, b = 1)

























#