The objective of this analysis is to investigate the factors influencing sleep patterns among various animal species. This analysis could provide insights into the relationship between sleep duration, sleep cycle characteristics, and other attributes such as diet, conservation status, and body weight.
Zookeepers, wildlife conservationists, and researchers studying animal behavior and physiology.
Understanding sleep patterns can be crucial for the management and care of animals in captivity, such as those in zoos. Wildlife conservationists can use insights to understand the natural behavior of animals in their habitats.
Zookeepers would benefit from insights into how environmental factors, conservation status, and other variables impact the sleep patterns of the animals they care for.
Conservationists can use the information to better understand the sleep needs of animals in the wild and make informed decisions for habitat preservation.
Loading the libraries and dataset:
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggthemes)
library(ggrepel)
library(ggplot2)
library(dplyr)
library(tidyr)
msleep <- read.csv("C:/Users/ABHIRAM/Downloads/msleep.csv")
Lets explore sleep patterns across different genera, orders, and diets. Also lets visualize the relationships between sleep duration, body weight, and other relevant variables.
# Exploring sleep patterns across different genera
genus_sleep <- msleep %>% group_by(genus) %>% summarise(avg_sleep = mean(sleep_total, na.rm = TRUE))
# Visualizing sleep patterns across genera
ggplot(genus_sleep, aes(x = reorder(genus, avg_sleep), y = avg_sleep)) +
geom_bar(stat = "identity", fill = "skyblue") +
theme(axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1, size = 10)) +
labs(title = "Average Sleep Duration Across Genera", x = "Genus", y = "Average Sleep Duration (hours)")
The bar chart is chosen to visualize average sleep duration across genera, facilitating easy comparison.
# Bar chart to visualize sleep patterns based on orders
ggplot(msleep, aes(x = order, fill = vore)) +
geom_bar(stat = "count") +
theme(axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1, size = 8)) +
labs(title = "Sleep Patterns Based on Orders", x = "Orders", y = "Count", fill = "Diet")
A bar chart is selected to illustrate sleep patterns based on orders, providing a count for each diet category within orders.
# Bar chart to visualize sleep patterns based on diets
ggplot(msleep, aes(x = vore, fill = vore)) +
geom_bar(stat = "count") +
labs(title = "Sleep Patterns Based on Diets", x = "Diet", y = "Count", fill = "Diet")
A bar chart is employed to display sleep patterns based on diets, offering a count for each diet category.
# Scatter plot to explore the relationship between sleep duration and body weight
ggplot(msleep, aes(x = sleep_total, y = bodywt)) +
geom_point() +
labs(title = "Relationship Between Sleep Duration and Body Weight", x = "Sleep Duration", y = "Body Weight")
A scatter plot is chosen to investigate the relationship between sleep duration and body weight.
# Box plot to check for differences in sleep patterns based on conservation status
ggplot(msleep, aes(x = conservation, y = sleep_total, fill = conservation)) +
geom_boxplot() +
labs(title = "Sleep Patterns Based on Conservation Status", x = "Conservation Status", y = "Sleep Duration", fill = "Conservation Status")
A box plot is used to identify differences in sleep patterns based on conservation status.
After seeing all the sleeps patterns of the mammals based on their genus, order, diet, vore and conservation status, it has been seen that their are a significant changes in the sleep patterns of the mammals based on the vore and conservation status. So the questions here are: Does carnivores sleep less thatn herbivores? and Does the conservation status effect the sleep patterns of the mammals? Lets find out.
Null Hypothesis (H0): The average sleep duration for carnivores is equal to the average sleep duration for herbivores. Alternative Hypothesis (H1): The average sleep duration for carnivores is less than the average sleep duration for herbivores.
The first hypothesis is based on the assumption that the type of diet (carnivore or herbivore) may influence the sleep patterns of animals. Carnivores, being more active hunters, might need less sleep compared to herbivores, which spend more time grazing. This hypothesis is grounded in the ecological roles of carnivores and herbivores and their energy requirements. The null hypothesis assumes no difference, while the alternative hypothesis suggests a specific direction of difference (carnivores sleep less).
Null Hypothesis (H0): There is no significant difference in sleep patterns between animals with “Low” and “Very High” bodyweights.
Alternative Hypothesis (H1): There is a significant difference in sleep patterns between animals with “Low” and “Very High” bodyweights.
The second hypothesis aims to explore the potential impact of conservation status on the sleep patterns of animals. Conservation status serves as an indicator of the health and well-being of animal populations, reflecting various environmental conditions and stressors. The null hypothesis posits that there is no significant difference in the average sleep duration among animals with different conservation statuses. In contrast, the alternative hypothesis proposes that there is a meaningful difference in sleep duration among these groups. By testing these hypotheses, we seek to determine whether conservation status plays a role in influencing the sleep patterns of animals, providing insights into the connection between environmental factors and animal behavior.
Null Hypothesis (H0): There is no significant difference in the average sleep duration among different conservation statuses. Alternative Hypothesis (H1): There is a significant difference in the average sleep duration among different conservation statuses.
The third hypothesis explores the impact of conservation status on sleep duration. Different conservation statuses may reflect varying degrees of stress, environmental conditions, or disturbances, all of which could influence the sleep patterns of animals. Conservation status is a broad indicator of the health and well-being of animal populations. Understanding its potential impact on sleep duration can provide valuable insights into the relationship between animal behavior and environmental conditions.
# Hypothesis 1: Carnivores sleep less than herbivores
t_test_result <- t.test(msleep$sleep_total[msleep$vore == "carni"], msleep$sleep_total[msleep$vore == "herbi"])
# Print t-test results
print(t_test_result)
##
## Welch Two Sample t-test
##
## data: msleep$sleep_total[msleep$vore == "carni"] and msleep$sleep_total[msleep$vore == "herbi"]
## t = 0.63232, df = 39.31, p-value = 0.5308
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -1.911365 3.650509
## sample estimates:
## mean of x mean of y
## 10.378947 9.509375
msleep <- na.omit(msleep)
# Creating a data frame with the test results
result_data <- data.frame(
Group = c("Carnivores", "Herbivores"),
Mean = c(mean(msleep$sleep_total[msleep$vore == "carni"]), mean(msleep$sleep_total[msleep$vore == "herbi"])),
SD = c(sd(msleep$sleep_total[msleep$vore == "carni"]), sd(msleep$sleep_total[msleep$vore == "herbi"])),
CI = c(t_test_result$conf.int[1], t_test_result$conf.int[2])
)
# Creating a bar plot with error bars
ggplot(result_data, aes(x = Group, y = Mean, fill = Group)) +
geom_bar(stat = "identity", position = "dodge", width = 0.7) +
geom_errorbar(aes(ymin = Mean - CI, ymax = Mean + CI), position = position_dodge(width = 0.7), width = 0.25) +
labs(title = "Average Sleep Duration: Carnivores vs. Herbivores", y = "Average Sleep Duration", x = "Group") +
theme_minimal()
Based on the results of the Welch Two Sample t-test:
Null Hypothesis: There is no significant difference in the average sleep duration between carnivores and herbivores.
# Hypothesis 2
# Create a weight category based on body weight
msleep$weight_category <- cut(msleep$bodywt, breaks = c(0, 1, 5, 10, Inf), labels = c("Low", "Medium", "High", "Very High"), include.lowest = TRUE)
# Pairwise t-tests for sleep patterns based on body weight category
t_test_results <- pairwise.t.test(msleep$sleep_total, msleep$weight_category, p.adjust.method = "bonferroni")
# Print pairwise t-test results
print(t_test_results)
##
## Pairwise comparisons using t tests with pooled SD
##
## data: msleep$sleep_total and msleep$weight_category
##
## Low Medium
## Medium 1.000 -
## Very High 0.011 0.011
##
## P value adjustment method: bonferroni
This code uses the pairwise.t.test function to perform pairwise t-tests between different levels of the ‘weight_category’ variable. The p.adjust.method = “bonferroni” parameter adjusts the p-values for multiple comparisons.
# Visualization of the t-test results
ggplot(msleep, aes(x = weight_category, y = sleep_total, fill = weight_category)) +
geom_boxplot() +
labs(title = "Sleep Patterns Based on Bodyweight", x = "Bodyweight Category", y = "Sleep Duration", fill = "Bodyweight Category") +
geom_text(aes(label = ifelse(weight_category %in% c("Low", "Very High"), as.character(round(sleep_total, 2)), "")),
vjust = -0.5, size = 3, color = "black") +
theme_minimal()
Null Hypothesis (H0): There is no significant difference in sleep duration between animals with low body weight and those with very high body weight.
# Hypothesis 3: Conservation status affects sleep duration
anova_lm <- aov(sleep_total ~ conservation, data = msleep)
# Print ANOVA results
print(summary(anova_lm))
## Df Sum Sq Mean Sq F value Pr(>F)
## conservation 4 173.0 43.24 2.956 0.0551 .
## Residuals 15 219.4 14.63
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Interpretation based on the results of ANOVA test results:
Null Hypothesis: There is no significant difference in the average sleep duration among different conservation statuses.
Alternative Hypothesis: There is a significant difference in the average sleep duration among different conservation statuses.
In conclusion, our comprehensive analysis of sleep patterns across diverse animal species has uncovered valuable insights with far-reaching implications. From understanding the average sleep duration across genera, orders, and diets to delving into the influence of conservation status, our findings offer a nuanced perspective on the intricate relationship between animal behavior and various factors. The exploration of hypotheses has provided meaningful answers, shedding light on the sleep disparities between carnivores and herbivores and revealing the impact of body weight and conservation status on sleep duration.