Bellabeat is a high-tech manufacturer of health-focused products for women, founded by Sršen and Sando Mur in 2013. This company has experienced rapid growth since its inception, with multiple products available through online retailers and Bellabeat’s own e-commerce channel. Bellabeat invests heavily in digital marketing, with a strong focus on Google Search, Facebook and Instagram pages, Twitter engagement, and video ads on Youtube and display ads on the Google Display Network. The company is in need of a new marketing plan and the best way to achieve this, is to conduct it according to customers prefrences and needs. By analyzing non-bellabeat smart device usage data, we will gain insights about how customers are currently using these kind of products and identify trends that can inform marketing strategy.
First, we demonstrate what we are looking for in this process, and also we establish our business plan and metrics. By doing so, the analysis will be more straightforward.
Analyse the data from non-bellabeat smart devices to gain insights about the trends in activities and sleep patterns and apply it for a new marketing strategy.
What are the trends in people’s activity?
Which kind of activity is better for burning more calories?
which one is more important, running distance or time?
How can we conduct a new marketing startegy with this data?
Urška Sršen- Cofounder & Chief Creative Officer, has a background in artistry which aids her in creating informative and elegantly designed technology to improve the lives of women.
Sando Mur- Cofounder & Mathematician; an important figure of the Bellabeat executive team.
Bellabeat Marketing Analytics Team: A team of data analysts responsible for collecting, analyzing, and reporting data that helps guide Bellabeat’s marketing strategy.
The Fitbit Fitness Tracker Data dataset was used for this case study. Möbius uploaded the dataset on Kaggle where it was then downloaded.
We used these three packages for the study. First we load them.
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## âś” dplyr 1.1.4 âś” readr 2.1.4
## âś” forcats 1.0.0 âś” stringr 1.5.1
## âś” ggplot2 3.4.4 âś” tibble 3.2.1
## âś” lubridate 1.9.3 âś” 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(janitor)
##
## Attaching package: 'janitor'
##
## The following objects are masked from 'package:stats':
##
## chisq.test, fisher.test
library(ggpubr)
Next, we import our datasets.
daily_activity <- read.csv("daily_activity.csv")
daily_sleep <- read.csv("sleep_day.csv")
hourly_activity <- read.csv("hourly_activity.csv")
hourly_intensity <- read.csv("hourly_intensity.csv")
hourly_steps <- read.csv("hourly_steps.csv")
Finally, we can take a look at each dataset to find out about them. We chose two daily and three hourly tracked datasets. “daily_activity” dataframe is more comprehensive and contain data about differnt types of activity, travelled distance, number of steps and also burned calories.
head(daily_activity)
## Id ActivityDate TotalSteps TotalDistance TrackerDistance
## 1 1503960366 4/12/2016 13162 8.50 8.50
## 2 1503960366 4/13/2016 10735 6.97 6.97
## 3 1503960366 4/14/2016 10460 6.74 6.74
## 4 1503960366 4/15/2016 9762 6.28 6.28
## 5 1503960366 4/16/2016 12669 8.16 8.16
## 6 1503960366 4/17/2016 9705 6.48 6.48
## LoggedActivitiesDistance VeryActiveDistance ModeratelyActiveDistance
## 1 0 1.88 0.55
## 2 0 1.57 0.69
## 3 0 2.44 0.40
## 4 0 2.14 1.26
## 5 0 2.71 0.41
## 6 0 3.19 0.78
## LightActiveDistance SedentaryActiveDistance VeryActiveMinutes
## 1 6.06 0 25
## 2 4.71 0 21
## 3 3.91 0 30
## 4 2.83 0 29
## 5 5.04 0 36
## 6 2.51 0 38
## FairlyActiveMinutes LightlyActiveMinutes SedentaryMinutes Calories
## 1 13 328 728 1985
## 2 19 217 776 1797
## 3 11 181 1218 1776
## 4 34 209 726 1745
## 5 10 221 773 1863
## 6 20 164 539 1728
head(daily_sleep)
## Id SleepDay TotalSleepRecords TotalMinutesAsleep
## 1 1503960366 4/12/2016 12:00:00 AM 1 327
## 2 1503960366 4/13/2016 12:00:00 AM 2 384
## 3 1503960366 4/15/2016 12:00:00 AM 1 412
## 4 1503960366 4/16/2016 12:00:00 AM 2 340
## 5 1503960366 4/17/2016 12:00:00 AM 1 700
## 6 1503960366 4/19/2016 12:00:00 AM 1 304
## TotalTimeInBed
## 1 346
## 2 407
## 3 442
## 4 367
## 5 712
## 6 320
head(hourly_activity)
## Id ActivityHour Calories
## 1 1503960366 4/12/2016 12:00:00 AM 81
## 2 1503960366 4/12/2016 1:00:00 AM 61
## 3 1503960366 4/12/2016 2:00:00 AM 59
## 4 1503960366 4/12/2016 3:00:00 AM 47
## 5 1503960366 4/12/2016 4:00:00 AM 48
## 6 1503960366 4/12/2016 5:00:00 AM 48
head(hourly_intensity)
## Id ActivityHour TotalIntensity AverageIntensity
## 1 1503960366 4/12/2016 12:00:00 AM 20 0.333333
## 2 1503960366 4/12/2016 1:00:00 AM 8 0.133333
## 3 1503960366 4/12/2016 2:00:00 AM 7 0.116667
## 4 1503960366 4/12/2016 3:00:00 AM 0 0.000000
## 5 1503960366 4/12/2016 4:00:00 AM 0 0.000000
## 6 1503960366 4/12/2016 5:00:00 AM 0 0.000000
head(hourly_steps)
## Id ActivityHour StepTotal
## 1 1503960366 4/12/2016 12:00:00 AM 373
## 2 1503960366 4/12/2016 1:00:00 AM 160
## 3 1503960366 4/12/2016 2:00:00 AM 151
## 4 1503960366 4/12/2016 3:00:00 AM 0
## 5 1503960366 4/12/2016 4:00:00 AM 0
## 6 1503960366 4/12/2016 5:00:00 AM 0
In this part of data analysis, we need to clean the data to be sure about the analysis results.
By running these lines, we find about duplicate entities in the dataframes.
sum(duplicated(daily_activity))
## [1] 0
sum(duplicated(daily_sleep))
## [1] 3
sum(duplicated(hourly_activity))
## [1] 0
sum(duplicated(hourly_intensity))
## [1] 0
sum(duplicated(hourly_steps))
## [1] 0
As you can see, the “daily_sleep” dataframe has 3 duplicates, which we’ll remove it with the next line of code.
daily_sleep <- distinct(daily_sleep)
sum(duplicated(daily_sleep))
## [1] 0
There are no more duplicates in this dataframe.
Same as duplicates, the N/A values should be replaced with the correct value if present.
sum(is.na(daily_activity))
## [1] 0
sum(is.na(daily_sleep))
## [1] 0
sum(is.na(hourly_activity))
## [1] 0
sum(is.na(hourly_intensity))
## [1] 0
sum(is.na(hourly_steps))
## [1] 0
Fortunately, none was found.
In this part, we do the following to clean the data:
clean_daily_act <- daily_activity %>%
select (-c(TrackerDistance, LoggedActivitiesDistance,
SedentaryActiveDistance)) %>%
clean_names() %>%
rename(date = activity_date, total_dist = total_distance,
vig_dist = very_active_distance, mod_dist = moderately_active_distance,
light_dist = light_active_distance, vig_min= very_active_minutes,
mod_min = fairly_active_minutes, light_min = lightly_active_minutes,
sed_min = sedentary_minutes) %>%
mutate(date = mdy(date), total_min = vig_min + mod_min + light_min)
As shown, the mentioned formatting was done on the first dataframe. We also do this for the rest of them.
clean_sleep <- daily_sleep %>%
mutate(time_to_sleep = TotalTimeInBed - TotalMinutesAsleep) %>%
select(-c(TotalSleepRecords, TotalTimeInBed)) %>%
clean_names() %>%
rename(date = sleep_day, asleep_min = total_minutes_asleep) %>%
mutate(date = as_date(mdy_hms(date)))
clean_hourly_act <- hourly_activity %>%
clean_names() %>%
rename(hour = activity_hour) %>%
mutate(hour = mdy_hms(hour))
clean_hourly_int <- hourly_intensity %>%
clean_names() %>%
rename(hour = activity_hour) %>%
mutate(hour = mdy_hms(hour))
clean_hourly_steps <- hourly_steps %>%
clean_names() %>%
rename(hour = activity_hour) %>%
mutate(hour = mdy_hms(hour))
First, find the number of observations in each dataframe.
n_distinct(clean_daily_act)
## [1] 940
n_distinct(clean_sleep)
## [1] 410
n_distinct(clean_hourly_act)
## [1] 22099
n_distinct(clean_hourly_int)
## [1] 22099
n_distinct(clean_hourly_steps)
## [1] 22099
As mentioned before, there are two daily dataframes and three hourly dataframes. For ease of analysis, merge the dataframes by attributes which are consistent in each of them. In case of hourly data, this process will be done in two steps.
clean_daily_data <- merge(clean_daily_act, clean_sleep, by = c("id", "date"))
hourly <- merge(clean_hourly_act, clean_hourly_int, by = c("id", "hour"))
clean_hourly_data <- merge(hourly, clean_hourly_steps, by = c("id", "hour"))
Also, we decided to make long versions of daily data. These new dataframes are used later for visualizing the data.
longer_dist <- clean_daily_data %>%
select(id, date, vig_dist, mod_dist, light_dist, calories) %>%
pivot_longer(vig_dist:light_dist, names_to = "types_dist",
values_to = "distances") %>%
mutate(types_dist = str_replace_all(types_dist, "vig_dist", "Vigorous")) %>%
mutate(types_dist = str_replace_all(types_dist, "mod_dist", "Moderate")) %>%
mutate(types_dist = str_replace_all(types_dist, "light_dist", "Light"))
head(longer_dist)
## # A tibble: 6 Ă— 5
## id date calories types_dist distances
## <dbl> <date> <int> <chr> <dbl>
## 1 1503960366 2016-04-12 1985 Vigorous 1.88
## 2 1503960366 2016-04-12 1985 Moderate 0.550
## 3 1503960366 2016-04-12 1985 Light 6.06
## 4 1503960366 2016-04-13 1797 Vigorous 1.57
## 5 1503960366 2016-04-13 1797 Moderate 0.690
## 6 1503960366 2016-04-13 1797 Light 4.71
longer_min <- clean_daily_data %>%
select(id, date, vig_min, mod_min, light_min, sed_min, asleep_min, calories) %>%
pivot_longer(vig_min:sed_min, names_to = "types_min",
values_to = "minutes") %>%
mutate(types_min = str_replace_all(types_min, "vig_min", "Vigorous")) %>%
mutate(types_min = str_replace_all(types_min, "mod_min", "Moderate")) %>%
mutate(types_min = str_replace_all(types_min, "light_min", "Light")) %>%
mutate(types_min = str_replace_all(types_min, "sed_min", "Sedentary"))
head(longer_min)
## # A tibble: 6 Ă— 6
## id date asleep_min calories types_min minutes
## <dbl> <date> <int> <int> <chr> <int>
## 1 1503960366 2016-04-12 327 1985 Vigorous 25
## 2 1503960366 2016-04-12 327 1985 Moderate 13
## 3 1503960366 2016-04-12 327 1985 Light 328
## 4 1503960366 2016-04-12 327 1985 Sedentary 728
## 5 1503960366 2016-04-13 384 1797 Vigorous 21
## 6 1503960366 2016-04-13 384 1797 Moderate 19
Next, a descriptive analysis was done on the daily data which includes minimum, maximum, mean, median, and quartiles of the selected attributes.
clean_daily_data %>%
select(total_steps, total_dist, total_min, vig_dist, mod_dist, light_dist,
vig_min, mod_min, light_min, sed_min, calories, asleep_min,
time_to_sleep) %>%
summary()
## total_steps total_dist total_min vig_dist
## Min. : 17 Min. : 0.010 Min. : 2.0 Min. : 0.000
## 1st Qu.: 5189 1st Qu.: 3.592 1st Qu.:206.5 1st Qu.: 0.000
## Median : 8913 Median : 6.270 Median :263.5 Median : 0.570
## Mean : 8515 Mean : 6.012 Mean :259.5 Mean : 1.446
## 3rd Qu.:11370 3rd Qu.: 8.005 3rd Qu.:315.5 3rd Qu.: 2.360
## Max. :22770 Max. :17.540 Max. :540.0 Max. :12.540
## mod_dist light_dist vig_min mod_min
## Min. :0.0000 Min. :0.010 Min. : 0.00 Min. : 0.00
## 1st Qu.:0.0000 1st Qu.:2.540 1st Qu.: 0.00 1st Qu.: 0.00
## Median :0.4200 Median :3.665 Median : 9.00 Median : 11.00
## Mean :0.7439 Mean :3.791 Mean : 25.05 Mean : 17.92
## 3rd Qu.:1.0375 3rd Qu.:4.918 3rd Qu.: 38.00 3rd Qu.: 26.75
## Max. :6.4800 Max. :9.480 Max. :210.00 Max. :143.00
## light_min sed_min calories asleep_min
## Min. : 2.0 Min. : 0.0 Min. : 257 Min. : 58.0
## 1st Qu.:158.0 1st Qu.: 631.2 1st Qu.:1841 1st Qu.:361.0
## Median :208.0 Median : 717.0 Median :2207 Median :432.5
## Mean :216.5 Mean : 712.1 Mean :2389 Mean :419.2
## 3rd Qu.:263.0 3rd Qu.: 782.8 3rd Qu.:2920 3rd Qu.:490.0
## Max. :518.0 Max. :1265.0 Max. :4900 Max. :796.0
## time_to_sleep
## Min. : 0.00
## 1st Qu.: 17.00
## Median : 25.50
## Mean : 39.31
## 3rd Qu.: 40.00
## Max. :371.00
The same process was done also on hourly data. However, before summarizing this dataframe, the datetime variable has been separated into two. By doing so, “00:00:00” was recognized as N/A, which we changed it to the correct value again.
clean_hourly_data <- clean_hourly_data %>%
separate(hour, into = c("date", "hour"), sep = " ") %>%
mutate(hour = replace_na(hour, "00:00:00"))
Now, we group them by hour and do a summary.
summarized_hourly_date <- clean_hourly_data %>%
group_by(hour) %>%
summarize(avg_cal=mean(calories),
avg_intensity = mean(total_intensity),
avg_steps = mean(step_total))
head(summarized_hourly_date)
## # A tibble: 6 Ă— 4
## hour avg_cal avg_intensity avg_steps
## <chr> <dbl> <dbl> <dbl>
## 1 00:00:00 71.8 2.13 42.2
## 2 01:00:00 70.2 1.42 23.1
## 3 02:00:00 69.2 1.04 17.1
## 4 03:00:00 67.5 0.444 6.43
## 5 04:00:00 68.3 0.633 12.7
## 6 05:00:00 81.7 4.95 43.9
Testing the association between these pair of continuous variables was done with Pearson R correlation coefficient. P-values of less than 0.001 were considered significant. In case of significant association, R coefficient comes to help for determining how strong this association is. It can range from -1 to 1, which negative values show negative association between the variables. The strength of association was indicated using the following guideline:
As an example, we did the correlation test for three of the main variables against burnt calories. Later on, these tests will be provided with a their respective plot.
cor.test(clean_daily_data$total_dist, clean_daily_data$calories,
method = "pearson")
##
## Pearson's product-moment correlation
##
## data: clean_daily_data$total_dist and clean_daily_data$calories
## t = 12.336, df = 408, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.4469291 0.5883638
## sample estimates:
## cor
## 0.5212162
cor.test(clean_daily_data$total_min, clean_daily_data$calories,
method = "pearson")
##
## Pearson's product-moment correlation
##
## data: clean_daily_data$total_min and clean_daily_data$calories
## t = 8.5546, df = 408, p-value = 2.417e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.3046418 0.4691127
## sample estimates:
## cor
## 0.3899832
cor.test(clean_daily_data$total_steps, clean_daily_data$calories,
method = "pearson")
##
## Pearson's product-moment correlation
##
## data: clean_daily_data$total_steps and clean_daily_data$calories
## t = 8.9816, df = 408, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
## 0.3221289 0.4840991
## sample estimates:
## cor
## 0.4063007
By testing these variables against burnt calories, we can conclude that there is a significant correlation with all three. However, the correlation between burnt calories and the distance in an activity is bigger in size.
Linear regression is a regression model that uses a straight line to describe the relationship between variables. Linear regression can be used to predict the value of a variable based on another one.
If the p-value shows significant correlation, we can make a linear regression model that predicts the dependent variable.
summary(lm(total_dist ~ calories , data = clean_daily_data))
##
## Call:
## lm(formula = total_dist ~ calories, data = clean_daily_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -5.9766 -2.0377 -0.0575 1.7352 8.7412
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 1.0142759 0.4250321 2.386 0.0175 *
## calories 0.0020919 0.0001696 12.336 <2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 2.601 on 408 degrees of freedom
## Multiple R-squared: 0.2717, Adjusted R-squared: 0.2699
## F-statistic: 152.2 on 1 and 408 DF, p-value: < 2.2e-16
summary(lm(total_min ~ calories , data = clean_daily_data))
##
## Call:
## lm(formula = total_min ~ calories, data = clean_daily_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -216.218 -51.912 -4.233 61.107 259.695
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 146.27149 13.88675 10.533 < 2e-16 ***
## calories 0.04739 0.00554 8.555 2.42e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 84.98 on 408 degrees of freedom
## Multiple R-squared: 0.1521, Adjusted R-squared: 0.15
## F-statistic: 73.18 on 1 and 408 DF, p-value: 2.417e-16
summary(lm(total_steps ~ calories , data = clean_daily_data))
##
## Call:
## lm(formula = total_steps ~ calories, data = clean_daily_data)
##
## Residuals:
## Min 1Q Median 3Q Max
## -8007 -2995 -133 2662 11250
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3193.604 621.529 5.138 4.31e-07 ***
## calories 2.227 0.248 8.982 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 3803 on 408 degrees of freedom
## Multiple R-squared: 0.1651, Adjusted R-squared: 0.163
## F-statistic: 80.67 on 1 and 408 DF, p-value: < 2.2e-16
The most practical part for modeling, is the estimates in the coefficient section. If “a” is the estimated effect of the variable and “b” is the intercept, the model would be y = ax + b.
Later, you can see linear regression models on the plots. Thus, we intentionally avoid doing the previous code chunk between all of our variables.
Here are some conclusion from this study:
Vigorous activities have the most impact on burnt calories.
Extending the duration od vigorous activities is the best method for more calorie count.
Walking and all of the light activities that promote movement are beneficial.
Being stationary reduces daily sleep but being more active doesn’t necessarily increase it.
Smart device users tend to be more active in 6 p.m
Collect data from our own users, with more participants and include demographics for a better analysis.
A device could be designed to measure the sleep quality of users. It can also measure the waves in their sleep
There are lots of studies now on the effect of temperature on sleep. Users may like the new thermometer feature and its uses.
Based on what was found, we can conduct a activity program for users to fully inhance their health and calorie count.