# read data
happiness <- read.csv("happiness.csv")
# check structure
str(happiness)
## 'data.frame': 156 obs. of 8 variables:
## $ country : chr "Finland" "Denmark" "Norway" "Iceland" ...
## $ happiness : num 7.77 7.6 7.55 7.49 7.49 ...
## $ economic : num 1.34 1.38 1.49 1.38 1.4 ...
## $ social : num 1.59 1.57 1.58 1.62 1.52 ...
## $ health : num 0.986 0.996 1.028 1.026 0.999 ...
## $ freedom : num 0.596 0.592 0.603 0.591 0.557 0.572 0.574 0.585 0.584 0.532 ...
## $ generosity: num 0.153 0.252 0.271 0.354 0.322 0.263 0.267 0.33 0.285 0.244 ...
## $ corruption: num 0.393 0.41 0.341 0.118 0.298 0.343 0.373 0.38 0.308 0.226 ...
num_data <- happiness[, -which(names(happiness) == "country")]
# mean
means <- sapply(num_data, mean)
# standard deviation
sds <- sapply(num_data, sd)
# range
ranges <- sapply(num_data, function(x) max(x) - min(x))
# combine into a table
summary_table <- data.frame(
Mean = means,
SD = sds,
Range = ranges
)
summary_table
## Mean SD Range
## happiness 5.4070962 1.11311987 4.916
## economic 0.9051474 0.39838946 1.684
## social 1.2088141 0.29919140 1.624
## health 0.7252436 0.24212400 1.141
## freedom 0.3925705 0.14328947 0.631
## generosity 0.1848462 0.09525444 0.566
## corruption 0.1106026 0.09453784 0.453
The mean shows the average level of each variable across countries. The standard deviation describes how much countries differ from the average. A larger standard deviation indicates greater inequality across countries. The range shows the difference between the highest and lowest observed values, which reflects the overall spread of the data.
hist(happiness$happiness,
main = "Histogram of Happiness Score",
xlab = "Happiness Score",
col = "pink",
breaks = 15)
The histogram shows the distribution of happiness scores across countries. Most countries cluster around the middle values, while fewer countries have very low or very high happiness scores. This suggests that extreme happiness levels are less common globally.
cor_matrix <- cor(num_data)
cor_with_happiness <- cor_matrix["happiness", ]
cor_with_happiness
## happiness economic social health freedom generosity corruption
## 1.00000000 0.79388287 0.77705779 0.77988315 0.56674183 0.07582369 0.38561307
cor_with_happiness[cor_with_happiness > 0.6]
## happiness economic social health
## 1.0000000 0.7938829 0.7770578 0.7798831
#Conceptual interpretation Economic conditions, social support, and health show strong positive correlations with happiness. This suggests that countries with higher income levels, stronger socialcial networks, and longer life expectancy tend to report higher happiness. Other variables such as generosity show weaker associations.