Have you ever wondered how your social media use and gender might influence your self-esteem? In this analysis, I delved into the relationship between self-esteem and daytime social media use, aiming to shed light on the impact of gender and frequency of social media use. Using Bayesian inference, a powerful statistical approach, I examined a dataset of 10,000 survey participants to unravel the fascinating connections between these variables. Join me as we uncover the intriguing insights that lie beneath the surface of our digital lives and explore the complex interplay between self-esteem, gender, and social media use.
# Load necessary libraries
library(ggplot2) # For data visualization
library(brms) # For Bayesian regression
## Loading required package: Rcpp
## Loading 'brms' package (version 2.19.0). Useful instructions
## can be found by typing help('brms'). A more detailed introduction
## to the package is available through vignette('brms_overview').
##
## Attaching package: 'brms'
## The following object is masked from 'package:stats':
##
## ar
library(posterior) # For posterior analysis
## This is posterior version 1.4.1
##
## Attaching package: 'posterior'
## The following objects are masked from 'package:stats':
##
## mad, sd, var
## The following objects are masked from 'package:base':
##
## %in%, match
library(bayesplot) # For posterior plots
## This is bayesplot version 1.10.0
## - Online documentation and vignettes at mc-stan.org/bayesplot
## - bayesplot theme set to bayesplot::theme_default()
## * Does _not_ affect other ggplot2 plots
## * See ?bayesplot_theme_set for details on theme setting
##
## Attaching package: 'bayesplot'
## The following object is masked from 'package:posterior':
##
## rhat
## The following object is masked from 'package:brms':
##
## rhat
library(tidybayes) # For tidyverse-style summaries of posterior draws
##
## Attaching package: 'tidybayes'
## The following objects are masked from 'package:brms':
##
## dstudent_t, pstudent_t, qstudent_t, rstudent_t
library(ggdist) # For plotting posteriors with ggplot2
##
## Attaching package: 'ggdist'
##
## The following objects are masked from 'package:brms':
##
## dstudent_t, pstudent_t, qstudent_t, rstudent_t
library(bayestestR) # For Bayesian hypothesis testing
##
## Attaching package: 'bayestestR'
## The following object is masked from 'package:ggdist':
##
## hdi
## The following object is masked from 'package:tidybayes':
##
## hdi
library(dplyr) # For data frame manipulation
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(tidyr) # For data tidying and reshaping
library(HDInterval) # For calculating HDI
##
## Attaching package: 'HDInterval'
## The following object is masked from 'package:bayestestR':
##
## hdi
## The following object is masked from 'package:ggdist':
##
## hdi
## The following object is masked from 'package:tidybayes':
##
## hdi
# Read the data
df <- read.csv("/Users/adiiore/Desktop/selfesteem.csv")
df <- df[, c("frequency_of_use", "gender", "self_esteem")]
To explore the relationship between gender and self-esteem, I created a scatter plot with gender on the x-axis and self-esteem on the y-axis. The plot revealed no clear association between gender and self-esteem, indicating that gender alone may not influence self-esteem levels.
# Visualize the relationship between gender and self-esteem
P1 <- ggplot(df, aes(x = gender, y = self_esteem)) +
geom_point() +
labs(title = "Relationship between Gender and Self-Esteem",
x = "Gender",
y = "Self-Esteem")
P1
Exploring Social Media Use and Self-Esteem by Gender: To gain a deeper understanding, I examined the impact of social media on self-esteem while considering gender differences. Using a whisker and box plot, I compared self-esteem scores for men and women at different levels of social media usage. Interestingly, the results showed minimal differences between genders, but a clearly negative correlation between the amount of daily social media usage in hours and self-esteem.
P2 <- ggplot(df, aes(factor(frequency_of_use), self_esteem)) +
geom_boxplot() +
facet_grid(. ~ gender) +
labs(title = "The Relationship between Frequency of Social Media Usage and Self-Esteem",
x = "Frequency of Daytime Social Media Usage (in Hours)",
y = "Level of Self-Esteem")
P2
Next, I employed Bayesian regression analysis to examine the relationship between gender, social media usage, and self-esteem. I set priors based on my prior beliefs, assuming a negative correlation between social media usage and self-esteem while having no strong assumption about gender. The model incorporated gender and usage frequency as predictors of self-esteem, and I evaluated the model’s fit and performed posterior analysis to extract insights.
# Set Priors
priors <- set_prior("normal(-4, 2)", class = "b", coef = "frequency_of_use") +
set_prior("student_t(3, 0.5, 0.5)", class = "b", coef = "genderMale") +
set_prior("student_t(3, 24.8, 4.2)", class = "Intercept") +
set_prior("student_t(3, 0, 4.2)", class = "sigma")
# Perform Bayesian regression
fit <- brm(
self_esteem ~ gender + frequency_of_use,
family = gaussian(),
data = df,
prior = priors,
backend = "cmdstanr",
seed = 1234
)
## Warning in readLines(hpp_path): incomplete final line found on
## '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T//RtmpTbiT7A/model-4c7d4a588795.hpp'
## Warning in readLines(private$hpp_file_): incomplete final line found on
## '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T//RtmpTbiT7A/model-4c7d4a588795.hpp'
## Start sampling
## Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 1
## Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 1
## Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 1
## Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 1
## Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 1
## Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 1
## Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 1
## Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 1
## Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 1
## Chain 1 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 1 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 1 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 1 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 1
## Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 2
## Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 2
## Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 2
## Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 2
## Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 2
## Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 2
## Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 2
## Chain 2 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 2 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 2 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 2 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 2
## Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 3
## Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 3
## Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 3
## Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 3
## Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 3
## Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 3
## Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 3
## Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 3
## Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 3
## Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 3
## Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 3
## Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 3
## Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 3
## Chain 3 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 3 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 3 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 3 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 3
## Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 4
## Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 4
## Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 4
## Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 4
## Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 4
## Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 4
## Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 4
## Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 4
## Chain 4 Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
## Chain 4 Exception: normal_id_glm_lpdf: Scale vector is inf, but must be positive finite! (in '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T/RtmpTbiT7A/model-4c7d4a588795.stan', line 37, column 4 to column 62)
## Chain 4 If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
## Chain 4 but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.
## Chain 4
# Check the model fit
fit
## Family: gaussian
## Links: mu = identity; sigma = identity
## Formula: self_esteem ~ gender + frequency_of_use
## Data: df (Number of observations: 10000)
## Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
## total post-warmup draws = 4000
##
## Population-Level Effects:
## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## Intercept 28.62 0.16 28.32 28.94 1.00 4589 3210
## genderMale 0.04 0.08 -0.13 0.20 1.00 3896 2766
## frequency_of_use -0.96 0.04 -1.04 -0.89 1.00 4776 3144
##
## Family Specific Parameters:
## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS Tail_ESS
## sigma 4.01 0.03 3.96 4.07 1.00 5507 2941
##
## Draws were sampled using sample(hmc). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).
Models Fit Summary: The Bayesian regression models showed good fit to the data, indicating an effective capture of the relationship between the predictors and self-esteem. The R-hat indicators being less than 0.01 confirm the convergence of the MCMC algorithm, ensuring reliable parameter estimation. Additionally, the Bulk-ESS indicators exceeding 1000 indicate a sufficient effective sample size, enabling robust statistical conclusions to be drawn from the analysis. Considering my posteriors, I created a graph to visualize the posterior expected value distributions of self-esteem for females and males at a specific social media usage frequency. This graph allows for a clear comparison of self-esteem distributions between genders, taking into account the frequency of social media usage.
conclusions: The analysis revealed that social media usage frequency has a negative impact on self-esteem, with each unit increase associated with a 0.96-point decrease in average self-esteem score. While there is a slight tendency for males to have higher self-esteem scores compared to females, the difference is not statistically significant. These findings highlight the importance of considering social media usage and gender dynamics in understanding self-esteem levels.
# Build the posterior expected value distributions of self-esteem for females and males
grid <- data.frame(gender = c("Female", "Male"),
frequency_of_use = c(8, 8))
grid <- grid |> add_epred_rvars(fit)
grid
## # A tibble: 2 × 3
## gender frequency_of_use .epred
## <chr> <dbl> <rvar[1d]>
## 1 Female 8 21 ± 0.17
## 2 Male 8 21 ± 0.16
# Create a graph to visualize the posterior expected value distributions of self-esteem
P3 <- ggplot(grid, aes(y = interaction(gender, frequency_of_use))) +
stat_slab(aes(xdist = .epred), fill = "#6495ED", alpha = 0.7, color = "black") +
labs(title = "Posterior Expected Value Distributions of Self-Esteem",
x = "Expected Value of Self-Esteem",
y = "Gender and Frequency of Social Media Usage") +
theme_minimal()
P3
The analysis indicates that for both females and males with a social media usage frequency of 8, the average self-esteem score is estimated to be 21, suggesting no significant gender differences in self-esteem at this frequency. However, these estimates are subject to uncertainty.
# Build the posterior expected value distributions of self-esteem for females and males
grid1 <- data.frame(frequency_of_use = c(2,4,6, 8),
gender = c("Female","Female","Female", "Female"))
grid1 <- grid1 |> add_epred_rvars(fit)
grid1
## # A tibble: 4 × 3
## frequency_of_use gender .epred
## <dbl> <chr> <rvar[1d]>
## 1 2 Female 27 ± 0.094
## 2 4 Female 25 ± 0.058
## 3 6 Female 23 ± 0.098
## 4 8 Female 21 ± 0.166
# Create a graph to visualize the posterior expected value distributions of self-esteem
P4 <- ggplot(grid1, aes(y = interaction(gender, frequency_of_use))) +
stat_slab(aes(xdist = .epred), fill = "pink", alpha = 0.7, color = "black") +
labs(title = "Posterior Expected Value Distributions of Self-Esteem",
x = "Expected Value of Self-Esteem",
y = "Gender and Frequency of Social Media Usage") +
theme_minimal()
P4
Tested the posterior expected value distributions of self-esteem for
different frequencies of social media usage among females, finding a
decreasing trend in average self-esteem as frequency of use increases.
Conclusions: Higher social media usage frequency may be associated with
lower self-esteem among females, but further analysis is needed
considering the uncertainties associated with the estimates.
Next, to gain insights into the relationship between gender and self-esteem, I visualized the posterior predictive distribution of self-esteem scores. This allowed me to assess the model’s ability to generate realistic values for self-esteem based on gender. The shaded region on the graph represents the range of possible self-esteem scores, considering both the model’s parameter estimates and the inherent variability in the data. By examining this distribution, we can better understand the expected values of self-esteem and evaluate the model’s predictive performance.
# Calculate central measures
post_theta <- grid$.epred
CM <- point_estimate(post_theta)
names(post_theta) <- grid$gender
CM_long <- CM %>%
mutate(gender = names(post_theta)) %>%
select(-Parameter) %>%
pivot_longer(-gender, names_to = "Measure")
CM_long
## # A tibble: 6 × 3
## gender Measure value
## <chr> <chr> <dbl>
## 1 Female Median 20.9
## 2 Female Mean 20.9
## 3 Female MAP 20.9
## 4 Male Median 21.0
## 5 Male Mean 21.0
## 6 Male MAP 21.0
CM_long <- CM %>%
mutate(gender = names(post_theta)) %>%
select(-Parameter) %>%
pivot_longer(-gender, names_to = "Measure")
The convergence of the center indices in the Posterior Predictive Distribution signifies that the model consistently predicts similar average self-esteem scores for each gender, providing confidence in the accuracy of the predictions.
# Visualize the posterior predictive distribution
p <- ggplot(grid, aes(y = gender)) +
stat_slab(aes(xdist = .epred), fill = "#FFA500", alpha = 0.7, color = "black") +
geom_point(aes(x = value, color = Measure, shape = Measure),
data = CM_long, size = 4, alpha = 0.6) +
labs(title = "Posterior Predictive Distribution: Expected Values",
x = "Expected Value",
y = "Gender") +
theme_minimal()
p
This project used Bayesian inference to investigate the relationship between gender, frequency of social media usage, and self-esteem. The analysis revealed that there are no significant differences in self-esteem levels between genders and across different frequencies of social media usage. However, there is a slight tendency for males to exhibit slightly better self-esteem scores compared to females. Additionally, the findings indicate a negative relationship between the number of hours spent on social media and self-worth scores, suggesting that excessive social media use may be associated with lower self-esteem. These conclusions contribute to our understanding of self-esteem and gender dynamics, emphasizing the importance of individual and contextual factors in shaping self-perception in the digital age.