Introduction

Penguins come in different sizes, and their flipper lengths might be related to how much they weigh. By looking at these two measurements, we can see if penguins with longer flippers also tend to weigh more. Since there are different types of penguins, I will also compare the species to see if the relationship is different.

This project looks at the question: Is there a relationship between a penguin’s flipper length and its body mass, and does this relationship change depending on the species? I will use the Palmer Penguins dataset from the palmerpenguins R package. The data were collected by Dr. Kristen Gorman and the Palmer Station research program in Antarctica. I will focus on three variables: flipper_length_mm, which is the length of a penguin’s flippers in millimeters; body_mass_g, which is the penguin’s weight in grams; and species, which tells us what type of penguin it is: Adelie, Chinstrap, or Gentoo (Horst, Hill, & Gorman, 2020).

Data Analysis

First, I will look at the dataset and check if any information is missing. I will remove rows that are missing any of the three variables I need. Then, I will calculate summary statistics for each penguin species and make a scatter plot to show the relationship between flipper length and body mass. Each species will have its own color, and the graph will include a trend line for each species. Finally, I will use a linear regression model to study how flipper length and species are related to body mass. These steps will help me understand the patterns in the data, but they will not prove that flipper length causes a penguin to weigh more or less.

1. Load the dataset and inspect it

# Load the dataset from the palmerpenguins package
data("penguins", package = "palmerpenguins")

# Preview the data and check its structure
head(penguins)
str(penguins)
## tibble [344 × 8] (S3: tbl_df/tbl/data.frame)
##  $ species          : Factor w/ 3 levels "Adelie","Chinstrap",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ island           : Factor w/ 3 levels "Biscoe","Dream",..: 3 3 3 3 3 3 3 3 3 3 ...
##  $ bill_length_mm   : num [1:344] 39.1 39.5 40.3 NA 36.7 39.3 38.9 39.2 34.1 42 ...
##  $ bill_depth_mm    : num [1:344] 18.7 17.4 18 NA 19.3 20.6 17.8 19.6 18.1 20.2 ...
##  $ flipper_length_mm: int [1:344] 181 186 195 NA 193 190 181 195 193 190 ...
##  $ body_mass_g      : int [1:344] 3750 3800 3250 NA 3450 3650 3625 4675 3475 4250 ...
##  $ sex              : Factor w/ 2 levels "female","male": 2 1 1 NA 1 2 1 2 NA NA ...
##  $ year             : int [1:344] 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 ...
dim(penguins)
## [1] 344   8

The first rows provide a preview of the observations, str() shows the variables and their data types, and dim() reports the number of rows and columns.

2. Check missing values and clean the data

# Count missing values in the variables used for this project
colSums(is.na(penguins[, c("flipper_length_mm", "body_mass_g", "species")]))
## flipper_length_mm       body_mass_g           species 
##                 2                 2                 0
# Keep the three relevant columns and remove rows with missing values
penguins_clean <- penguins |>
  dplyr::select(species, flipper_length_mm, body_mass_g) |>
  dplyr::filter(
    !is.na(species),
    !is.na(flipper_length_mm),
    !is.na(body_mass_g)
  )

# Check the cleaned dataset
dim(penguins_clean)
## [1] 342   3
summary(penguins_clean)
##       species    flipper_length_mm  body_mass_g  
##  Adelie   :151   Min.   :172.0     Min.   :2700  
##  Chinstrap: 68   1st Qu.:190.0     1st Qu.:3550  
##  Gentoo   :123   Median :197.0     Median :4050  
##                  Mean   :200.9     Mean   :4202  
##                  3rd Qu.:213.0     3rd Qu.:4750  
##                  Max.   :231.0     Max.   :6300

This step keeps only the information needed for my research question and removes any rows with missing information. The summary helps me see the lowest, highest, and average values in the data.

3. Summarize measurements by species

species_summary <- penguins_clean |>
  dplyr::group_by(species) |>
  dplyr::summarise(
    penguin_count = dplyr::n(),
    mean_flipper_length_mm = mean(flipper_length_mm),
    mean_body_mass_g = mean(body_mass_g),
    median_body_mass_g = median(body_mass_g),
    .groups = "drop"
  )

