# install.packages("foreign")
library(foreign)
# install.packages("ltm")
library(ltm)
library(knitr)
# Set default behaviour for R chunks:
# echo = TRUE >> show R output in final document
# message = FALSE >> do not show R messages in final document
# warning = FALSE >> do not show R warnings in final document
knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)

setwd("/Users/sonjakoncar/Desktop/MCI/SEM1/Quantitative/R")
df = read.spss("ESS11.sav", to.data.frame = T)

Introduction

This analysis uses data from the European Social Survey (ESS), specifically focusing on Hungary, to explore social determinants of depression. Depression is measured through eight self-reported indicators of emotional wellbeing over the past week. The study tests five hypotheses concerning the association between depression and various social factors: educational level, gender, self-rated health, internet usage frequency, and social activity. The aim is to identify patterns that may inform policy and intervention strategies.

# Filtering data set to only include responses from Hungary
df = df[df$cntry=="Hungary",]
nrow(df)
## [1] 2118

Methods

The dataset was filtered to include only Hungarian respondents (n = 2,118). Depression was operationalised as the average score across eight items indicating emotional states, including feeling depressed, restless sleep, happiness, and loneliness. Two items measuring positive emotions were reverse-coded.

# Converting responses to numbers
df$d20 = as.numeric(df$fltdpr)
df$d21 = as.numeric(df$flteeff)
df$d22 = as.numeric(df$slprl)
df$d23 = as.numeric(df$wrhpp)
df$d24 = as.numeric(df$fltlnl)
df$d25 = as.numeric(df$enjlf)
df$d26 = as.numeric(df$fltsd)
df$d27 = as.numeric(df$cldgng)

# Reversing scale of positive items
df$d23 = 5 - df$d23
df$d25 = 5 - df$d25

# Consistency check
cronbach.alpha(df[,c("d20","d21","d22","d23","d24","d25","d26","d27")], na.rm=T)
## 
## Cronbach's alpha for the 'df[, c("d20", "d21", "d22", "d23", "d24", "d25", "d26", "d27")]' data-set
## 
## Items: 8
## Sample units: 2118
## alpha: 0.845
# Computing average depression score
df$depression = rowSums(df[,c("d20","d21","d22","d23","d24","d25","d26","d27")]) / 8

# Descriptives
summary(df$depression)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   1.000   1.375   1.750   1.807   2.125   3.875      34
hist(df$depression, breaks=8)

Cronbach’s alpha 0.8446908 confirmed internal consistency of the scale.

Hypotheses

  1. Individuals with higher educational levels are associated with lower depression scores.
  2. Women are more likely to report higher depression scores compared to men.
  3. Individuals with better self-reported health levels are likely to report lower levels of depression.
  4. Excessive internet use increases levels of depression.
  5. Individuals who frequently socialize with friends, relatives, or colleagues are less likely to experience symptoms of depression compared to those who socialize less frequently.

Hypothesis 1

Individuals with higher educational levels are associated with lower depression scores.

# Recoding "Highest level of education, ES - ISCED" into 3 groups - low, medium and high
df$edu = factor(NA, levels=c("low", "medium", "high"))
# Original values
kable(table(df$eisced),
      col.names = c("Education","n"),
      caption = "Frequency of Answers by Education"
      )
Frequency of Answers by Education
Education n
Not possible to harmonise into ES-ISCED 0
ES-ISCED I , less than lower secondary 27
ES-ISCED II, lower secondary 377
ES-ISCED IIIb, lower tier upper secondary 623
ES-ISCED IIIa, upper tier upper secondary 679
ES-ISCED IV, advanced vocational, sub-degree 141
ES-ISCED V1, lower tertiary education, BA level 195
ES-ISCED V2, higher tertiary education, >= MA level 73
Other 0
df$edu[df$eisced == "ES-ISCED I , less than lower secondary"] = "low"
df$edu[df$eisced == "ES-ISCED II, lower secondary"] = "low"
df$edu[df$eisced == "ES-ISCED IIIb, lower tier upper secondary"] = "medium"
df$edu[df$eisced == "ES-ISCED IIIa, upper tier upper secondary"] = "medium"
df$edu[df$eisced == "ES-ISCED IV, advanced vocational, sub-degree"] = "high"
df$edu[df$eisced == "ES-ISCED V1, lower tertiary education, BA level"] = "high"
df$edu[df$eisced == "ES-ISCED V2, higher tertiary education, >= MA level"] = "high"

