Installing necessary packages for the Analysis

install.packages('tidyverse')
install.packages('lubridate')
install.packages('dplyr')
install.packages('ggplot2')
install.packages('tidyr')

Loading packages to Library

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

Now, let’s load our Smart Fitness Device Dataset

activities <- read.csv("dailyActivity_merged.csv")
calories <- read.csv("dailyCalories_merged.csv")
daily_step <- read.csv("dailySteps_merged.csv")
daily_sleep <- read.csv("sleepDay_merged.csv")
weight <- read.csv("weightLogInfo_merged.csv")
intensities <- read.csv("dailyIntensities_merged.csv")

Let’s have a summarized view of our dataset. Using the head() function, we can review the data heading. A more details review can be done usig SQL or Worksheet.

head(activities)
head(calories)
head(daily_step)
head(daily_sleep)
head(weight)
head(intensities)

Let’s ensure the column names for date and Id are consistent across board.

#Rename the column
activities <- activities %>%
  rename(A_Date = ActivityDate)
weight <- weight %>%
  rename(A_Date = Date)
daily_sleep <- daily_sleep %>%
  rename(A_Date = SleepDay)

Now, ensure character consistency for both Id and A_Date columns

activities$Id <- as.character(activities$Id)
weight$Id <- as.character(weight$Id)
daily_step$Id <- as.character(daily_step$Id)
daily_sleep$Id <- as.character(daily_sleep$Id)

activities$A_Date <- as.Date(activities$A_Date)
weight$A_Date<- as.Date(weight$A_Date)
daily_sleep$A_Date <- as.Date(daily_sleep$A_Date)

To ensure a productive analysis, we will retrive the actual week day from the date column.

activities <- activities%>%
  mutate(weekday = weekdays(A_Date))%>%
drop_na(A_Date)

Notorious merging

(The code: {merged1 <- merge(activities, weight, by = c(‘Id’, ‘A_Date’), all.x = TRUE)%>% mergeddate <- merge(merged1, daily_sleep, by = c(‘Id’, ‘A_Date’), all.x = TRUE)%>% head(mergeddate) })

merged1 <- merge(activities, weight, by = c('Id', 'A_Date'), all.x = TRUE)
mergeddate <- merge(merged1, daily_sleep, by = c('Id', 'A_Date'), all.x = TRUE)
head(mergeddate)

In order to better visualize the data I will group the user into four categories based on for which of their activity types they have more minutes, this will be very useful to quickly see patterns and visualize them:

mergeddate1 <- mergeddate %>%
  ungroup() %>%  # Ensure data is ungrouped
  mutate(
    user_type = factor(
      case_when(
        SedentaryMinutes > mean(SedentaryMinutes, na.rm = TRUE) &
          LightlyActiveMinutes < mean(LightlyActiveMinutes, na.rm = TRUE) &
          FairlyActiveMinutes < mean(FairlyActiveMinutes, na.rm = TRUE) &
          VeryActiveMinutes < mean(VeryActiveMinutes, na.rm = TRUE) ~ "Sedentary",
        
        LightlyActiveMinutes > mean(LightlyActiveMinutes, na.rm = TRUE) &
          FairlyActiveMinutes <= mean(FairlyActiveMinutes, na.rm = TRUE) &
          VeryActiveMinutes <= mean(VeryActiveMinutes, na.rm = TRUE) ~ "Lightly Active",
        
        FairlyActiveMinutes > mean(FairlyActiveMinutes, na.rm = TRUE) &
          VeryActiveMinutes <= mean(VeryActiveMinutes, na.rm = TRUE) ~ "Fairly Active",
        
        VeryActiveMinutes > quantile(VeryActiveMinutes, 0.75, na.rm = TRUE) ~ "Very Active",
        
        TRUE ~ NA_character_
      ),
      levels = c("Sedentary", "Lightly Active", "Fairly Active", "Very Active")
    )
  ) %>%
  drop_na(user_type)  # Remove rows with NA in `user_type`

Alright! Let’s visualize.

V1: Showing Participation per day.

