---
title: "Well being statistics"
shorttitle: "Well Stats"
author:
  - name: Josef Mana
    orcid: 0000-0002-7817-3978
    corresponding: true
    affiliations:
      - name: Institute of Psychology, Czech Academy of Sciences
        department: Department of Cognitive Psychology
        address: Pod Vodárenskou věží 4
        city: Prague
        country: Czech Republic
        postal-code: 18200
bibliography: references.bib
format:
  apaquarto-html: default
self-contained: true
warning: false
echo: false
---

# Methods

## Statistical analyses

All demographic and outcome variables were described via contingency tables for nominal (gender and education level), and ordinal (single item responses) variables and via sample mean ± standard deviation for continuous variables (age, years of teaching experience and questionnaires' sum scores). All descriptive statistics were computed separately for each city size. Furthermore, null distributions of nominal and ordinal variables across city sizes were tested via Pearson's $\chi^2$ test of the null hypothesis that the joint distribution of the cell counts is the product of the row and column marginals. The null hypotheses of zero difference between means of continuous variables across city sizes as well as across education levels were tested via one-way ANOVAs with Type I sum of squares. The null hypotheses of zero difference between means of continuous variables in men and women were tested via two sample t-test with Welch approximation of degrees of freedom and two-sided alternative hypothesis.

To establish internal consistency of methods used, Cronbach's coefficient $\alpha$ [@cronbach1951] was computed together with its 95% confidence interval (CI) via @feldt1987 procedure. Methods were considered to show adequate internal consistency if the $\alpha$ exceeded 0.80.

Inspired by the model proposed by @vogel2007, we conducted a moderated mediation analysis of the effect of Well being and Job Satisfaction on Self Stigma either directly or via the Public Stigma. Specifically, we assumed that Well being and Job Satisfaction are causes of Public Stigma perception which in turn is a cause of Self Stigma perception. Moreover, we assume Well being and Job Satisfaction have a direct causal effect on Self Stigma perception and that all these relations are moderated by age and gender. Finally, Well being and Job Satisfaction were assumed to have common unobserved causes. These causal assumptions are depicted in @fig-dag in the form of a directed acyclic graph (DAG). To estimate the direct and indirect effects implied by this DAG, a structural equation model (SEM) following @fig-dag was fitted and evaluated via the lavaan [@rosseel2012] R package. Full model specification is available at [https://github.com/josefmana/StigHelp.git](https://github.com/josefmana/StigHelp.git).

![Assumed causal relations between observed variables represented by a directed acyclic graph.](../projects/wellbeing/figures/DAG.jpg){#fig-dag}

Finally, correlation structure of questionnaires on levels of sum scores and single items was explored. For item-level analysis, all reverse-coded items were rescored such that higher scores of all items within a questionnaire implied higher level of construct being measured, and then pairwise correlation of all item pairs across all questionnaires were estimated via polychoric correlation coefficient [@olsson1979]. Sum scores' correlations were estimated via Pearson's correlation coefficient and null hypotheses of *r* = 0 were tested via t-test based on formula

$t = \frac{r \sqrt(n-2)}{\sqrt(1-r^2)}$

with standard error:

$se = \sqrt(\frac{1-r^2}{n-2})$,

where *r* = Pearson's correlation coefficient and *n* = sample size.

Across analyses, missing values were addressed via complete cases analysis and tests with p \< .05 were considered "statically significant." Analyses were conducted in language for statistical computing R (version `r with(version, paste(major, minor, sep = '.'))`) via "psych" package [@psych], and correlation matrices were visualised via "corrplot" package [@corrplot].

```{r}
#| label: import
#| output: false

library(targets)
library(tidyverse)
library(gt)

upstore <- "_targets"
tar_source()
tar_source("../../R")
new_folder("tables")

# Read outcome data for the report:
n1 <- tar_read(N, store = upstore)$n1 |> c() # Numbers based on city size
n2 <- tar_read(N, store = upstore)$n2 |> c() # Numbers based on gender
n3 <- tar_read(N, store = upstore)$n3 |> c() # Numbers based on education level
tab1 <- tar_read(main_description, store = upstore)
tab2 <- tar_read(education_comparisons, store = upstore)$stats
tab3 <- tar_read(mediation_table, store = upstore)
tab4 <- tar_read(main_correlations, store = upstore)
gtab <- tar_read(gender_comparisons, store = upstore)$stats
alph <- tar_read(alphas_table, store = upstore)
```

# Results

## Sample description

In total, the sample included `r sum(n1)` participants out of which `r n1[1]` came from a city with less than 3,000 inhabitants, `r n1[2]` came from a city with 3,000-15,000 inhabitants, `r n1[3]` came from a city with 15,000-50,000 inhabitants, `r n1[4]` came from a city with 50,000-100,000 inhabitants, `r n1[5]` came from a city with 100,000-500,000 inhabitants, and `r n1[6]` came from a city with more than 500,000 inhabitants. No statistically significant difference in distribution of nominal variables or means of continuous variables between city sizes was observed (@tbl-desc).

```{r}
#| label: tbl-desc
#| tbl-cap: "Sample description"

tab1 <- tab1 |>
  mutate(Variable = case_when(
    startsWith(Variable, "7.") ~ "Gender",
    startsWith(Variable, "9.") ~ "Education level",
    startsWith(Variable, "6.") ~ "Age (years)",
    startsWith(Variable, "10.") ~ "Teaching experience (years)",
    .default = Variable
  )) |>
  add_column(type = c(rep("Demographic variables", 4), rep("Psychological outcomes", 4))) |>
  gt(rowname_col = "Variable", groupname_col = "type") |>
  tab_spanner(label = "Number of inhabitants", columns = ends_with("000")) |>
  cols_label(stats = html("Statistical analysis")) |>
  tab_footnote(
    footnote = "presented as women/men/unanswered",
    locations = cells_stub(rows = "Gender")
  ) |>
  tab_footnote(
    footnote = "presented as High school/Bachelors/Masters/PhD",
    locations = cells_stub(rows = "Education level")
  ) |>
  tab_source_note("All continuous variables are reported as sample mean ± standard deviation.")

gtsave(tab1, here::here("projects", "wellbeing", "tables", "tab1_sample_description.docx"))
tab1
```

There were `r n3[1]` participants with High School, `r n3[2]` participants with Bachelor's degree, `r n3[3]` participants with Master's degree, and `r n3[4]` participants with PhD. We did not observe any statistically significant differences in means of psychological outcomes between different education levels (@tbl-edu).

```{r}
#| label: tbl-edu
#| tbl-cap: "Psychological outcomes' means across education level"

tab2 <- tab2 |>
  gt(rowname_col = "scale") |>
  tab_spanner(label = "Education level", columns = !contains("stats")) |>
  cols_label(stats = "One-way ANOVA") |>
  tab_source_note(
    "BA = Bachelor's degree, MA = Master's degree. All variables are reported as sample mean ± standard deviation"
  )

gtsave(tab2, here::here("projects", "wellbeing", "tables", "tab2_outcomes_description.docx"))
tab2
```

There were `r n2["female"]` women, `r n2["male"]` men, and `r n2["other"]` participants who did not report their gender. We observed a statistically significant difference between mean Self Stigma ($M_{women}$ = `r with(gtab, mean_female[grepl("Self-stigma", scale)])`, $M_{men}$ = `r with(gtab, mean_male[grepl("Self-stigma", scale)])`, t(`r with(gtab, df[grepl("Self-stigma", scale)])`) = `r with(gtab, t[grepl("Self-stigma", scale)])`, p `r with(gtab, p[grepl("Self-stigma", scale)])`) and mean Public stigma ($M_{women}$ = `r with(gtab, mean_female[grepl("others", scale)])`, $M_{men}$ = `r with(gtab, mean_male[grepl("others", scale)])`, t(`r with(gtab, df[grepl("others", scale)])`) = `r with(gtab, t[grepl("others", scale)])`, p = `r with(gtab, p[grepl("others", scale)])`). In both cases, men reported higher mean stigmatisation compared to women. We did not observe a significant difference between men and women in either mean Well-being ($M_{women}$ = `r with(gtab, mean_female[grepl("being", scale)])`, $M_{men}$ = `r with(gtab, mean_male[grepl("being", scale)])`, t(`r with(gtab, df[grepl("being", scale)])`) = `r with(gtab, t[grepl("being", scale)])`, p = `r with(gtab, p[grepl("being", scale)])`) or mean Job satisfaction ($M_{women}$ = `r with(gtab, mean_female[grepl("Job", scale)])`, $M_{men}$ = `r with(gtab, mean_male[grepl("Job", scale)])`, t(`r with(gtab, df[grepl("Job", scale)])`) = `r with(gtab, t[grepl("Job", scale)])`, p = `r with(gtab, p[grepl("Job", scale)])`).

## Internal consistency

All scales showed adequate internal consistency in the current sample according to the Cronbach's $\alpha$ estimates ($\alpha_D$ = `r with(alph, alpha[grepl("D scale", scale)])`, $\alpha_U$ = `r with(alph, alpha[grepl("U scale", scale)])`, $\alpha_S$ = `r with(alph, alpha[grepl('S scale',scale)])`, $\alpha_K$ = `r with(alph, alpha[grepl("K scale", scale)])`) for Well being, Job satisfaction, Self-stigma and Public stigma respectively.

## Moderated mediation

Effect estimates from the SEM are presented in @tbl-sem. We observed a statistically significant effect of Public Stigma on Self Stigma across age groups and genders. The model implies a significant effect of Job Satisfaction and Well being on Public Stigma in Women. The estimates of total effect of Job Satisfaction on Self-Stigma were compatible with a null model (i.e., no causal effect). On the other hand, the model implies a statistically significant total effect of Well being on Self-stigma in women, especially in older age groups. This effect was driven primarily by the direct effect instead of the indirect effect via Public Stigma.

```{r}
#| label: tbl-sem
#| tbl-cap: "Effects derived from the structural equation model of observed variables"

gtsave(tab3, here::here("projects", "wellbeing", "tables", "tab3_moderated_mediation.docx"))
tab3
```

## Correlation structure

Correlation matrix of sum scores is presented in @fig-corsum (see also @tbl-corsum for numeric representation). Both Self-stigma and Stigma due to others correlated statistically significantly with Well-being and Job satisfaction but not with age and years of teaching experience. Interestingly, the correlation seems to be confined to several stigma due to others scale items on the item-level (see @fig-corits)

![Psychological outcomes' correlational structure. Green circles denote variable pairs whose correlation was statistically significant on 5% level.](../projects/wellbeing/_figures/sum_scores_cormat.jpg){#fig-corsum}

# Appendix

```{r}
#| label: tbl-corsum
#| tbl-cap: "Pearson's correlations between primary outcome variables of the study"

tab4 <- tab4 |>
  rownames_to_column("x") |>
  gt(rowname_col = "x") |>
  sub_missing(missing_text = "")

gtsave(tab4, here::here("projects", "wellbeing", "tables", "tab4_correlation_matrix.docx"))
tab4
```

![Item-level correlation matrix. Cells represent polychoric correlations between each item of each questionnaire used.](../projects/wellbeing/figures/item_level_cormat.jpg){#fig-corits}

# References
