Data for Change

There have been numerous studies looking into the relationship between sleep, exercise, leisure, studying and Happiness. The results were often quite like how we expected, though there have been debates about the relationship between sleep and happiness. However, I was wondering if we could put it in the perspective of how we spend our time in general and seeing whether a balance of time spent in different aspects of our lives would influence our happiness levels.
Rather than chasing after more sleep, or more exercise, how should we be spending our time across the board to increase our happiness?
As a university student in Singapore, I decided to do a simple survey of my peers.
Data description:
Number of responses=45
Variables, keeping in mind that I am asking university students:
- year of studies
- gender
- level of comfort around people (account for possible personality differences)
- satisfaction (a good measure for happiness as it tends to be stable)
- sleep hours (per day)
- study hours (per day)
- exercise hours (per week)
- leisure hours (per week)
Next, I’ll be using Python through Jupyter Notebook to do some data cleaning. Starting with importing of the necessary packages and looking at the data.
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import statsmodels.api as sm
import numpy as np
import math
#loading the data
data=pd.read_csv("Happiness and how we spend our time (Responses) - Form Responses 1.csv")
data.head()

Data cleaning:
1) Renaming the column header for simplicity
data.columns=['Year','Gender','Being around others','Happiness score','Sleep','Study','Exercise','Leisure']
2) Converting from categorical to numerical by:
- taking the mean of the range of values, with a constant interval between each option (Note: get respondents to enter integers instead next time).
- replacing ‘Male’ and ‘Female’ with 1 and 0 and ‘year 1’ to ‘year 5’ to just ‘1’ to ‘5’.
data=data.replace({'Year 5':5, 'Year 4':4,'Year 3':3,'Year 2':2,'Year 1':1,'Male':0,'Female':1,'0 to 1 hour':0.5,'0 to 2 hours':1,'1 to 2 hours':1.5,'3 to 4 hours':3.5,'4 to 5 hours':4.5,'5 to 6 hours':5.5,'7 to 8 hours':7.5,'0 to 4 hours':2,'5 to 9 hours':7,'9 to 10 hours':9.5,'10 to 14 hours':12,'15 to 19 hours':17,'20 to 24 hours':22,'25 to 29 hours':27,'9 or more hours a week':9.5,'More than 30 hours a week':32})
3) drop the ‘Timestamp’ column and dividing ‘exercise’ and ‘leisure’ values by 7 to get a daily value
data=data.drop('Timestamp',axis=1)
#make weekly hours to daily
data['Exercise']=data['Exercise']/7
data['Leisure']=data['Leisure']/7
data.head()
4) Converting sleep, study, exercise and leisure to percentages.
#get the hours variables
dv=data
dv=dv.drop(['Year','Gender','Being around others','Happiness score'],axis=1)
#sum of rows
sumv=dv.sum(axis=1)
#making it into percentages
dv['Sleep']=100*dv['Sleep']/sumv
dv['Study']=100*dv['Study']/sumv
dv['Exercise']=100*dv['Exercise']/sumv
dv['Leisure']=100*dv['Leisure']/sumv
#replacing the values
data['Sleep']=dv['Sleep']
data['Study']=dv['Study']
data['Exercise']=dv['Exercise']
data['Leisure']=dv['Leisure']
#looking at data
data.head()

