---
title: Power motivations and sexual risk-taking
date: "March 22nd, 2023"
toc: true
number-depth: 3
code-scroll: true
code-line-numbers: true
df-print: kable
format:
html:
html-math-method: katex
code-tools: true
self-contained: true
latex: true
code-fold: true
code-summary: "Show the code"
execute:
warning: false
---
```{css}
/* APA Style */
. table > thead> tr> th {
border- color: black;
}
/** Remove borders within the table body **/
. table > tbody> tr> td {
border: none;
}
/** Add a top border to the table header row **/
. table thead tr: first- child {
border- top: 2px solid black;
}
/** Add a bottom border to the table body **/
. table tbody tr: last- child {
border- bottom: 2px solid black;
}
/** Make the table header row a normal weight; not bold **/
. table th {
font- weight: normal;
}
/** Make the caption italic and black **/
. table caption {
font- style: italic;
color: black;
}
```
```{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" )
```
# Results
## Gender
```{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 = "Gender" ) +
scale_x_discrete (labels = c ("Male" , "Female" ), guide = "prism_offset" ) +
scale_y_continuous (breaks = seq (0 , 100 , 10 ), guide = "prism_offset" ) +
theme_apa ()
```
## Analysis Priors
```{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" )
)
m2_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 = "PNI_Vulnerability_z" , resp = "SRTBRiskz" ),
prior (normal (0 , 1 ), coef = "PNI_Grandiosity_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 = "PNI_Vulnerability_z" , resp = "SRTBBenefitz" ),
prior (normal (0 , 1 ), coef = "PNI_Grandiosity_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 = "PNI_Vulnerability_z" , resp = "SRTBFrequencyz" ),
prior (normal (0 , 1 ), coef = "PNI_Grandiosity_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 = "PNI_Vulnerability_z" , resp = "SRTBLikelihoodz" ),
prior (normal (0 , 1 ), coef = "PNI_Grandiosity_z" , resp = "SRTBLikelihoodz" ),
prior (normal (0 , 1 ), class = "Intercept" , resp = "SRTBLikelihoodz" ),
prior (normal (0 , 1 ), class = "sigma" , resp = "SRTBLikelihoodz" )
)
```
## Models
### 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"
)
```
### Summary of m1
```{r}
#| eval: true
#| label: tbl-SRTBDoPLPNI
#| echo: true
#| collapse: true
summary (m1)
```
```{r}
#| label: tbl-SRTBDoPL
#| echo: FALSE
#| tbl-cap: "Experiment 1 | Bayesian regression of individual SRTB domains as response and dominance, prestige, leadership, and pathlogical narcissism as predictors."
#| out.width: "6in"
#| out.height: "6in"
knitr:: include_graphics ("../tbl-SRTBDoPL_1-1.png" )
```
## Multi model with dopl and pni as predictor variables and interaction terms
```{r}
#| eval: false
#| 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"
)
```
### Summary of the m1_interaction model
```{r}
#| eval: true
#| echo: true
#| collapse: true
summary (m1_interaction)
```
```{r}
#| label: tbl-SRTBDoPL_interaction
#| echo: false
#| tbl-cap: "Experiment 1 | Bayesian regression of individual SRTB domains as response and dominance, prestige, leadership, and pathlogical narcissism as predictors with gender interactions."
#| out.width: "6in"
#| out.height: "6in"
knitr:: include_graphics ("../tbl_SRTBDoPL_interaction-1.png" )
```
## m1 model comparison
### loo comparison
```{r}
#| eval: false
#| echo: true
#| collapse: true
m1_comparison <- loo (m1, m1_interaction)
```
```{r}
#| eval: true
#| echo: true
m1_comparison
```
### bayes factor comparison
```{r}
#| collapse: true
#| eval: false
#| echo: true
comparison <- bayesfactor_models (m1, m1_interaction)
```
```{r}
#| eval: true
#| echo: true
comparison
```
```{r}
#| eval: false
#| label: code-SRTBDoPLPNI_2
#| echo: true
#| collapse: true
m2 <- brm (mvbind (SRTB_Likelihood_z, SRTB_Risk_z, SRTB_Benefit_z, SRTB_Frequency_z) ~ DoPL_Dominance_z + DoPL_Prestige_z + DoPL_Leadership_z + PNI_Grandiosity_z + PNI_Vulnerability_z + Age + Gender,
data = Experiment_4_Analysis_DF,
prior = m2_prior,
iter = 10000 ,
warmup = 1000 ,
chains = 4 ,
cores = parallel:: detectCores (),
save_pars = save_pars (all = TRUE ),
backend = "cmdstanr"
)
```
```{r}
#| eval: true
#| label: tbl-SRTBDoPLPNI_2
#| echo: true
#| collapse: true
summary (m2)
```
## Correlation
```{r}
#| eval: false
#| label: code-correlation
#| echo: true
#| collapse: true
correlation_df <- MutateColumns:: column_mutation (Experiment_4_Analysis_DF)
correlation_df <- subset (correlation_df, select = c (
"Age" ,
"Dominance" ,
"Leadership" ,
"Prestige" ,
"B PNI" ,
"PNI Grandiosity" ,
"PNI Vulnerability" ,
"UMS" ,
"UMS Intimacy" ,
"UMS Affiliation" ,
"SRTB Risk Benefit" ,
"SRTB Risk Perception" ,
"SRTB Risk Likelihood" ,
"SRTB Risk Frequency"
))
correlation_df$ Age <- scale (correlation_df$ Age)
corr_1 <- correlation (correlation_df, bayesian = TRUE , method = "auto" )
saveRDS (corr_1, "corr_1.rds" )
```
### Correlation Summary
```{r}
#| eval: true
#| echo: true
#| label: tbl-correlation
#| out.width: "6in"
#| out.height: "6in"
knitr:: include_graphics ("../test-1.png" )
```