# As numeric
df$edunum = as.numeric(df$edu)
# Check
kable(table(df$edunum),
      col.names = c("Educational Level by Low (1), Medium (2), High (3)","n"),
      caption = "Frequency of Answers by Educational Level"
      )
Frequency of Answers by Educational Level
Educational Level by Low (1), Medium (2), High (3) n
1 404
2 1302
3 409
# Anova to check for differences in depression levels by educational category
anova_model= aov(depression ~ edu, data = df)
summary(anova_model)
##               Df Sum Sq Mean Sq F value Pr(>F)    
## edu            2   38.2   19.09   73.41 <2e-16 ***
## Residuals   2078  540.3    0.26                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 37 observations deleted due to missingness
# Result shows high significance
# Group means to assess hypothesis confirmation
means_df = data.frame(
by(df$depression, df$edu, mean, na.rm=T)
)
kable(means_df,
      col.names = c("Educational Level","Average Depression Score"),
      caption = "Average Depression Score by Educational Level"
      )
Average Depression Score by Educational Level
Educational Level Average Depression Score
low 2.062659
medium 1.781299
high 1.636816

Result

Respondents were recoded into three educational levels (low, medium, high). ANOVA revealed a statistically significant difference in depression scores across education levels (F(2,2078) = 73.41, p < 0.001). Post hoc mean comparisons showed that respondents with low education had the highest average depression score (M = 2.06), followed by medium (M = 1.78), and high education (M = 1.64).

This supports the hypothesis that higher education is associated with lower depression levels. Possible explanations include increased coping resources and better access to social capital among the more educated.

Hypothesis 2

Women are more likely to report higher depression scores compared to men.

# Computing and comparing mean depression score by gender
means_df = data.frame(
by(df$depression, df$gndr, mean, na.rm=T)
)
kable(means_df,
      col.names = c("Gender","Average Depression Score"),
      caption = "Average Depression Score by Gender"
      )
Average Depression Score by Gender
Gender Average Depression Score
Male 1.752427
Female 1.842361
# Result
# Females show higher depression rates than males, confirming the hypothesis.
kable(table(df$gndr),
      col.names = c("Gender","n"),
      caption = "Frequency of Answers by Gender"
      )
Frequency of Answers by Gender
Gender n
Male 835
Female 1283
# Creating binary variable for gender: 1 for female, 0 for male
df$female = NA
df$female[df$gndr=="Male"] = 0
df$female[df$gndr=="Female"] = 1

Result

Mean scores by gender indicated that women (M = 1.84) reported higher depression levels than men (M = 1.75). The gender variable was recoded into binary format for further analysis.

Findings confirm the hypothesis and are consistent with global trends indicating higher rates of depression in women, possibly due to biological, psychological, and social factors.

Hypothesis 3

Individuals who report ‘very good’ health will have significantly lower depression scores than those reporting ‘bad’ or ‘very bad’ health.

# Computing mean depression scores for each health level
means_df = data.frame(
by(df$depression, df$health, mean, na.rm=T)
)
kable(means_df,
      col.names = c("Health Level","Average Depression Score"),
      caption = "Average Depression Score by Subjective Health Level"
      )
Average Depression Score by Subjective Health Level
Health Level Average Depression Score
Very good 1.484863
Good 1.725671
Fair 2.009073
Bad 2.483275
Very bad 2.842105
# Check
kable(table(df$health),
      col.names = c("Health Level","n"),
      caption = "Frequency of Answers by Subjective Health Level"
      )
