Summary

Bellabeat was founded in 2013 manufacturing health-focused smart products for women. The marketing analytics team has been asked to focus on a product and analyze smart device usage data to gain insights into how customers use their product. These insights will be used to help guide the marketing strategy.

Ask

Business Task

Identify trends of customers using a non-Bellabeat smart device (Fitbit) dataset to gain insights to guide Bellabeat marketing strategy. For this analysis, we will be focusing on Bellabeat’s Leaf product.

Questions

  1. What are some trends in smart device usage?
  2. How could these trends apply to Bellabeat customers?
  3. How could these trends help influence Bellabeat’s marketing strategy

Key Stakeholders

Primary stakeholders: Urška Sršen and Sando Mur, executive team members.
Secondary stakeholders: Bellabeat marketing analytics team.

Prepare

The Data

FitBit Fitness Tracker Data (CCO: Public Domain, dataset was made available by Mobius) on Kaggle
There are 18 csv files available
Contains data for physical activity, sleep, and heart rate, with each user having a unique ID.

Credibility and Limitations

Only 30 users’ data is included in the dataset, meaning the data is most likely not representative.
The dataset is outdated and only contains two months’ worth of data. It is also limited in that FitBits are exclusively worn as watches, whereas the Bellabeat’s Leaf can be worn as a watch or a necklace, so the data obtained by wearing the Leaf as a necklace could differ.

Installing packages, libraries, and datasets

I installed the following packages and libraries to use.

install.packages('tidyverse')
install.packages('lubridate')
install.packages('ggpubr')
install.packages('janitor')

library(tidyverse)
library(lubridate)
library(ggplot2)
library(dplyr)
library(tidyr)
library(janitor)
library(readr)

Then I imported the following csv files and took an overview of them.

daily_activity <- read_csv('Fitbit_datasets/dailyActivity_merged.csv')
daily_calories <- read_csv('Fitbit_datasets/dailyCalories_merged.csv')
daily_steps <- read_csv('Fitbit_datasets/dailySteps_merged.csv')
heartrate <- read_csv('Fitbit_datasets/heartrate_seconds_merged.csv')
daily_sleep <- read_csv('Fitbit_datasets/sleepDay_merged.csv')
weight_log <- read_csv('Fitbit_datasets/weightLogInfo_merged.csv')

head(daily_activity)
head(daily_calories)
head(daily_steps)
head(heartrate)
head(daily_sleep)
head(weight_log)

The file daily_activity contains the data from the daily_calories and daily_steps,
making them redundant, so we won’t use them.
Next, we can check on how many unique Ids are in each dataset left.

n_distinct(daily_activity$Id)
## [1] 33
n_distinct(heartrate$Id)
## [1] 14
n_distinct(daily_sleep$Id)
## [1] 24
n_distinct(weight_log$Id)
## [1] 8

As seen, the weight_log and the heartrate datasets do not have enough unique user data to use them as part of this analysis, so we will disregard those as well.
It is important to also note the discrepancy between the number of users we were told the datasets had (30) and the actual number of unique IDs listed in the data we’re using (33 and 24).
Next, I want to quickly glimpse the data to double-check what we’ve got.

glimpse(daily_activity)
glimpse(daily_sleep)

Process

I chose to use R to have all of my data, process, analysis, and visuals in one place.
First, I check for any duplicates.

sum(duplicated(daily_activity))
## [1] 0
sum(duplicated(daily_sleep))
## [1] 3

Since only the daily sleep has duplicates, we’ll remove those.

daily_sleep <- daily_sleep %>%
  distinct() %>%
  drop_na()

Then I verify the duplicates were dropped.

sum(duplicated(daily_sleep))
## [1] 0

Next, I’ll clean up the column names to ensure they’re all lowercase and consistent.

clean_daily_activity <- daily_activity %>%
  clean_names()
clean_daily_sleep <- daily_sleep %>%
  clean_names()

The columns recording the dates in each data set are labeled differently, so I will change them to be the same.

colnames(clean_daily_sleep)[colnames(clean_daily_sleep) == "sleep_day"] = "activity_date"

In addition, both datasets have these columns as character format, so I convert them to date format.

clean_daily_activity <- clean_daily_activity %>%
  mutate(activity_date = as.POSIXct(activity_date, format = "%m/%d/%Y"))

clean_daily_sleep <- clean_daily_sleep %>%
  mutate(activity_date = as.POSIXct(activity_date, format ="%m/%d/%Y %I:%M:%S %p" , tz=Sys.timezone()))

I also will separate the date and time from the clean_daily_sleep data into two separate columns.

clean_daily_sleep <- clean_daily_sleep %>%
  separate(activity_date, into=c("activity_date", "sleep_time"), sep= " ")

Next, I take a look at the summary of both datasets before merging them.

clean_daily_activity %>%
  select(total_steps, total_distance, calories) %>%
  summary()
##   total_steps    total_distance      calories   
##  Min.   :    0   Min.   : 0.000   Min.   :   0  
##  1st Qu.: 3790   1st Qu.: 2.620   1st Qu.:1828  
##  Median : 7406   Median : 5.245   Median :2134  
##  Mean   : 7638   Mean   : 5.490   Mean   :2304  
##  3rd Qu.:10727   3rd Qu.: 7.713   3rd Qu.:2793  
##  Max.   :36019   Max.   :28.030   Max.   :4900

The average number of steps taken per day is 7,638. Average number of calories consumed is 2,304.

clean_daily_sleep %>%
  select(total_sleep_records, total_minutes_asleep, total_time_in_bed) %>%
  summary()
