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.
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//Rtmp5dCfSO/model-37264ca28c86.hpp'
## Warning in readLines(private$hpp_file_): incomplete final line found on
## '/var/folders/fy/8zbj5_zd18z5fkghsc48m2bc0000gn/T//Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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/Rtmp5dCfSO/model-37264ca28c86.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).
Model Fit Summary: The Bayesian regression model 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.
# 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)
# 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
Inference and Practical Implications: Using the posterior expected value distributions, I calculated the central measures for each gender and frequency of usage combination. This allowed for a more concise summary of the model’s results, indicating the expected values of self-esteem for different groups.
# 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
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.
CM_long <- CM %>%
mutate(gender = names(post_theta)) %>%
select(-Parameter) %>%
pivot_longer(-gender, names_to = "Measure")
# 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
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.
To analyze the differences in self-esteem scores between females and males, I built the posterior expected value distribution. By considering a fixed frequency of social media usage, I calculated the difference in self-esteem scores for the two genders. This step allowed me to explore how self-esteem scores varied based on gender and social media usage.
# Build the posterior expected value distribution of the differences in self-esteem score estimates
grid <- data.frame(gender = c("Female", "Male"),
frequency_of_use = c(8, 8))
grid <- grid |> add_epred_rvars(fit) |>
mutate(
gender_diff = .epred[gender == "Male"] - .epred[gender == "Female"]
)
grid
## # A tibble: 2 × 4
## gender frequency_of_use .epred gender_diff
## <chr> <dbl> <rvar[1d]> <rvar[1d]>
## 1 Female 8 21 ± 0.17 0.035 ± 0.082
## 2 Male 8 21 ± 0.16 0.035 ± 0.082
These results suggest that there is little to no significant difference in self-esteem scores between genders, regardless of the frequency of social media usage.
To further evaluate the gender differences, I calculated the p-direction and estimated the Region of Practical Equivalence (ROPE). The p-direction measured the probability of observing a certain effect size in favor of one gender over the other. The ROPE provided a range of effect sizes considered practically equivalent between genders.
# Calculate p-direction and estimate Region of Practical Equivalence (ROPE)
p_direction <- grid$gender_diff[grid$frequency_of_use == 8] |>
describe_posterior(rope_range = c(-0.5, 0.5), ci_method = "HDI") |>
mutate(Parameter = grid$gender[grid$frequency_of_use == 8])
p_direction
## Summary of Posterior Distribution
##
## Parameter | Median | 95% CI | pd | ROPE | % in ROPE
## -----------------------------------------------------------------------
## Female | 0.04 | [-0.13, 0.19] | 66.45% | [-0.50, 0.50] | 100%
## Male | 0.04 | [-0.13, 0.19] | 66.45% | [-0.50, 0.50] | 100%
The analysis of p-direction and the Region of Practical Equivalence (ROPE) revealed that there is a 66.45% probability of observing a gender difference in self-esteem scores favoring one gender over the other, based on the estimated effect size. However, when considering the ROPE, which defines a range of effect sizes considered practically equivalent, both females and males had 100% of their posterior distribution within the ROPE of [-0.50, 0.50]. This suggests that there is no practically meaningful difference in self-esteem scores between genders, regardless of the frequency of social media usage.
In order to visualize the distribution of the difference in self-esteem scores and the ROPE, I created another graph. The graph displayed the posterior distribution, the ROPE range indicated by dashed red lines, and a shaded region representing probabilities outside the ROPE. This visualization helped me understand the probability of a meaningful difference in self-esteem scores between genders.
# Visualize the distribution and ROPE
ggplot(grid, aes(y = gender)) +
stat_slabinterval(aes(xdist = gender_diff), fill = "#FFA500", alpha = 0.7, color = "black") +
geom_vline(xintercept = 0, linewidth = 1, color = "red") +
geom_vline(xintercept = -0.5, linewidth = 1, linetype = "dashed", color = "red") +
geom_vline(xintercept = 0.5, linewidth = 1, linetype = "dashed", color = "red") +
geom_rect(aes(xmin = -0.5, xmax = 0.5, ymin = -Inf, ymax = Inf), fill = "red", alpha = 0.01) +
labs(title = "Distribution of Difference in Self-Esteem Score (Female - Male) for Frequency of Use = 8",
x = "Difference of Self-Esteem Score",
y = "Gender") +
theme_minimal()
Additionally, I examined the probability that, for a random female-male pair, the female would exhibit a better self-esteem score. The analysis revealed the likelihood of a female having a higher self-esteem score compared to a male, providing valuable insights into gender differences in self-esteem.
# Calculate the probability that for a random female-male pair, the female will exhibit a better score
prob_female_better <- mean(grid$gender_diff < 0)
cat(prob_female_better, "\n")
## 0.3355 0.3355
The analysis found that there is a 33.55% probability that, for a random female-male pair, the female would have a higher self-esteem score than the male. This suggests a slight tendency for males to exhibit better self-esteem scores compared to females, although the difference is not substantial.
Using Bayesian inference, this analysis examined the relationship between gender, social media usage frequency, and self-esteem. The combination of visualizations and statistical calculations provided insights into gender differences and effect sizes. The findings contribute to our understanding of self-esteem and gender dynamics, emphasizing the importance of individual and contextual factors.
In conclusion, this project found no significant differences in self-esteem levels between genders and across different frequencies of social media usage, based on the analyzed data.