# Sample Data
library(wooldridge)
B <- barium
Identify outliers using the third empirical rule.
plot(B$t, B$gas,
main = "Line Graph of Gasoline Production Over Time",
ylab = "Gasoline Production", xlab = "Time Trend")
lines(B$t, B$gas)
gas.upper_limit3 <- mean(B$gas) + 3*sd(B$gas)
gas.lower_limit3 <- mean(B$gas) - 3*sd(B$gas)
abline(h = gas.upper_limit3, col = 4) # Horizontal blue line
abline(h = gas.lower_limit3, col = 4) # Horizontal blue line
Identify outliers using the second empirical rule.
plot(B$t, B$gas,
main = "Line Graph of Gasoline Production Over Time",
ylab = "Gasoline Production", xlab = "Time Trend")
lines(B$t, B$gas)
gas.upper_limit3 <- mean(B$gas) + 1.5*sd(B$gas)
gas.lower_limit3 <- mean(B$gas) - 1.5*sd(B$gas)
abline(h = gas.upper_limit3, col = 2) # Horizontal red line
abline(h = gas.lower_limit3, col = 2) # Horizontal red line
# Functions
library(ggplot2)
# Sample Data
library(wooldridge)
B <- barium
Identify outliers using the third empirical rule.
gas.upper_limit3 <- mean(B$gas) + 3*sd(B$gas)
gas.lower_limit3 <- mean(B$gas) - 3*sd(B$gas)
ggplot(B, aes(x = t, y = gas)) +
geom_line() +
geom_hline(yintercept = gas.upper_limit3, colour = "blue") +
geom_hline(yintercept = gas.lower_limit3, colour = "blue") +
labs(title = "Line Graph of Gasoline Production Over Time")
Identify outliers using the second empirical rule.
gas.upper_limit2 <- mean(B$gas) + 2*sd(B$gas)
gas.lower_limit2 <- mean(B$gas) - 2*sd(B$gas)
ggplot(B, aes(x = t, y = gas)) +
geom_line() +
geom_hline(yintercept = gas.upper_limit2, colour = "red") +
geom_hline(yintercept = gas.lower_limit2, colour = "red") +
labs(title = "Line Graph of Gasoline Production Over Time")