##  total_sleep_records total_minutes_asleep total_time_in_bed
##  Min.   :1.00        Min.   : 58.0        Min.   : 61.0    
##  1st Qu.:1.00        1st Qu.:361.0        1st Qu.:403.8    
##  Median :1.00        Median :432.5        Median :463.0    
##  Mean   :1.12        Mean   :419.2        Mean   :458.5    
##  3rd Qu.:1.00        3rd Qu.:490.0        3rd Qu.:526.0    
##  Max.   :3.00        Max.   :796.0        Max.   :961.0

Looking at the clean_daily_sleep data, one user spent 16 hours in bed, and most users are falling asleep almost as soon as they get into bed. This data does not account for injuries or disabilities, nor does it look at night-time routines.

Finally, I can merge the datasets.

clean_daily_activity_sleep <- merge(clean_daily_activity, clean_daily_sleep, by=c("id"),all=TRUE)

Analyze and Share

We can classify users by the number of steps they’ve taken in a day, utilizing the classification outlined in this article.
How we will classify the users is as follows: - Sedentary: Less than 5,000 steps daily - Low active: About 5,000 to 7,499 steps daily - Somewhat active: About 7,500 to 9,999 steps daily - Active: More than 10,000 steps daily - Highly active: More than 12,500 steps daily

daily_average_steps <- clean_daily_activity_sleep %>%
  group_by(id) %>%
  summarise (mean_daily_steps = mean(total_steps))

head(daily_average_steps)
## # A tibble: 6 × 2
##           id mean_daily_steps
##        <dbl>            <dbl>
## 1 1503960366           12117.
## 2 1624580081            5744.
## 3 1644430081            7283.
## 4 1844505072            2580.
## 5 1927972279             916.
## 6 2022484408           11371.
user_class <- daily_average_steps %>%
  mutate(user_class = case_when(
    mean_daily_steps < 5000 ~ "sedentary",
    mean_daily_steps >= 5000 & mean_daily_steps < 7499 ~ "low active", 
    mean_daily_steps >= 7500 & mean_daily_steps < 9999 ~ "somewhat active", 
    mean_daily_steps >= 10000 & mean_daily_steps <12500 ~ "active",
    mean_daily_steps >= 12500 ~ "highly active"))

Then I change it into a percentage and add the labels.

user_class_percent <- user_class %>%
  group_by(user_class) %>%
  summarise(total = n()) %>%
  mutate(totals = sum(total)) %>%
  group_by(user_class) %>%
  summarise(total_percent = total / totals) %>%
  mutate(labels = scales::percent(total_percent))

user_class_percent$user_class <- factor(user_class_percent$user_class , levels = c("highly active", "active", "somewhat active", "low active", "sedentary"))

head(user_class_percent)
## # A tibble: 5 × 3
##   user_class      total_percent labels
##   <fct>                   <dbl> <chr> 
## 1 active                 0.152  15.2% 
## 2 highly active          0.0606 6.1%  
## 3 low active             0.273  27.3% 
## 4 sedentary              0.242  24.2% 
## 5 somewhat active        0.273  27.3%

We can use this frame to create a chart

This shows the percent of users which fall into each category, with over 75 percent of users falling into the somewhat active, low active, and sedentary categories. The data here could have some inaccuracies depending on how often the user wears the watch.

We can also compare other aspects of the data.

clean_daily_activity_sleep %>% 
  ggplot(aes(x=total_steps, y=total_distance)) + 
  geom_point() + geom_smooth() + labs(title="Total Steps vs. Total Distance")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'

In this graph, it shows a clear correlation between the number of steps taken and the distance traveled. While there are points that deviate from the average line, leg length, age, and physical health data are not included, which could account for the slight variation.

clean_daily_activity_sleep %>%
  ggplot(aes(x=total_steps, y=calories)) +
  geom_point() + geom_smooth() + labs(title="Total Steps vs. Calories")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'

Although I expected a graph similar to the previous Total Steps vs Total Distance, it is clear in this graph that there is not as strong a correlation between the calorie intake and steps taken in a day, though there is some correlation.

clean_daily_activity_sleep %>%
  ggplot(aes(x=total_steps, y=total_minutes_asleep))+
  geom_jitter() + geom_smooth() + xlim(0,25000) +
  labs(title = "Total Steps vs. Total Minutes Asleep")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'

When comparing the total steps and time asleep, we find that getting more exercise does not seem to correlate to getting more sleep, or vise versa. Many other factors, including work, family, and physical or mental health, could contribute to how much sleep or how many steps a user takes. However, this would need to be researched since this could also just be a result of our limited data set.

clean_daily_activity_sleep %>%
  ggplot(aes(x=total_minutes_asleep, y=total_time_in_bed)) +
  geom_point()+ geom_smooth() +
  labs(title="Total Minutes Asleep vs. Total Time in Bed")
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'

The data here shows that generally, the more time a user spent in bed, the more time asleep they had.

Act

There are many limitations to this dataset, which Bellabeat should keep in mind.
Many of the users are sedentary or not very active, and they would benefit from fun reminders and being able to set individual goals to motivate them to move more.
Sleep and activity do not seem to affect the other, though I would recommend gathering more data to verify the accuracy of this.
Adding reminders for bedtime, along with relaxation aids like breathing and nature or other calming sound recordings, would aid users in improving the quality and length of their sleep.

Conclusion

In my first case study and first project using R, I learned how to find the answers to various questions and problems, not just what the analysis was answering. I found myself more confident in analyzing the data since I was able to use resources like Google, R Community, and others who have more experience using R. I’m looking forward to working on more case studies and using my skills.