Frequency of Answers by Subjective Health Level
Health Level n
Very good 521
Good 905
Fair 505
Bad 145
Very bad 40

Result

Subjective health ratings showed a clear gradient: those reporting “very good” health had the lowest depression scores (M = 1.48), whereas those reporting “very bad” health had the highest (M = 2.84).

These results support the hypothesis and suggest a strong link between physical and mental wellbeing. Individuals with poor health may experience limitations that contribute to depressive symptoms.

Hypothesis 4

Excessive internet use increases levels of depression.

# Computing mean depression scores for different internet usage levels
means_df = data.frame(
by(df$depression, df$netusoft, mean, na.rm=T)
)
kable(means_df,
      col.names = c("Amount of Internet Use","Average Depression Score"),
      caption = "Average Depression Score by Amount of Internet Use"
      )
Average Depression Score by Amount of Internet Use
Amount of Internet Use Average Depression Score
Never 2.214467
Only occasionally 2.010246
A few times a week 1.855132
Most days 1.784722
Every day 1.662448
# Check
kable(table(df$netusoft),
      col.names = c("Amount of Internet Use","n"),
      caption = "Internet Use by Frquency"
      )
Internet Use by Frquency
Amount of Internet Use n
Never 406
Only occasionally 64
A few times a week 154
Most days 272
Every day 1219

Result

Contrary to the hypothesis, depression scores decreased with increasing internet use. Respondents who never used the internet had the highest scores (M = 2.21), while daily users reported the lowest (M = 1.66).

This finding contradicts the hypothesis. One explanation may be that internet use facilitates social connection, information access, or entertainment, which can serve as protective factors against depression.

Hypothesis 5

Individuals who frequently socialize with friends, relatives, or colleagues are less likely to experience symptoms of depression compared to those who socialize less frequently.

# Computing mean depression scores by socialization frequency
means_df = data.frame(
by(df$depression, df$sclmeet, mean, na.rm=T)
)
kable(means_df,
      col.names = c("Amount of Socialising","Average Depression Score"),
      caption = "Average Depression Score by Amount of Socialisation"
      )
Average Depression Score by Amount of Socialisation
Amount of Socialising Average Depression Score
Never 2.343954
Less than once a month 1.948585
Once a month 1.730592
Several times a month 1.649668
Once a week 1.713439
Several times a week 1.665559
Every day 1.892500
# Check
kable(table(df$sclmeet),
      col.names = c("Amount of Socialising","n"),
      caption = "Frequency of Answers by Amount of Socialisation"
      )
Frequency of Answers by Amount of Socialisation
Amount of Socialising n
Never 159
Less than once a month 538
Once a month 386
Several times a month 534
Once a week 256
Several times a week 192
Every day 50
# Testing for differences in depression scores by socialization frequency
anova_result = aov(depression ~ sclmeet, data = df)
summary(anova_result)
##               Df Sum Sq Mean Sq F value Pr(>F)    
## sclmeet        6   76.3  12.724   52.45 <2e-16 ***
## Residuals   2074  503.1   0.243                   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 37 observations deleted due to missingness

Result

ANOVA results showed significant differences in depression by socialising frequency (F(6,2074) = 52.45, p < 0.001). Depression was highest among those who never socialised (M = 2.34) and lowest for those socialising several times per month (M = 1.65).

The hypothesis is partially confirmed. While less socialising correlates with higher depression, daily socialisers reported slightly higher depression than those who socialise several times per week or per month, suggesting a non-linear relationship that may be influenced by quality rather than just quantity of interactions.

Conclusion

This study confirms that depression is significantly influenced by various social determinants in Hungary. Higher education, better self-rated health, and frequent social contact correlate with lower depression scores. Gender differences and internet usage patterns offer additional insights. These findings may inform targeted mental health interventions and social policies to mitigate depression risk in vulnerable groups.