---
title: Power motivations and sexual risk-taking
date: "March 22nd, 2023"
toc: true
format:
html:
html-math-method: katex
code-tools: true
self-contained: true
code-fold: true
code-summary: "Show the code"
execute:
warning: false
---
```{r}
#| collapse: true
#| echo: true
library (papaja)
library (xtable)
library (tidyr)
library (purrr)
library (ggplot2)
library (brms)
library (bayestestR)
library (rstan)
library (readxl)
library (sjPlot)
library (cmdstanr)
library (plotly)
library (corrplot)
library (htmlwidgets)
library (bayestestR)
library (formatR)
library (kableExtra)
library (tidybayes)
library (blavaan)
library (rmarkdown)
library (tidySEM)
library (ggcorrplot)
library (ggprism)
library (htmlTable)
library (table1)
library (data.table)
library (semPlot)
library (correlation)
library (dplyr)
library (lavaan)
library (dplyr)
library (tibble)
library (stringi)
library (tidyr)
library (kableExtra)
library (rrtable)
library (sjPlot)
library (purrr)
library (stringi)
library (ggplot2)
library (tidyverse)
setwd ("/Users/andrew/Documents/1_UoE/Research/PhD/Experiments/DoPL/Experiments/Experiment_2_Study_Past_Sexual_Experiences" )
Experiment_4_DF_Final <- read.csv ("./Analysis/Experiment_4_DF_Final.csv" )
source ("./Analysis/Question_index.R" )
Experiment_4_DF_Final$ Gender <- as.factor (Experiment_4_DF_Final$ Gender)
load ("Experiment_4_Analysis.RData" )
```
```{r}
Experiment_4_DF_Final$ Gender <- as.factor (Experiment_4_DF_Final$ Gender)
Experiment_4_Analysis_DF <- Experiment_4_DF_Final[! grepl (5 , Experiment_4_DF_Final$ Gender), ]
ggplot (Experiment_4_Analysis_DF, aes (x = Gender, fill = Gender)) +
geom_histogram (stat = "count" ) +
labs (x = "Gender2" ) +
scale_y_continuous (breaks = seq (0 , 160 , 10 ), guide = "prism_offset" ) +
theme (legend.position = "none" )
```
```{r Analysis-Priors}
#| eval: false
#| collapse: true
#| echo: true
m1_prior <- c (
# SRTB Risk
prior (normal (0 , 1 ), coef = "Age" , resp = "SRTBRiskz" ),
prior (normal (.5 , .02 ), coef = "DoPL_Dominance_z" , resp = "SRTBRiskz" ),
prior (normal (0 , 1 ), coef = "DoPL_Leadership_z" , resp = "SRTBRiskz" ),
prior (normal (0 , 1 ), coef = "DoPL_Prestige_z" , resp = "SRTBRiskz" ),
prior (normal (.5 , .2 ), coef = "Gender2" , resp = "SRTBRiskz" ),
prior (normal (0 , 1 ), coef = "B_PNI_z" , resp = "SRTBRiskz" ),
prior (normal (0 , 1 ), class = "Intercept" , resp = "SRTBRiskz" ),
prior (normal (0 , 1 ), class = "sigma" , resp = "SRTBRiskz" ),
# SRTB Benefit
prior (normal (0 , 1 ), coef = "Age" , resp = "SRTBBenefitz" ),
prior (normal (.5 , .02 ), coef = "DoPL_Dominance_z" , resp = "SRTBBenefitz" ),
prior (normal (0 , 1 ), coef = "DoPL_Leadership_z" , resp = "SRTBBenefitz" ),
prior (normal (0 , 1 ), coef = "DoPL_Prestige_z" , resp = "SRTBBenefitz" ),
prior (normal (.5 , .2 ), coef = "Gender2" , resp = "SRTBBenefitz" ),
prior (normal (0 , 1 ), coef = "B_PNI_z" , resp = "SRTBBenefitz" ),
prior (normal (0 , 1 ), class = "Intercept" , resp = "SRTBBenefitz" ),
prior (normal (0 , 1 ), class = "sigma" , resp = "SRTBBenefitz" ),
# SRTB Frequency
prior (normal (0 , 1 ), coef = "Age" , resp = "SRTBFrequencyz" ),
prior (normal (.5 , .02 ), coef = "DoPL_Dominance_z" , resp = "SRTBFrequencyz" ),
prior (normal (0 , 1 ), coef = "DoPL_Leadership_z" , resp = "SRTBFrequencyz" ),
prior (normal (0 , 1 ), coef = "DoPL_Prestige_z" , resp = "SRTBFrequencyz" ),
prior (normal (.5 , .2 ), coef = "Gender2" , resp = "SRTBFrequencyz" ),
prior (normal (0 , 1 ), coef = "B_PNI_z" , resp = "SRTBFrequencyz" ),
prior (normal (0 , 1 ), class = "Intercept" , resp = "SRTBFrequencyz" ),
prior (normal (0 , 1 ), class = "sigma" , resp = "SRTBFrequencyz" ),
# SRTB Likelihood
prior (normal (0 , 1 ), coef = "Age" , resp = "SRTBLikelihoodz" ),
prior (normal (.5 , .02 ), coef = "DoPL_Dominance_z" , resp = "SRTBLikelihoodz" ),
prior (normal (0 , 1 ), coef = "DoPL_Leadership_z" , resp = "SRTBLikelihoodz" ),
prior (normal (0 , 1 ), coef = "DoPL_Prestige_z" , resp = "SRTBLikelihoodz" ),
prior (normal (.5 , .2 ), coef = "Gender2" , resp = "SRTBLikelihoodz" ),
prior (normal (0 , 1 ), coef = "B_PNI_z" , resp = "SRTBLikelihoodz" ),
prior (normal (0 , 1 ), class = "Intercept" , resp = "SRTBLikelihoodz" ),
prior (normal (0 , 1 ), class = "sigma" , resp = "SRTBLikelihoodz" )
)
m1_interaction_prior <- c (
# SRTB Risk
prior (normal (0 , 1 ), coef = "Age" , resp = "SRTBRiskz" ),
prior (normal (.5 , .02 ), coef = "DoPL_Dominance_z" , resp = "SRTBRiskz" ),
prior (normal (0 , 1 ), coef = "DoPL_Leadership_z" , resp = "SRTBRiskz" ),
prior (normal (0 , 1 ), coef = "DoPL_Prestige_z" , resp = "SRTBRiskz" ),
prior (normal (.5 , .2 ), coef = "Gender2" , resp = "SRTBRiskz" ),
prior (normal (0 , 1 ), coef = "B_PNI_z" , resp = "SRTBRiskz" ),
prior (normal (0 , 1 ), class = "Intercept" , resp = "SRTBRiskz" ),
prior (normal (0 , 1 ), class = "sigma" , resp = "SRTBRiskz" ),
prior (normal (.5 , .02 ), coef = "DoPL_Dominance_z:Gender2" , resp = "SRTBRiskz" ),
prior (normal (0 , 1 ), coef = "Gender2:DoPL_Leadership_z" , resp = "SRTBRiskz" ),
prior (normal (0 , 1 ), coef = "Gender2:DoPL_Prestige_z" , resp = "SRTBRiskz" ),
prior (normal (0 , 1 ), coef = "Gender2:B_PNI_z" , resp = "SRTBRiskz" ),
# SRTB Benefit
prior (normal (0 , 1 ), coef = "Age" , resp = "SRTBBenefitz" ),
prior (normal (.5 , .02 ), coef = "DoPL_Dominance_z" , resp = "SRTBBenefitz" ),
prior (normal (0 , 1 ), coef = "DoPL_Leadership_z" , resp = "SRTBBenefitz" ),
prior (normal (0 , 1 ), coef = "DoPL_Prestige_z" , resp = "SRTBBenefitz" ),
prior (normal (.5 , .2 ), coef = "Gender2" , resp = "SRTBBenefitz" ),
prior (normal (0 , 1 ), coef = "B_PNI_z" , resp = "SRTBBenefitz" ),
prior (normal (0 , 1 ), class = "Intercept" , resp = "SRTBBenefitz" ),
prior (normal (0 , 1 ), class = "sigma" , resp = "SRTBBenefitz" ),
prior (normal (.5 , .02 ), coef = "DoPL_Dominance_z:Gender2" , resp = "SRTBBenefitz" ),
prior (normal (0 , 1 ), coef = "Gender2:DoPL_Leadership_z" , resp = "SRTBBenefitz" ),
prior (normal (0 , 1 ), coef = "Gender2:DoPL_Prestige_z" , resp = "SRTBBenefitz" ),
prior (normal (0 , 1 ), coef = "Gender2:B_PNI_z" , resp = "SRTBBenefitz" ),
# SRTB Frequency
prior (normal (0 , 1 ), coef = "Age" , resp = "SRTBFrequencyz" ),
prior (normal (.5 , .02 ), coef = "DoPL_Dominance_z" , resp = "SRTBFrequencyz" ),
prior (normal (0 , 1 ), coef = "DoPL_Leadership_z" , resp = "SRTBFrequencyz" ),
prior (normal (0 , 1 ), coef = "DoPL_Prestige_z" , resp = "SRTBFrequencyz" ),
prior (normal (.5 , .2 ), coef = "Gender2" , resp = "SRTBFrequencyz" ),
prior (normal (0 , 1 ), coef = "B_PNI_z" , resp = "SRTBFrequencyz" ),
prior (normal (0 , 1 ), class = "Intercept" , resp = "SRTBFrequencyz" ),
prior (normal (0 , 1 ), class = "sigma" , resp = "SRTBFrequencyz" ),
prior (normal (.5 , .02 ), coef = "DoPL_Dominance_z:Gender2" , resp = "SRTBFrequencyz" ),
prior (normal (0 , 1 ), coef = "Gender2:DoPL_Leadership_z" , resp = "SRTBFrequencyz" ),
prior (normal (0 , 1 ), coef = "Gender2:DoPL_Prestige_z" , resp = "SRTBFrequencyz" ),
prior (normal (0 , 1 ), coef = "Gender2:B_PNI_z" , resp = "SRTBFrequencyz" ),
# SRTB Likelihood
prior (normal (0 , 1 ), coef = "Age" , resp = "SRTBLikelihoodz" ),
prior (normal (.5 , .02 ), coef = "DoPL_Dominance_z" , resp = "SRTBLikelihoodz" ),
prior (normal (0 , 1 ), coef = "DoPL_Leadership_z" , resp = "SRTBLikelihoodz" ),
prior (normal (0 , 1 ), coef = "DoPL_Prestige_z" , resp = "SRTBLikelihoodz" ),
prior (normal (.5 , .2 ), coef = "Gender2" , resp = "SRTBLikelihoodz" ),
prior (normal (0 , 1 ), coef = "B_PNI_z" , resp = "SRTBLikelihoodz" ),
prior (normal (0 , 1 ), class = "Intercept" , resp = "SRTBLikelihoodz" ),
prior (normal (0 , 1 ), class = "sigma" , resp = "SRTBLikelihoodz" ),
prior (normal (.5 , .02 ), coef = "DoPL_Dominance_z:Gender2" , resp = "SRTBLikelihoodz" ),
prior (normal (0 , 1 ), coef = "Gender2:DoPL_Leadership_z" , resp = "SRTBLikelihoodz" ),
prior (normal (0 , 1 ), coef = "Gender2:DoPL_Prestige_z" , resp = "SRTBLikelihoodz" ),
prior (normal (0 , 1 ), coef = "Gender2:B_PNI_z" , resp = "SRTBLikelihoodz" )
)
```
# Multi model with dopl and pni as predictor variables
```{r}
#| eval: false
#| label: code-SRTBDoPLPNI
#| echo: true
#| collapse: true
Experiment_4_Analysis_DF <- Experiment_4_DF_Final[! grepl (5 ,Experiment_4_DF_Final$ Gender), ]
m1 <- brm (mvbind (SRTB_Likelihood_z, SRTB_Risk_z, SRTB_Benefit_z, SRTB_Frequency_z) ~ DoPL_Dominance_z + DoPL_Prestige_z + DoPL_Leadership_z + B_PNI_z + Age + Gender,
data = Experiment_4_Analysis_DF,
prior = m1_prior,
iter = 10000 ,
warmup = 1000 ,
chains = 4 ,
cores = parallel:: detectCores (),
save_pars = save_pars (all = TRUE ),
backend = "cmdstanr"
)
```
```{r}
#| eval: true
#| label: tbl-SRTBDoPLPNI
#| echo: true
#| collapse: true
summary (m1)
```
```{r}
#| label: tbl-SRTBDoPL
#| echo: FALSE
#| tbl-cap: "Experiment 2 | Bayesian regression of individual DOSPERT domains as response and dominance, prestige, leadership, and pathlogical narcissism as predictors."
kable (MutateHDI:: mutate_df_multi_not_dospert (m1),
booktabs = TRUE ,
format = "html" ,
linesep = "" ,
escape = TRUE ,
col.names = c ("Predictor" , "Estimate" , "HDI (95%)" , "ROPE" , "Estimate" , "HDI (95%)" , "ROPE" , "Estimate" , "HDI (95%)" , "ROPE" , "Estimate" , "HDI (95&)" , "ROPE" ))%>%
kable_styling (full_width = FALSE , latex_options = "scale_down" )%>%
add_header_above (c ("" , "SRTB Likelihood" = 3 , "SRTB Perception" = 3 , "SRTB Benefit" = 3 , "SRTB Frequency" = 3 )) %>%
footnote (footnote_as_chunk = TRUE , general = "ROPE equates to percentage in region of practical equivalence. HDI equates to high density interval of the posterior distribution." )
```
# Multi model with dopl and pni as predictor variables and interaction terms
```{r}
#| eval: true
#| echo: true
#| collapse: true
Experiment_4_Analysis_DF <- Experiment_4_DF_Final[! grepl (5 , Experiment_4_DF_Final$ Gender), ]
m1_interaction <- brm (mvbind (SRTB_Likelihood_z, SRTB_Risk_z, SRTB_Benefit_z, SRTB_Frequency_z) ~ DoPL_Dominance_z * Gender + DoPL_Prestige_z * Gender + DoPL_Leadership_z * Gender + B_PNI_z * Gender + Age,
data = Experiment_4_Analysis_DF,
prior = m1_interaction_prior,
iter = 10000 ,
warmup = 1000 ,
chains = 4 ,
cores = parallel:: detectCores (),
save_pars = save_pars (all = TRUE ),
backend = "cmdstanr"
)
```
```{r}
#| eval: true
#| echo: true
#| collapse: true
summary (m1_interaction)
```
```{r}
#| label: tbl-SRTBDoPL_interaction
#| echo: false
#| tbl-cap: "Experiment 2 | Bayesian regression of individual DOSPERT domains as response and dominance, prestige, leadership, and pathlogical narcissism as predictors."
kable (MutateHDI:: mutate_df_multi_not_dospert (m1_interaction),
booktabs = TRUE ,
format = "html" ,
linesep = "" ,
escape = TRUE ,
col.names = c ("Predictor" , "Estimate" , "HDI (95%)" , "ROPE" , "Estimate" , "HDI (95%)" , "ROPE" , "Estimate" , "HDI (95%)" , "ROPE" , "Estimate" , "HDI (95&)" , "ROPE" ))%>%
kable_styling (full_width = FALSE , latex_options = "scale_down" )%>%
add_header_above (c ("" , "SRTB Likelihood" = 3 , "SRTB Perception" = 3 , "SRTB Benefit" = 3 , "SRTB Frequency" = 3 )) %>%
footnote (footnote_as_chunk = TRUE , general = "ROPE equates to percentage in region of practical equivalence. HDI equates to high density interval of the posterior distribution." )
```
# m1 model comparison
```{r}
#| eval: false
m1_comparison <- loo (m1, m1_interaction)
m1_comparison
```
```{r}
#| collapse: true
bayes_factor (m1, m1_interaction)
```
## Correlation
```{r}
#| eval: false
correlation_df <- Experiment_4_DF_Final %>% rename (
"Age" = "Age" ,
"Dominance" = "DoPL_Dominance_z" ,
"Leadership" = "DoPL_Leadership_z" ,
"Prestige" = "DoPL_Prestige_z" ,
"B-PNI" = "B_PNI_z" ,
"Grandiosity" = "PNI_Grandiosity_z" ,
"Vulnerability" = "PNI_Vulnerability_z" ,
"UMS" = "UMS_z" ,
"Intimacy" = "UMS_Intimacy_z" ,
"Affiliation" = "UMS_Affiliation_z" ,
"SRTB Benefit" = "SRTB_Benefit_z" ,
"SRTB Risk" = "SRTB_Risk_z" ,
"SRTB Likelihood" = "SRTB_Likelihood_z" ,
"SRTB Frequency" = "SRTB_Frequency_z"
)
correlation_df <- subset (correlation_df, select = c (
"Age" ,
"Dominance" ,
"Leadership" ,
"Prestige" ,
"B-PNI" ,
"Grandiosity" ,
"Vulnerability" ,
"UMS" ,
"Intimacy" ,
"Affiliation" ,
"SRTB Benefit" ,
"SRTB Risk" ,
"SRTB Likelihood" ,
"SRTB Frequency"
))
correlation_df$ Age <- scale (correlation_df$ Age)
corr_1 <- correlation (correlation_df, bayesian = TRUE , method = "auto" )
saveRDS (corr_1, "corr_1.rds" )
```
```{r}
#| eval: true
#| echo: true
#| collapse: true
summary (corr_1)
```