knitr::kable(
  species_summary,
  digits = 2,
  caption = "Flipper length and body mass summary by penguin species"
)
Flipper length and body mass summary by penguin species
species penguin_count mean_flipper_length_mm mean_body_mass_g median_body_mass_g
Adelie 151 189.95 3700.66 3700
Chinstrap 68 195.82 3733.09 3700
Gentoo 123 217.19 5076.02 5000

This table shows how many penguins are in each species and compares their average flipper length and body weight. It also shows the middle body weight for each species to help us understand their sizes.

4. Visualize the relationship

library(ggplot2)

ggplot(
  penguins_clean,
  aes(x = flipper_length_mm, y = body_mass_g, color = species)
) +
  geom_point(alpha = 0.75, size = 2) +
  geom_smooth(method = "lm", se = FALSE) +
  labs(
    title = "Penguin Flipper Length and Body Mass",
    subtitle = "Points and fitted linear trends are shown by species",
    x = "Flipper length (millimeters)",
    y = "Body mass (grams)",
    color = "Species"
  ) +
  theme_minimal()

Each point on the graph represents one penguin. The different colors show the three penguin species, and the lines show the patterns in the data. These lines help us see if penguins with longer flippers also tend to weigh more within each species.

5. Fit a linear regression model

model <- lm(body_mass_g ~ flipper_length_mm * species, data = penguins_clean)

summary(model)
## 
## Call:
## lm(formula = body_mass_g ~ flipper_length_mm * species, data = penguins_clean)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -911.18 -251.93  -31.77  197.82 1144.81 
## 
## Coefficients:
##                                     Estimate Std. Error t value Pr(>|t|)    
## (Intercept)                        -2535.837    879.468  -2.883  0.00419 ** 
## flipper_length_mm                     32.832      4.627   7.095 7.69e-12 ***
## speciesChinstrap                    -501.359   1523.459  -0.329  0.74229    
## speciesGentoo                      -4251.444   1427.332  -2.979  0.00311 ** 
## flipper_length_mm:speciesChinstrap     1.742      7.856   0.222  0.82467    
## flipper_length_mm:speciesGentoo       21.791      6.941   3.139  0.00184 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 370.6 on 336 degrees of freedom
## Multiple R-squared:  0.7896, Adjusted R-squared:  0.7864 
## F-statistic: 252.2 on 5 and 336 DF,  p-value: < 2.2e-16

This model looks at flipper length, penguin species, and how they are related to body weight. It helps us see if the relationship between flipper length and weight is different for each species. The results give us numbers that we can compare with the table and graph. However, this does not prove that longer flippers cause penguins to weigh more.

Conclusion and Future Directions

Conclusion and Future Directions

After looking at the results, I found that penguins with longer flippers tend to weigh more. The table shows that Gentoo penguins have the longest flippers and weigh the most on average. Adelie and Chinstrap penguins have shorter flippers and weigh less. The graph and model also show that flipper length and body weight are related. However, the relationship is not exactly the same for every species. Gentoo penguins show a stronger relationship than Adelie penguins, while Adelie and Chinstrap penguins have similar patterns. This helps answer my research question because it shows that flipper length is related to body weight, but the relationship can depend on the species.

One limitation of my project is that I only studied flipper length, body weight, and species. The dataset also includes information about whether penguins are male or female, which island they were found on, and their bill measurements. These things might also be related to their body weight. In the future, I could study these other factors to learn more about penguin sizes. I could also compare other penguin datasets to see if the results are similar. My findings only describe the penguins in this dataset, so they might not be the same for all penguins.

References

Horst, A. M., Hill, A. P., & Gorman, K. B. (2020). palmerpenguins: Palmer Archipelago (Antarctica) penguin data. https://github.com/allisonhorst/palmerpenguins

Palmer Penguins project website: https://allisonhorst.github.io/palmerpenguins/