Plotting regression

A/B Testing in R

Lauryn Burleigh

Data Scientist

Linear line

cor.test(~ Enjoy + Time, data = pizza, 
         method = "pearson")
library(ggplot2)
ggplot(pizza, aes(x = Enjoy, 
                  y = Time)) + 
  geom_point()

A positive correlation scatter plot of the time to eat pizza on the y-axis and enjoy on the x-axis.

ggplot(pizza, aes(x = Enjoy, 
                  y = Time)) + 
  geom_point() +
  geom_smooth(method = "lm")

A positive correlation scatter plot of the time to eat pizza on the y-axis and enjoy on the x-axis and a blue line of best fit with confidence interval.

A/B Testing in R

Linear prediction

linear <- lm(Time ~ Enjoy, 
                data = Pizza) 
Enjoy  <- 12
topredict <-  data.frame(Enjoy) 
prediction <- predict(linear, 
                     newdata = topredict) 

ggplot(pizza, aes(x = Enjoy, y = Time)) + 
  geom_point() +
  geom_smooth(method = "lm") +  
  geom_hline(yintercept = prediction) + 
  geom_vline(xintercept = Enjoy) 

A positive correlation scatter plot of the time to eat pizza on the y-axis and enjoy on the x-axis and a blue line of best fit with confidence interval and intersecting black lines at an x of 12 and y of 6.24.

A/B Testing in R

Denoting groups

ggplot(pizza, aes(x = Enjoy, y = Time, 
                  color = Topping)) + 
  geom_point() +
  geom_smooth(method = "lm") 

A positive correlation scatter plot of the time to eat pizza on the y-axis and enjoy on the x-axis with the points and line of best fit for Pepperoni in pink and points and line for Cheese in blue.

A/B Testing in R

Denoting groups

ggplot(pizza, aes(x = Enjoy, 
                  y = Time)) + 
  geom_point(aes(colour = Topping)) +
  geom_smooth(method = "lm")

A positive correlation scatter plot of the time to eat pizza on the y-axis and enjoy on the x-axis with a blue line of best fit and the points for Cheese in pink and points for Pepperoni in blue.

A/B Testing in R

Logistic line

ggplot(pizza, aes(x = Enjoy, 
                  y = EatAgain)) + 
  geom_point(aes(colour = Topping)) +
  geom_smooth(method = "glm",  
              method.args = 
                 list(family = 
                      "binomial"))

Scatter plot with enjoy on the x-axis and eat again on the y-axis with points at 0 or 1, and a curved logistic regression line.

A/B Testing in R

Logistic prediction

Enjoy  <- 12

ggplot(pizza2, aes(x = Enjoy, 
                   y = EatAgain)) + 
  geom_point(aes(colour = Topping)) +
  geom_smooth(method = "glm",  
              method.args = 
              list(family = 
                   "binomial")) +
  geom_vline(xintercept = Enjoy) 

Scatter plot with enjoy on the x-axis and eat again on the y-axis with points at 0 or 1, colored pink for Pepperoni and blue for Cheese, and a curved logistic regression line and a black vertical line at 12 on the x-axis.

A/B Testing in R

Let's practice!

A/B Testing in R

Preparing Video For Download...