mergeddate2 <- mergeddate %>%
  mutate(weekday = factor(weekday, levels = c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")))
ggplot(data = mergeddate2, aes(x = weekday, y = Id, fill = weekday)) +
  geom_bar(stat = "identity") +
  labs(title = "Daily Participation Volume", x = "Weekday", y = "Participation Count") +
  scale_fill_manual(values = c("Sunday" = "red", 
                               "Monday" = "blue", 
                               "Tuesday" = "green", 
                               "Wednesday" = "yellow", 
                               "Thursday" = "orange", 
                               "Friday" = "purple", 
                               "Saturday" = "pink"))

V2: Impact of Active Steps on Calorie burnt

ggplot(data = mergeddate2, aes(x = Calories, y = TotalSteps)) + 
  geom_point(color = 'darkblue') +
  geom_smooth(method = "loess", color = 'red') +  # Add smoothing line
  labs(
    title = "Calories vs. Total Steps",
    x = "Calories",
    y = "Total Steps"
  ) +
  theme_minimal()

V3: Now, let’s visualize the relationship between each active user-Type and the calorie burnt

ggplot(data = mergeddate1, aes(x = user_type, y = Calories, fill = user_type)) +
geom_boxplot(outlier.color = "red", outlier.shape = 16, outlier.size = 2) +
geom_jitter(width = 0.2, size = 2, alpha = 0.5, color = "black") +
labs(
    title = "Calories Burned by User Type",
    x = "User Type",
    y = "Calories Burned") +
theme_minimal() +
theme(
legend.position = "none",                # Removes the legend
text = element_text(size = 16),          # Adjusts text size globally
plot.title = element_text(hjust = 0.5),  # Centers the plot title
axis.text.x = element_text(angle = 45, hjust = 1)  # Angled x-axis labels for readability
)

V4: Visualizing Average BMI for each User Type

WHO’s recomendation for healthy BMI is between 18.5 and 24.9. Let’s view the relationship between the customer’s BMI and User Type. We anticipate that the report will open up a whole new market penetration opportunities.

mergeddate_summary <- mergeddate1 %>%
  group_by(user_type) %>%
  summarize(mean_BMI = mean(BMI, na.rm = TRUE))  # Handles NA values gracefully

ggplot(data = mergeddate_summary, aes(x = user_type, y = mean_BMI, fill = user_type)) +
geom_bar(stat = "identity") +
labs(title = "BMI Trend by User Type", 
       x = "User Type", 
       y = "Average BMI") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))

INFERENCES

  1. Focus on Daily Participation User participation is highest on Sunday, followed by Monday and Wednesday, while activity on Tuesday, Friday, and Saturday is relatively lower.

Action Plan Implement gamified incentives to encourage increased participation on low-activity days. For example, award extra points for participation on Tuesday, Friday, and Saturday to motivate users and balance engagement throughout the week.

Outcomes: Increased Participation on Low-Volume Days Enhanced User Engagement Higher Retention and Loyalty

  1. Focus on Daily Steps and Calories Burned A linear relationship exists between the total steps taken and calories burned. Current data indicates that users typically take 400–600 steps daily, resulting in 1,500–2,300 calories burned.

Action Plan: Bellabeta Fitness should launch the “Millenia Challenge” across its wearable fitness products. This initiative will motivate users to exceed 1,000 daily steps through gamified features and incentives, such as rewards, badges, or leaderboards.

Outcome: By surpassing 1,000 daily steps, users can burn over 2,500 calories, promoting healthier lifestyles while enhancing their overall fitness experience. Additionally, this approach increases user engagement and reinforces their connection to Bellabeta’s ecosystem.

  1. Focus on the Trend of Calories Burned Across Each User Type There is a clear linear relationship between User Type and Calories Burned, ranging from Sedentary to Very Active users. This insight can inform a targeted marketing strategy.

Action Plan Develop challenges and competitions designed to motivate sedentary users to take more daily steps, leading to increased calorie burn and fostering healthier habits. Leverage the same gamified approach to showcase the benefits of increased activity, using targeted advertising campaigns to appeal to potential customers.

Outcome Increased sales (New customer onboarding). Increased activities among the Sedantary Users.

  1. Focus on BMI trends across User Type

Sedentary users are a low-hanging fruit for engagement. However, limited BMI data hinders personalized strategies.

Action Plan:

Collect BMI via onboarding, surveys, or wearable partnerships.

Use proxy metrics like step counts temporarily.

Create simple, gamified programs to boost activity.

Track KPIs and adjust strategies quarterly.

Outcome:

Better health insights, stronger user engagement, and improved retention.