Now that we have the data in the form that we’d like, we can start to create data visualizations. I’ve decided to focus on personality, % of hours (sleep, study, exercise and leisure) and the happiness score.
Analysis:
Personality and happiness:
The following is the correlation heat map for those who rated themselves as being less comfortable around others (‘Being around others'<=5).
#set size
plt.rcParams['figure.figsize'] = (8, 6)
#plot data desired
d = data.loc[lambda data: data['Being around others'] <= 5]
sns.heatmap(d.corr(), cmap = 'Blues', annot = True)
plt.show()

Mean for sleep=42.11%, mean for leisure=13.98%, mean happiness score=4.92. Notice that the correlation between happiness and sleep was the highest at 0.52, correlation between happiness and leisure was -0.37.
Compare this to those who rated themselves as being more comfortable around others (‘Being around others’>5).

Mean for sleep=45.64%, mean for leisure=15.21%, mean happiness score=6.81. The correlation between happiness and sleep was the highest at 0.24, correlation between happiness and leisure was -0.0028.
Every other correlation was surprisingly negative! Although I expected sleep to have a high correlation with happiness as people may prefer to be alone, activities like leisure having a negative correlation with happiness is quite unexpected. This seems to suggest that for people who are less comfortable around others are more likely to be influenced by the amount of time they spend sleeping, while the other factors do not seem to be an important factor that influences their happiness. At the same time, spending more time on leisure appears to have a negative correlation with their happiness, though this may not be as prominent in people who rated themselves as being more comfortable with others.
If we take a look at the mean value for exercise and leisure, it appears that more time spent on sleeping might be beneficial to those who are less comfortable around others. Perhaps a further dissection and examination on personality might grant further insights into what makes us happy. Nonetheless, it appears that perhaps happiness and personality seems to have some correlation.
Sleep is a more important factor in those who are less comfortable around others compared to their counterparts.
Balanced hours and happiness:
Next, let’s look at how spending different proportion of our time correlates with happiness scores. Balanced: all components <50%

Happiness score: mean=6.80, sd=2.00. Correlation between being around others and happiness =0.44.
Unbalanced: any component ≥ 50%

Happiness score: mean=5.60, sd=2.80. Correlation between sleep and happiness=0.7, correlation between study and happiness=-0.4. *those who entered the unbalanced group were due to study or sleep ≥ 50%
Looking at the mean, it appears that ensuring that we have a balanced distribution of hours across the 4 factors correlates with higher levels of happiness. However, let’s take a look at the regression line for happiness and sleep for unbalanced hours with correlation of 0.7!
#nbal is the data with only rows that are not balanced
x = nbal['Sleep']
y = nbal['Happiness score']
plt.plot(x, y, 'o')
m, b = np.polyfit(x, y, 1)
plt.plot(x, m*x + b)

If i look at only data of those with ‘Sleep’ ≥ 50% of hours: Happiness mean=7.17, sd=1.22 Maybe we all just need a higher % of time for sleep. When I relaxed the criteria to ≥ 40%, the mean happiness score fell to 6.49. Furthermore, it appears that it’s spending >50% of our time on studying that brought down the mean (mean of those with ≥ 50% studying hours = 3.4285, sd=2.88).
Those with ≥50% of hours spent on sleep across ‘Sleep’, ‘Study’, ‘Exercise’, ‘Leisure’ had a happiness mean score of 7.17.
Conclusion:
If you read all of the above, thank you so much because I spent a lot of time trying to code and getting the values I needed for analysis! Otherwise, here’s a quick summary: Question that I wanted to answer: Does the proportion of time spent on different activities influence our happiness levels?
Yes, it does! Students with a more balanced proportion of hours spent across activities appear to have a positive correlation with happiness levels.
Findings:
1) Positive correlation between sleep and happiness throughout 2) Personality has an influence on the types of activities that correlates with our happiness (e.g sleep and leisure) 3) Those who have a more balanced spread of hours seem to be happier than those who had unbalanced hours 4) Those with ≥50% of their time, across the variables, spent on sleeping had higher mean score for happiness 5) Those with ≥50% of their time, across the variables, spent on studying had lower mean score for happiness.
Rather than chasing after more sleep, or more exercise, how should we be spending our time across the board to increase our happiness?
- Spend more % of our time sleeping. Sounds simple yet difficult in a competitive/work-centric environment.
- Alternatively, try to balance the number of hours we spent in different activities (do not spend too much time on a single activity!)
Nonetheless, glad to have learnt a lot of python and data visualization from this mini-project and trying to milk all the information that it’s trying to tell me! Do let me know if there are other areas I could look at or your thoughts on the results! Would try to get a larger data set the next time.