In this second part, I will work through the statistical tests for each hypothesis.

As before, I will import my packages.

library(tidyverse)
library(broom)

library(flextable)

library(lavaan)
library(semTools)

This time, I will also import an instance of a mock data set created in the previous part.

mydata <- read_csv(file.path("..", "github", "thesis", "mock.csv"))

# turn dataframe into html table
formatAsTable <- function(data) {
  data %>%
    mutate(across(where(is.double), ~ round(., 3))) %>%
    flextable %>%
    color(color = "white", part = "all")
}

mydata %>%
  head(5) %>%
  formatAsTable

Now we can move on to some actual analysis.

Note: Because I am working with latent variables comprising multiple items, I will be using structural equation modeling (SEM) with lavaan.

H1: Main Effects of Disclosure

This hypothesis has three components, corresponding to the effects of disclosure on:

  1. liking
  2. affective trust
  3. cognitive trust
# helper functions
regress <- function(..., data = mydata) {
  paste(..., sep = '\n') %>%
    sem(data)
}

paramTable <- function(fit) {
   fit %>%
    parameterEstimates %>%
    filter(!str_detect(rhs, "\\d")) %>%
    formatAsTable
}

H1a: Disclosure increases liking

# measurement model for liking
lik <- 'lik =~ lik1 + lik2 + lik3 + lik4'

# structural model for disclosure and liking
dis.lik <- "lik ~ disclose"

regress(lik, dis.lik) %>%
  paramTable

H1b: Disclosure increases affective trust

# measurement model for affective trust
aff <- 'aff =~ aff1 + aff2 + aff3 + aff4'

# structural model for disclosure and affective trust
dis.aff <- 'aff ~ disclose'

regress(aff, dis.aff) %>%
  paramTable

H1c: Disclosure decreases cognitive trust

# measurement model for cognitive trust
cog <- 'cog =~ cog1 + cog2 + cog3 + cog4'

# structural model for disclosure and cognitive trust
dis.cog <- 'cog ~ disclose'

regress(cog, dis.cog) %>%
  paramTable

H2: Main effects of interdependence

As before, I will examine the effect of interdependence on:

  1. liking
  2. affective trust
  3. cognitive trust

H2a: Interdependence increases liking

# structural model for interdependence and liking
int.lik <- 'lik ~ interdep'

regress(lik, int.lik) %>%
  paramTable

H2b: Interdependence increases affective trust

# structural model for interdependence and affective trust
int.aff <- 'aff ~ interdep'

regress(aff, int.aff) %>%
  paramTable

H2c: Interdependence increases cognitive trust

# structural model for interdependence and liking
int.cog <- 'cog ~ interdep'

regress(cog, int.cog) %>%
  paramTable

H3: Moderation by interdependence

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:

  1. disclosure, non-interdependent
  2. non-disclosure, interdependent
  3. non-disclosure, non-interdependent
  4. disclosure, interdependent
mydata <- mydata %>%
  mutate(likpred = lavPredict(cfa(lik, .)))

mydata %>%
  group_by(disclose, interdep) %>%
  summarise(liking = mean(likpred),
            t = t.test(likpred)$statistic,
            p = t.test(likpred)$p.value) %>%
  arrange(desc(liking))  %>%
  formatAsTable

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
mydata <- mydata %>%
  mutate(discent = disclose - .5,
         intcent = interdep - .5,
         intdis = discent * intcent)

# structural model for moderation by interdependence
dis.lik.int <- 'lik ~ discent + intcent + intdis'

interact.fit <- regress(lik, dis.lik.int)

interact.fit %>%
  paramTable

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.

params <- interact.fit %>%
  parameterEstimates %>%
  filter(op == '~') %>%
  select('est')

simple.effects <- tibble(
  independent = params[1,] + params[3,] * -.5,
  interdependent = params[1,] + params[3,] * .5
)

simple.effects %>%
  formatAsTable

H4: Mediation by trust

The final hypothesis has two components:

  1. When interdependence is low, affective trust will mediate the positive effect of disclosure on liking.
  2. When interdependence is high, cognitive trust will mediate the negative effect of disclosure on liking.

To evaluate these hypotheses, I need to subset the data into two sets: one where interdependence is low and one where it is high.

lo.int <- mydata %>%
  filter(interdep == 0)

hi.int <- mydata %>%
  filter(interdep == 1)

H4a: Mediation by affective trust when interdependence is low

fit.4a <- regress(aff, lik,
                  "lik ~ cprime*disclose",
                  "aff ~ a*disclose",
                  "lik ~ b*aff",
                  "ab := a*b",
                  "total := cprime + (a*b)",
                  data = lo.int)

fit.4a %>%
  paramTable

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.

H4b: Mediation by cognitive trust

fit.4b <- hi.int %>%
  regress(cog, lik,
          "lik ~ cprime*disclose",
          "cog ~ a*disclose",
          "lik ~ b*cog",
          "ab := a*b",
          "total := cprime + (a*b)",
          data = .)

fit.4b %>%
  paramTable

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.

Complete Model

Finally, I will build a full, theory-based structural model of all the variables in the study.

Causal path model (so-called “boxes-and-arrows”) for this study.

med.fit <- regress(aff, cog, lik,
                   "cog ~ discent + intcent + intdis",
                   "aff ~ discent",
                   "lik ~ cog + aff + intcent")

med.fit %>%
  paramTable

Output document:

rmarkdown::render("tests.Rmd", output_dir = file.path("..", "github", "thesis"))