2024-04-04

Introduction

In this ioslide presentation, I chose to present linear regression with the data set that is included with Base R called “ChickWeight.” Through linear regression, we will be able to see the progress of weight between 50 chicks on 4 different diets, along with other insights. This data set includes 4 variables:

  • Weight
  • Time
  • Chick
  • Diet

Simplifying the Data Set

The first thing I did was found the average weight of chicks between the four different diets they were on. From these stats, we are able to determine which diet creates larger/smaller chickens. Larger chickens are what butchers for, so finding a diet that fattens the chicks the most is ideal.

The following code chunk is one way I determined the average weight of the chicks on each diet. I used these numbers as a way to check if the other ways I’m computing the mean in ggplot matches:

averageWeight = tapply(ChickWeight$weight, 
                       ChickWeight$Diet, 
                       mean)
print(averageWeight)
       1        2        3        4 
102.6455 122.6167 142.9500 135.2627 

ggplot of the Average Weight of Chicks

Below is a plot that shows the average weight of the chicks between 4 different diets. From these results, we can conclude that Diet 3 creates the largest chickens, while Diet 1 creates the smallest chickens.

Basic Equation Used for Solving Average Weight for Each Diet


\[ \text{Average Weight}_{\text{Diet}} = \frac{\text{Total Weight}_{\text{Diet}}}{\text{Number of Chicks}_{\text{Diet}}} \]

ggplot Showing Weight Growth of All Chicks

This ggplot shows the weight progress of all 50 chicks over the course of 21 days in this data set. As we can see by the different lines, the green line shows a larger weight amongst the other chicks. This means that Diet 3 indeed produces the largest chicks.

Plotly Plot Showing the Weight on the 21st Day

This interactive plot allows you to look at the weights of all 50 chicks after the 21st day. From observation, the 35th chick weighed the most at 373 lbs while on Diet 3, as specified by the “+” symbol.

Code Chunk That Produces Plotly Plot

finalWeight = ChickWeight %>%
  filter(Time == 21)

plot_ly(finalWeight, 
        x = ~Chick, 
        y = ~weight, 
        type = 'scatter', 
        mode = 'markers', 
        marker = list(
          color = ~weight, 
          colorscale = "Rainbow", 
          symbol = ~factor(Diet))) %>%
  layout(title = "Weight of Chicks on the Last Day", 
         yaxis = list(title = "Weight"))

Equation Used to Find the Final Weight of Each Chick


\[ W_{\text{final}} = \beta_0 + \beta_1\times\text{Time} \]