Load packages.
library(broom)
library(tidyverse)
library(flextable)
library(lavaan)
library(semTools)
Import data.
<- readRDS(file.path("..", "data", "hq-data.rds"))
adhd.data
<- readRDS("format.rds") formatAsTable
This hypothesis has three components, corresponding to the effects of disclosure on:
# helper functions
<- function(..., data = adhd.data) {
regress paste(..., sep = '\n') %>%
sem(data)
}
<- function(fit) {
paramTable %>%
fit %>%
parameterEstimates filter(!str_detect(rhs, "\\d")) %>%
formatAsTable }
# collapse lik1 categories
<- adhd.data %>%
adhd.data mutate(lik1 = fct_collapse(lik1,
disagree = c("Strongly disagree",
"Somewhat disagree")))
# measurement model for liking
<- 'lik =~ lik1 + lik2 + lik3.r + lik4.r'
lik
# structural model for disclosure and liking
<- "lik ~ disclose"
dis.lik
regress(lik, dis.lik) %>%
paramTable
lhs | op | rhs | est | se | z | pvalue | ci.lower | ci.upper |
lik | ~ | disclose | 0.48 | 0.10 | 4.64 | 0.00 | 0.27 | 0.68 |
lik | ~~ | lik | 0.69 | 0.05 | 15.32 | 0.00 | 0.60 | 0.78 |
disclose | ~~ | disclose | 0.25 | 0.00 | 0.25 | 0.25 | ||
lik1 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
lik2 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
lik3.r | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
lik4.r | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
disclose | ~1 | 0.52 | 0.00 | 0.52 | 0.52 | |||
lik | ~1 | 0.00 | 0.00 | 0.00 | 0.00 |
# measurement model for affective trust
<- 'aff =~ aff1 + aff2 + aff3 + aff4'
aff
# structural model for disclosure and affective trust
<- 'aff ~ disclose'
dis.aff
regress(aff, dis.aff) %>%
paramTable
lhs | op | rhs | est | se | z | pvalue | ci.lower | ci.upper |
aff | ~ | disclose | 0.68 | 0.09 | 7.35 | 0.00 | 0.50 | 0.86 |
aff | ~~ | aff | 0.62 | 0.04 | 16.69 | 0.00 | 0.55 | 0.70 |
disclose | ~~ | disclose | 0.25 | 0.00 | 0.25 | 0.25 | ||
aff1 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
aff2 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
aff3 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
aff4 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
disclose | ~1 | 0.52 | 0.00 | 0.52 | 0.52 | |||
aff | ~1 | 0.00 | 0.00 | 0.00 | 0.00 |
# measurement model for cognitive trust
<- 'cog =~ cog1 + cog2 + cog3'
cog
# structural model for disclosure and cognitive trust
<- 'cog ~ disclose'
dis.cog
regress(cog, dis.cog) %>%
paramTable
lhs | op | rhs | est | se | z | pvalue | ci.lower | ci.upper |
cog | ~ | disclose | 0.27 | 0.10 | 2.73 | 0.01 | 0.08 | 0.46 |
cog | ~~ | cog | 0.63 | 0.06 | 11.05 | 0.00 | 0.52 | 0.75 |
disclose | ~~ | disclose | 0.25 | 0.00 | 0.25 | 0.25 | ||
cog1 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
cog2 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
cog3 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
disclose | ~1 | 0.52 | 0.00 | 0.52 | 0.52 | |||
cog | ~1 | 0.00 | 0.00 | 0.00 | 0.00 |
As before, I will examine the effect of interdependence on:
# structural model for interdependence and liking
<- 'lik ~ interdep'
int.lik
regress(lik, int.lik) %>%
paramTable
lhs | op | rhs | est | se | z | pvalue | ci.lower | ci.upper |
lik | ~ | interdep | 0.21 | 0.10 | 2.07 | 0.04 | 0.01 | 0.41 |
lik | ~~ | lik | 0.72 | 0.04 | 16.75 | 0.00 | 0.64 | 0.81 |
interdep | ~~ | interdep | 0.25 | 0.00 | 0.25 | 0.25 | ||
lik1 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
lik2 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
lik3.r | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
lik4.r | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
interdep | ~1 | 0.49 | 0.00 | 0.49 | 0.49 | |||
lik | ~1 | 0.00 | 0.00 | 0.00 | 0.00 |
# structural model for interdependence and affective trust
<- 'aff ~ interdep'
int.aff
regress(aff, int.aff) %>%
paramTable
lhs | op | rhs | est | se | z | pvalue | ci.lower | ci.upper |
aff | ~ | interdep | 0.64 | 0.10 | 6.50 | 0.00 | 0.45 | 0.83 |
aff | ~~ | aff | 0.68 | 0.04 | 18.68 | 0.00 | 0.61 | 0.75 |
interdep | ~~ | interdep | 0.25 | 0.00 | 0.25 | 0.25 | ||
aff1 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
aff2 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
aff3 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
aff4 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
interdep | ~1 | 0.49 | 0.00 | 0.49 | 0.49 | |||
aff | ~1 | 0.00 | 0.00 | 0.00 | 0.00 |
# structural model for interdependence and liking
<- 'cog ~ interdep'
int.cog
regress(cog, int.cog) %>%
paramTable
lhs | op | rhs | est | se | z | pvalue | ci.lower | ci.upper |
cog | ~ | interdep | 0.08 | 0.10 | 0.79 | 0.43 | -0.11 | 0.27 |
cog | ~~ | cog | 0.61 | 0.05 | 11.28 | 0.00 | 0.50 | 0.72 |
interdep | ~~ | interdep | 0.25 | 0.00 | 0.25 | 0.25 | ||
cog1 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
cog2 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
cog3 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
interdep | ~1 | 0.49 | 0.00 | 0.49 | 0.49 | |||
cog | ~1 | 0.00 | 0.00 | 0.00 | 0.00 |
Now I will introduce interdependence as a moderator of the relationship between disclosure and liking.
Before doing anything too fancy, I’m going to look at the mean predicted value of liking for each condition. If the hypotheses are to be supported we want to see something like the following ranking:
<- adhd.data %>%
adhd.data mutate(likpred = lavPredict(cfa(lik, .)))
%>%
adhd.data group_by(disclose, interdep) %>%
summarise(liking = mean(likpred),
t = t.test(likpred)$statistic,
p = t.test(likpred)$p.value) %>%
arrange(desc(liking)) %>%
formatAsTable
disclose | interdep | liking | t | p |
TRUE | TRUE | 0.25 | 3.44 | 0.00 |
TRUE | FALSE | 0.07 | 1.04 | 0.30 |
FALSE | TRUE | -0.06 | -0.65 | 0.52 |
FALSE | FALSE | -0.33 | -4.91 | 0.00 |
In the next step, I will zero-center the elements of the product term, create the product term, and fit a regression model.
# create mean-centered product term
<- adhd.data %>%
adhd.data mutate(discent = disclose - .5,
intcent = interdep - .5,
intdis = interdep * disclose)
# structural model for moderation by interdependence
<- 'lik ~ disclose + interdep + intdis'
dis.lik.int
<- regress(lik, dis.lik.int)
interact.fit
%>%
interact.fit paramTable
lhs | op | rhs | est | se | z | pvalue | ci.lower | ci.upper |
lik | ~ | disclose | 0.52 | 0.14 | 3.67 | 0.00 | 0.24 | 0.81 |
lik | ~ | interdep | 0.27 | 0.15 | 1.84 | 0.07 | -0.02 | 0.56 |
lik | ~ | intdis | -0.08 | 0.20 | -0.38 | 0.70 | -0.47 | 0.32 |
lik | ~~ | lik | 0.70 | 0.04 | 15.76 | 0.00 | 0.61 | 0.78 |
disclose | ~~ | disclose | 0.25 | 0.00 | 0.25 | 0.25 | ||
disclose | ~~ | interdep | -0.01 | 0.00 | -0.01 | -0.01 | ||
disclose | ~~ | intdis | 0.12 | 0.00 | 0.12 | 0.12 | ||
interdep | ~~ | interdep | 0.25 | 0.00 | 0.25 | 0.25 | ||
interdep | ~~ | intdis | 0.13 | 0.00 | 0.13 | 0.13 | ||
intdis | ~~ | intdis | 0.19 | 0.00 | 0.19 | 0.19 | ||
lik1 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
lik2 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
lik3.r | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
lik4.r | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
disclose | ~1 | 0.52 | 0.00 | 0.52 | 0.52 | |||
interdep | ~1 | 0.49 | 0.00 | 0.49 | 0.49 | |||
intdis | ~1 | 0.25 | 0.00 | 0.25 | 0.25 | |||
lik | ~1 | 0.00 | 0.00 | 0.00 | 0.00 |
Let’s look at the simple slopes. Recall that this is the effect of disclosure on liking either in or not in the context of interdependence.
<- interact.fit %>%
params %>%
parameterEstimates filter(op == '~') %>%
select('est')
<- tibble(
simple.effects independent = params[1,] + params[3,] * -.5,
interdependent = params[1,] + params[3,] * .5
)
%>%
simple.effects formatAsTable
independent | interdependent |
0.56 | 0.49 |
The final hypothesis has two components:
To evaluate these hypotheses, I need to subset the data into two sets: one where interdependence is low and one where it is high.
<- adhd.data %>%
lo.int filter(interdep == 0)
<- adhd.data %>%
hi.int filter(interdep == 1)
.4a <- regress(aff, lik,
fit"lik ~ cprime*disclose",
"aff ~ a*disclose",
"lik ~ b*aff",
"ab := a*b",
"total := cprime + (a*b)",
data = lo.int)
.4a %>%
fit paramTable
lhs | op | rhs | label | est | se | z | pvalue | ci.lower | ci.upper |
lik | ~ | disclose | cprime | -0.02 | 0.16 | -0.15 | 0.88 | -0.33 | 0.29 |
aff | ~ | disclose | a | 0.93 | 0.13 | 6.97 | 0.00 | 0.67 | 1.19 |
lik | ~ | aff | b | 0.72 | 0.07 | 10.62 | 0.00 | 0.59 | 0.85 |
aff | ~~ | aff | 0.63 | 0.06 | 11.32 | 0.00 | 0.52 | 0.74 | |
lik | ~~ | lik | 0.53 | 0.07 | 7.08 | 0.00 | 0.38 | 0.68 | |
disclose | ~~ | disclose | 0.25 | 0.00 | 0.25 | 0.25 | |||
aff1 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
aff2 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
aff3 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
aff4 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
lik1 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
lik2 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
lik3.r | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
lik4.r | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
disclose | ~1 | 0.53 | 0.00 | 0.53 | 0.53 | ||||
aff | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
lik | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
ab | := | a*b | ab | 0.67 | 0.11 | 6.27 | 0.00 | 0.46 | 0.88 |
total | := | cprime+(a*b) | total | 0.64 | 0.16 | 3.98 | 0.00 | 0.33 | 0.96 |
To show mediation, we want to see that the total effect (\(c\)), the effect on the mediator (\(a\)), and the effect of the mediator (\(b\)) are significantly different from 0 but that the main effect (\(c\prime\)) is zero.
.4b <- hi.int %>%
fitregress(cog, lik,
"lik ~ cprime*disclose",
"cog ~ a*disclose",
"lik ~ b*cog",
"ab := a*b",
"total := cprime + (a*b)",
data = .)
.4b %>%
fit paramTable
lhs | op | rhs | label | est | se | z | pvalue | ci.lower | ci.upper |
lik | ~ | disclose | cprime | 0.21 | 0.12 | 1.68 | 0.09 | -0.03 | 0.45 |
cog | ~ | disclose | a | 0.29 | 0.16 | 1.84 | 0.07 | -0.02 | 0.59 |
lik | ~ | cog | b | 0.74 | 0.05 | 14.58 | 0.00 | 0.64 | 0.84 |
cog | ~~ | cog | 0.86 | 0.05 | 18.56 | 0.00 | 0.77 | 0.96 | |
lik | ~~ | lik | 0.27 | 0.05 | 5.68 | 0.00 | 0.18 | 0.37 | |
disclose | ~~ | disclose | 0.25 | 0.00 | 0.25 | 0.25 | |||
cog1 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
cog2 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
cog3 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
lik1 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
lik2 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
lik3.r | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
lik4.r | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
disclose | ~1 | 0.51 | 0.00 | 0.51 | 0.51 | ||||
cog | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
lik | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | ||||
ab | := | a*b | ab | 0.21 | 0.12 | 1.83 | 0.07 | -0.01 | 0.44 |
total | := | cprime+(a*b) | total | 0.42 | 0.15 | 2.80 | 0.01 | 0.13 | 0.72 |
Just as in the previous analysis, to show mediation, we need to find that the total effect (\(c\)), \(a\), and \(b\) are significantly different from zero but that the main effect (\(c\prime\)) is equal to zero.
Finally, I will build a full, theory-based structural model of all the variables in the study.
<- regress(aff, cog, lik,
med.fit "cog ~ disclose + interdep + intdis",
"aff ~ disclose",
"lik ~ cog + aff + interdep")
%>%
med.fit paramTable
lhs | op | rhs | est | se | z | pvalue | ci.lower | ci.upper |
cog | ~ | disclose | 0.12 | 0.13 | 0.93 | 0.35 | -0.14 | 0.38 |
cog | ~ | interdep | 0.14 | 0.16 | 0.86 | 0.39 | -0.17 | 0.45 |
cog | ~ | intdis | -0.06 | 0.22 | -0.28 | 0.78 | -0.49 | 0.37 |
aff | ~ | disclose | 0.79 | 0.11 | 7.38 | 0.00 | 0.58 | 1.00 |
lik | ~ | cog | 0.77 | 0.05 | 16.53 | 0.00 | 0.68 | 0.86 |
lik | ~ | aff | 0.86 | 0.05 | 18.96 | 0.00 | 0.77 | 0.95 |
lik | ~ | interdep | 0.21 | 0.13 | 1.62 | 0.10 | -0.04 | 0.47 |
aff | ~~ | aff | 0.57 | 0.04 | 13.50 | 0.00 | 0.49 | 0.66 |
cog | ~~ | cog | 0.83 | 0.04 | 18.72 | 0.00 | 0.75 | 0.92 |
lik | ~~ | lik | -0.11 | 0.06 | -1.71 | 0.09 | -0.23 | 0.02 |
disclose | ~~ | disclose | 0.25 | 0.00 | 0.25 | 0.25 | ||
disclose | ~~ | interdep | -0.01 | 0.00 | -0.01 | -0.01 | ||
disclose | ~~ | intdis | 0.12 | 0.00 | 0.12 | 0.12 | ||
interdep | ~~ | interdep | 0.25 | 0.00 | 0.25 | 0.25 | ||
interdep | ~~ | intdis | 0.13 | 0.00 | 0.13 | 0.13 | ||
intdis | ~~ | intdis | 0.19 | 0.00 | 0.19 | 0.19 | ||
aff1 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
aff2 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
aff3 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
aff4 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
cog1 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
cog2 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
cog3 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
lik1 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
lik2 | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
lik3.r | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
lik4.r | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
disclose | ~1 | 0.52 | 0.00 | 0.52 | 0.52 | |||
interdep | ~1 | 0.49 | 0.00 | 0.49 | 0.49 | |||
intdis | ~1 | 0.25 | 0.00 | 0.25 | 0.25 | |||
aff | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
cog | ~1 | 0.00 | 0.00 | 0.00 | 0.00 | |||
lik | ~1 | 0.00 | 0.00 | 0.00 | 0.00 |
Save data:
%>%
adhd.data saveRDS(file.path("..", "data", "adhd-data.rds"))
%>%
adhd.data write_csv(file.path("..", "data", "adhd-data.csv"))
%>%
adhd.data.hq saveRDS(file.path("..", "data", "hq-data.rds"))
%>%
adhd.data.hq write_csv(file.path("..", "data", "hq-data.rds"))
Output document:
options(knitr.duplicate.label = "allow")
::render("inferences-hq-nocog4.Rmd",
rmarkdownoutput_dir = file.path("..", "github", "thesis"))