# install.packages("foreign")
library(foreign)
# install.packages("ltm")
library(ltm)
library(knitr)
library(likert)
# 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/SEM2/Advanced Statistics")
df = read.spss("ESS11.sav", to.data.frame = T)
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
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.
vnames = c("fltdpr", "flteeff", "slprl","wrhpp", "fltlnl", "enjlf", "fltsd", "cldgng")
likert_df = df[,vnames]
likert(likert_df)
## Item None or almost none of the time Some of the time Most of the time
## 1 fltdpr 41.406988 47.02550 9.726157
## 2 flteeff 41.749409 43.45154 12.198582
## 3 slprl 28.936170 52.10402 16.643026
## 4 wrhpp 5.035629 21.09264 49.833729
## 5 fltlnl 61.410985 26.89394 8.143939
## 6 enjlf 7.531975 24.72762 46.707721
## 7 fltsd 47.328605 43.30969 8.179669
## 8 cldgng 46.764289 40.52905 10.769957
## All or almost all of the time
## 1 1.841360
## 2 2.600473
## 3 2.316785
## 4 24.038005
## 5 3.551136
## 6 21.032686
## 7 1.182033
## 8 1.936703
plot(likert(likert_df))
# Converting responses to numbers
likert_numeric_df = df[,vnames]
likert_numeric_df$d20 = as.numeric(likert_numeric_df[,vnames[1]])
likert_numeric_df$d21 = as.numeric(likert_numeric_df[,vnames[2]])
likert_numeric_df$d22 = as.numeric(likert_numeric_df[,vnames[3]])
likert_numeric_df$d23 = as.numeric(likert_numeric_df[,vnames[4]])
likert_numeric_df$d24 = as.numeric(likert_numeric_df[,vnames[5]])
likert_numeric_df$d25 = as.numeric(likert_numeric_df[,vnames[6]])
likert_numeric_df$d26 = as.numeric(likert_numeric_df[,vnames[7]])
likert_numeric_df$d27 = as.numeric(likert_numeric_df[,vnames[8]])
likert_means = lapply((likert_numeric_df[,vnames]), mean, na.rm=T)
# Reversing scale of positive items
likert_numeric_df$d23 = 5 - likert_numeric_df$d23
likert_numeric_df$d25 = 5 - likert_numeric_df$d25
# Consistency check
cronbach.alpha(likert_numeric_df[,c("d20","d21","d22","d23","d24","d25","d26","d27")], na.rm=T)
##
## Cronbach's alpha for the 'likert_numeric_df[, c("d20", "d21", "d22", "d23", "d24", "d25", ' ' "d26", "d27")]' data-set
##
## Items: 8
## Sample units: 2118
## alpha: 0.845
Cronbach’s alpha 0.8446908 confirmed internal consistency of the scale.
# Computing average depression score
likert_numeric_df$depression = rowSums(likert_numeric_df[,c("d20","d21","d22","d23","d24","d25","d26","d27")]) / 8
df$depression = likert_numeric_df$depression
# 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(likert_numeric_df$depression, breaks=8)
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"
)
| 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"
)
| 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(likert_numeric_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"
)
| Educational Level | Average Depression Score |
|---|---|
| low | 2.062659 |
| medium | 1.781299 |
| high | 1.636816 |
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.
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(likert_numeric_df$depression, df$gndr, mean, na.rm=T)
)
kable(means_df,
col.names = c("Gender","Average Depression Score"),
caption = "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"
)
| 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
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.
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(likert_numeric_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"
)
| 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"
)
| Health Level | n |
|---|---|
| Very good | 521 |
| Good | 905 |
| Fair | 505 |
| Bad | 145 |
| Very bad | 40 |
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.
Excessive internet use increases levels of depression.
# Computing mean depression scores for different internet usage levels
means_df = data.frame(
by(likert_numeric_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"
)
| 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"
)
| Amount of Internet Use | n |
|---|---|
| Never | 406 |
| Only occasionally | 64 |
| A few times a week | 154 |
| Most days | 272 |
| Every day | 1219 |
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.
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(likert_numeric_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"
)
| 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 |
# Number of respondents per socialisation frequency group
kable(table(df$sclmeet),
col.names = c("Amount of Socialising","n"),
caption = "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
# Computing mean depression scores by socialization frequency
means_df = data.frame(
by(likert_numeric_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"
)
| 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"
)
| 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
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).
df$gender = ifelse(df$gndr == "Female", 1, 0) # Binary: Female = 1
df$health_num = as.numeric(df$health)
df$internet_use = as.numeric(df$netusoft)
df$social_freq = as.numeric(df$sclmeet)
# Combined weight: design * post-stratification
df$reg_weight = df$dweight * df$pspwght
# Removing rows with missing predictors or weights
regression_df = df[complete.cases(df[, c(
"depression", "edunum", "gender", "health_num",
"internet_use", "social_freq", "reg_weight"
)]), ]
# Linear regression
regression_model = lm(
depression ~ edunum + gender + health_num + internet_use + social_freq,
data = regression_df,
weights = reg_weight
)
regression_summary = coef(summary(regression_model))
kable(regression_summary,
digits = 4,
col.names = c("Estimate", "Std. Error", "t value", "p value"),
caption = "Predictors of Depression"
)
| Estimate | Std. Error | t value | p value | |
|---|---|---|---|---|
| (Intercept) | 1.6624 | 0.0592 | 28.0722 | 0.0000 |
| edunum | -0.0952 | 0.0139 | -6.8439 | 0.0000 |
| gender | 0.0595 | 0.0183 | 3.2542 | 0.0012 |
| health_num | 0.2455 | 0.0116 | 21.0840 | 0.0000 |
| internet_use | -0.0410 | 0.0078 | -5.2700 | 0.0000 |
| social_freq | -0.0222 | 0.0066 | -3.3911 | 0.0007 |
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.
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.