Setup

Setup Overview

See tabs for loading libraries, loading dataset etc.

Libraries

Load Dataset

Load Functions

Rename Variables

Baseline Factor Analyses

Stress Mindsets

Health Growth Mindset

Activity Adequacy

Motivation

Social Support

PHQ

SF8

Descriptives

Demographics & Clinical Variables

baseline_demographics <- tableby(~ gender + ethnicity + age_group + bmi_t1 + initial_weight_t1 + prediabetes_risk_score_t1, data=t2, control=tableby.control(numeric.stats = c("meansd", "range")), cat.stats=c("countpct"))
summary(baseline_demographics, pfootnote=TRUE)
Overall (N=847)
gender
   Male 303 (35.8%)
   Female 544 (64.2%)
ethnicity
   American Indian 5 (0.6%)
   Asian 50 (5.9%)
   Black 84 (9.9%)
   Hispanic 124 (14.6%)
   Other 25 (3.0%)
   Pacific Islander 4 (0.5%)
   No Response 19 (2.2%)
   White 536 (63.3%)
age_group
   18-29 106 (14.0%)
   30-39 208 (27.4%)
   40-49 208 (27.4%)
   50-59 179 (23.6%)
   >60 57 (7.5%)
bmi_t1
   Mean (SD) 33.773 (6.821)
   Range 22.466 - 63.764
initial_weight_t1
   Mean (SD) 214.409 (48.075)
   Range 125.000 - 456.000
prediabetes_risk_score_t1
   Mean (SD) 11.383 (3.215)
   Range 0.000 - 19.000

Omada Engagement

baseline_meta <- tableby(~ lesson_count_t2 + coach_messages_sent_t2 + coach_messages_received_t2 + logins_t2 + meals_logged_t2 + physical_activity_steps_t2, data=t2, control=tableby.control(numeric.stats = c("meansd", "range")), cat.stats=c("countpct"))
summary(baseline_meta, pfootnote=TRUE)
Overall (N=847)
lesson_count_t2
   Mean (SD) 2.983 (3.244)
   Range 0.000 - 9.881
coach_messages_sent_t2
   Mean (SD) 2.878 (3.072)
   Range 0.000 - 9.881
coach_messages_received_t2
   Mean (SD) 3.334 (2.059)
   Range 0.000 - 9.881
logins_t2
   Mean (SD) 3.875 (2.777)
   Range 0.000 - 9.931
meals_logged_t2
   Mean (SD) 2.691 (2.394)
   Range 0.000 - 9.881
physical_activity_steps_t2
   Mean (SD) 3.036 (2.937)
   Range 0.000 - 9.967

Change Over Time

Change in Illness Mindsets

se <- function(x) sqrt(var(x)/length(x))

illmset_time <- t2 %>% 
  select(external_id, ill_catastrophe_t1, ill_catastrophe_t2, ill_manageable_t1, ill_manageable_t2, ill_opportunity_t1, ill_opportunity_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(ill_catastrophe_t1, ill_catastrophe_t2, ill_manageable_t1, ill_manageable_t2, ill_opportunity_t1, ill_opportunity_t2))%>% 
  mutate(Timepoint=
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2", 
              )) %>% 
  mutate(Mindset= as.factor(
    case_when(grepl("ill_catastrophe_t", name) ~ "Catastrophe",
              grepl("ill_manageable_t", name) ~ "Manageable",
              grepl("ill_opportunity_t", name) ~ "Opportunity"))) %>%
  group_by(Mindset, Timepoint) %>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Mindset' (override with `.groups` argument)
ill_mset_time_graph <- illmset_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, group=Mindset, color=Mindset)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("darkred", "deepskyblue4", "darkolivegreen"))+
    geom_point(shape=21, color="grey21", fill="grey21", size=2.5) +
    scale_y_continuous(limits=c(1, 6), breaks=c(1,2,3,4,5,6)) + 
    theme_minimal() + 
  theme(legend.position="bottom") + 
  theme(legend.text = element_text(color="grey21", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(ill_mset_time_graph)

#Catastrophe Mindset

imi_cat_time <- t2 %>% 
  select(external_id, ill_catastrophe_t1, ill_catastrophe_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(ill_catastrophe_t1, ill_catastrophe_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Mindset= as.factor(
    case_when(grepl("ill_catastrophe_t", name) ~ "Catastrophe Mindset"))) %>%
  group_by(Mindset, Timepoint)

mindset_comparisons <- list(c("Baseline", "T2"))

imi_cat_time_plot <- imi_cat_time %>%
ggplot(aes(x=Timepoint, y=value, fill=Timepoint)) +  
  geom_boxplot(outlier.shape = NA) + 
  expand_limits(y = 1) +
  scale_y_continuous(breaks=c(1,2,3,4,5,6)) +
  stat_summary(fun=mean, geom="point", colour="black", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=2.5, show.legend = FALSE, 
               vjust=2.2, aes(label=round(..y.., digits=2))) +
  stat_compare_means(aes(x=Timepoint, y=value), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Catastrophe Mindset",x="Timepoint", y = "Agreement") +
  scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))

print(imi_cat_time_plot)

#Manageable Mindset
imi_man_time <- t2 %>% 
  select(external_id, ill_manageable_t1, ill_manageable_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(ill_manageable_t1, ill_manageable_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Mindset= as.factor(
    case_when(grepl("ill_manageable_t", name) ~ "Manageable Mindset"))) %>%
  group_by(Mindset, Timepoint)

imi_man_time_plot <- imi_man_time %>%
ggplot(aes(x=Timepoint, y=value, fill=Timepoint)) +  
  geom_boxplot(outlier.shape = NA) + 
  expand_limits(y = 1) +
  scale_y_continuous(breaks=c(1,2,3,4,5,6)) +
  stat_summary(fun=mean, geom="point", colour="black", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=2.5, show.legend = FALSE, 
               vjust=2.2, aes(label=round(..y.., digits=2))) +
  stat_compare_means(aes(x=Timepoint, y=value), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Manageable Mindset",x="Timepoint", y = "Agreement") +
  scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))

print(imi_man_time_plot)

#Opportunity Mindset
imi_opp_time <- t2 %>% 
  select(external_id, ill_opportunity_t1, ill_opportunity_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(ill_opportunity_t1, ill_opportunity_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Mindset= as.factor(
    case_when(grepl("ill_opportunity_t", name) ~ "Opportunity Mindset"))) %>%
  group_by(Mindset, Timepoint)

imi_opp_time_plot <- imi_opp_time %>%
ggplot(aes(x=Timepoint, y=value, fill=Timepoint)) +  
  geom_boxplot(outlier.shape = NA) + 
  expand_limits(y = 1) +
  scale_y_continuous(breaks=c(1,2,3,4,5,6)) +
  stat_summary(fun=mean, geom="point", colour="black", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=2.5, show.legend = FALSE, 
               vjust=2.2, aes(label=round(..y.., digits=2))) +
  stat_compare_means(aes(x=Timepoint, y=value), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Opportunity Mindset",x="Timepoint", y = "Agreement") +
  scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))

print(imi_opp_time_plot)

Change in Body Mindsets

se <- function(x) sqrt(var(x)/length(x))

bodmset_time <- t2 %>% 
  select(external_id, body_adversary_t1, body_adversary_t2, body_capable_t1, body_capable_t2, body_responsive_t1, body_responsive_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(body_adversary_t1, body_adversary_t2, body_capable_t1, body_capable_t2, body_responsive_t1, body_responsive_t2))%>% 
  mutate(Timepoint=
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2", 
              )) %>% 
  mutate(Mindset= as.factor(
    case_when(grepl("body_adversary_t", name) ~ "Adversary",
              grepl("body_capable_t", name) ~ "Capable",
              grepl("body_responsive_t", name) ~ "Responsive"))) %>%
  group_by(Mindset, Timepoint) %>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Mindset' (override with `.groups` argument)
bodmset_time_graph <- bodmset_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, group=Mindset, color=Mindset)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("darkred", "deepskyblue4", "darkolivegreen"))+
    geom_point(shape=21, color="grey21", fill="grey21", size=2.5) +
    scale_y_continuous(limits=c(1, 6), breaks=c(1,2,3,4,5,6)) + 
    theme_minimal() + 
  theme(legend.position="bottom") + 
  theme(legend.text = element_text(color="grey21", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(bodmset_time_graph)

#Body Adversary Mindset
bmi_adv_time <- t2 %>% 
  select(external_id, body_adversary_t1, body_adversary_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(body_adversary_t1, body_adversary_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Mindset= as.factor(
    case_when(grepl("body_adversary_t", name) ~ "Body Adversary Mindset"))) %>%
  group_by(Mindset, Timepoint)

bmi_adv_time_plot <- bmi_adv_time %>%
ggplot(aes(x=Timepoint, y=value, fill=Timepoint)) +  
  geom_boxplot(outlier.shape = NA) + 
  expand_limits(y = 1) +
  scale_y_continuous(breaks=c(1,2,3,4,5,6)) +
  stat_summary(fun=mean, geom="point", colour="black", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=2.5, show.legend = FALSE, 
               vjust=2.2, aes(label=round(..y.., digits=2))) +
  stat_compare_means(aes(x=Timepoint, y=value), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Body Adversary Mindset",x="Timepoint", y = "Agreement") +
  scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))

print(bmi_adv_time_plot)

#Body Capable Mindset
bmi_cap_time <- t2 %>% 
  select(external_id, body_capable_t1, body_capable_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(body_capable_t1, body_capable_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Mindset= as.factor(
    case_when(grepl("body_capable_t", name) ~ "Body Capable Mindset"))) %>%
  group_by(Mindset, Timepoint)

bmi_cap_time_plot <- bmi_cap_time %>%
ggplot(aes(x=Timepoint, y=value, fill=Timepoint)) +  
  geom_boxplot(outlier.shape = NA) + 
  expand_limits(y = 1) +
  scale_y_continuous(breaks=c(1,2,3,4,5,6)) +
  stat_summary(fun=mean, geom="point", colour="black", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=2.5, show.legend = FALSE, 
               vjust=2.2, aes(label=round(..y.., digits=2))) +
  stat_compare_means(aes(x=Timepoint, y=value), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Body Capable Mindset",x="Timepoint", y = "Agreement") +
  scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))

print(bmi_cap_time_plot)

#Body Responsive Mindset
bmi_resp_time <- t2 %>% 
  select(external_id, body_responsive_t1, body_responsive_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(body_responsive_t1, body_responsive_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Mindset= as.factor(
    case_when(grepl("body_responsive_t", name) ~ "Body Responsive Mindset"))) %>%
  group_by(Mindset, Timepoint)

bmi_resp_time_plot <- bmi_resp_time %>%
ggplot(aes(x=Timepoint, y=value, fill=Timepoint)) +  
  geom_boxplot(outlier.shape = NA) + 
  expand_limits(y = 1) +
  scale_y_continuous(breaks=c(1,2,3,4,5,6)) +
  stat_summary(fun=mean, geom="point", colour="black", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=2.5, show.legend = FALSE, 
               vjust=2.2, aes(label=round(..y.., digits=2))) +
  stat_compare_means(aes(x=Timepoint, y=value), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Body Responsive Mindset",x="Timepoint", y = "Agreement") +
  scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))

print(bmi_resp_time_plot)

Change in Process Mindsets

se <- function(x) sqrt(var(x)/length(x))

process_time <- t2 %>% 
  select(external_id, process_difficult_t1, process_difficult_t2, process_unpleasant_t1, process_unpleasant_t2, process_stressful_t1, process_stressful_t2, process_inconvenient_t1, process_inconvenient_t2, process_boring_t1, process_boring_t2, process_lonely_t1, process_lonely_t2, process_depriving_t1, process_depriving_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(process_difficult_t1, process_difficult_t2, process_unpleasant_t1, process_unpleasant_t2, process_stressful_t1, process_stressful_t2, process_inconvenient_t1, process_inconvenient_t2, process_boring_t1, process_boring_t2, process_lonely_t1, process_lonely_t2, process_depriving_t1, process_depriving_t2))%>% 
  mutate(Timepoint=
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2", 
              )) %>% 
  mutate(Mindset=as.factor(
    case_when(grepl("process_difficult_t", name) ~ "Difficult",
              grepl("process_unpleasant_t", name) ~ "Unpleasant",
              grepl("process_stressful_t", name) ~ "Stressful",
              grepl("process_inconvenient_t", name) ~ "Inconvenient",
              grepl("process_boring_t", name) ~ "Boring",
              grepl("process_lonely_t", name) ~ "Lonely",
              grepl("process_depriving_t", name) ~ "Depriving"))) %>%
  group_by(Mindset, Timepoint) %>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Mindset' (override with `.groups` argument)
process_time_graph <- process_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, group=Mindset, color=Mindset)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("darkred", "deepskyblue4", "darkolivegreen", "darkorchid4", "deeppink2", "firebrick1", "orange2"))+
    geom_point(shape=21, color="grey21", fill="grey21", size=2.5) +
    scale_y_continuous(limits=c(1.5, 3), breaks=c(1.5,1.75,2,2.25,2.5,2.75,3)) + 
    theme_minimal() + 
  theme(legend.position="bottom") + 
  theme(legend.text = element_text(color="grey21", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(process_time_graph)

#Process Difficult Mindset
process_difficult_time <- t2 %>% 
  select(external_id, process_difficult_t1, process_difficult_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(process_difficult_t1, process_difficult_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Mindset= as.factor(
    case_when(grepl("process_difficult_t", name) ~ "Process Difficult"))) %>%
  group_by(Mindset, Timepoint)%>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Mindset' (override with `.groups` argument)
process_difficult_time_plot <- process_difficult_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, color=Mindset)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("darkolivegreen"))+
    geom_point(shape=21, color="grey21", fill="grey21", size=2.5) +
    scale_y_continuous(limits=c(1.5, 3), breaks=c(1.5,1.75,2,2.25,2.5,2.75,3)) + 
    theme_minimal() + 
   stat_summary(fun=mean, geom="point", colour="black", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=4, show.legend = FALSE, 
               vjust=-4, aes(label=round(..y.., digits=2))) +
    stat_compare_means(aes(x=Timepoint, y=Agreement), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Process Difficult Mindset",x="Timepoint", y = "Agreement") + 
 scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(process_difficult_time_plot)
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

#Process Unpleasant Mindset
process_unpleasant_time <- t2 %>% 
  select(external_id, process_unpleasant_t1, process_unpleasant_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(process_unpleasant_t1, process_unpleasant_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Mindset= as.factor(
    case_when(grepl("process_unpleasant_t", name) ~ "Process Unpleasant"))) %>%
  group_by(Mindset, Timepoint)%>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Mindset' (override with `.groups` argument)
process_unpleasant_time_plot <- process_unpleasant_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, color=Mindset)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("orange2"))+
    geom_point(shape=21, color="orange2", fill="orange2", size=2.5) +
    scale_y_continuous(limits=c(1.5, 3), breaks=c(1.5,1.75,2,2.25,2.5,2.75,3)) + 
    theme_minimal() + 
   stat_summary(fun=mean, geom="point", colour="orange2", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=4, show.legend = FALSE, 
               vjust=-4, aes(label=round(..y.., digits=2))) +
    stat_compare_means(aes(x=Timepoint, y=Agreement), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Process Unpleasant Mindset",x="Timepoint", y = "Agreement") + 
 scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(process_unpleasant_time_plot)
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

#Process Stressful Mindset
process_stressful_time <- t2 %>% 
  select(external_id, process_stressful_t1, process_stressful_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(process_stressful_t1, process_stressful_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Mindset= as.factor(
    case_when(grepl("process_stressful_t", name) ~ "Process Stressful"))) %>%
  group_by(Mindset, Timepoint)%>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Mindset' (override with `.groups` argument)
process_stressful_time_plot <- process_stressful_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, color=Mindset)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("firebrick1"))+
    geom_point(shape=21, color="firebrick1", fill="firebrick1", size=2.5) +
    scale_y_continuous(limits=c(1.5, 3), breaks=c(1.5,1.75,2,2.25,2.5,2.75,3)) + 
    theme_minimal() + 
   stat_summary(fun=mean, geom="point", colour="firebrick1", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=4, show.legend = FALSE, 
               vjust=-4, aes(label=round(..y.., digits=2))) +
    stat_compare_means(aes(x=Timepoint, y=Agreement), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Process Stressful Mindset",x="Timepoint", y = "Agreement") + 
 scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(process_stressful_time_plot)
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

#Process Inconvenient Mindset
process_inconvenient_time <- t2 %>% 
  select(external_id, process_inconvenient_t1, process_inconvenient_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(process_inconvenient_t1, process_inconvenient_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Mindset= as.factor(
    case_when(grepl("process_inconvenient_t", name) ~ "Process Inconvenient"))) %>%
  group_by(Mindset, Timepoint)%>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Mindset' (override with `.groups` argument)
process_inconvenient_time_plot <- process_inconvenient_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, color=Mindset)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("darkorchid4"))+
    geom_point(shape=21, color="darkorchid4", fill="darkorchid4", size=2.5) +
    scale_y_continuous(limits=c(1.5, 3), breaks=c(1.5,1.75,2,2.25,2.5,2.75,3)) + 
    theme_minimal() + 
   stat_summary(fun=mean, geom="point", colour="darkorchid4", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=4, show.legend = FALSE, 
               vjust=-4, aes(label=round(..y.., digits=2))) +
    stat_compare_means(aes(x=Timepoint, y=Agreement), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Process Inconvenient Mindset",x="Timepoint", y = "Agreement") + 
 scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(process_inconvenient_time_plot)
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

#Process boring Mindset
process_boring_time <- t2 %>% 
  select(external_id, process_boring_t1, process_boring_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(process_boring_t1, process_boring_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Mindset= as.factor(
    case_when(grepl("process_boring_t", name) ~ "Process Boring"))) %>%
  group_by(Mindset, Timepoint)%>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Mindset' (override with `.groups` argument)
process_boring_time_plot <- process_boring_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, color=Mindset)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("darkred"))+
    geom_point(shape=21, color="darkred", fill="darkred", size=2.5) +
    scale_y_continuous(limits=c(1.5, 3), breaks=c(1.5,1.75,2,2.25,2.5,2.75,3)) + 
    theme_minimal() + 
   stat_summary(fun=mean, geom="point", colour="darkred", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=4, show.legend = FALSE, 
               vjust=-4, aes(label=round(..y.., digits=2))) +
    stat_compare_means(aes(x=Timepoint, y=Agreement), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Process Boring Mindset",x="Timepoint", y = "Agreement") + 
 scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(process_boring_time_plot)
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

#Process Lonely Mindset
process_lonely_time <- t2 %>% 
  select(external_id, process_lonely_t1, process_lonely_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(process_lonely_t1, process_lonely_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Mindset= as.factor(
    case_when(grepl("process_lonely_t", name) ~ "Process Lonely"))) %>%
  group_by(Mindset, Timepoint)%>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Mindset' (override with `.groups` argument)
process_lonely_time_plot <- process_lonely_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, color=Mindset)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("deeppink2"))+
    geom_point(shape=21, color="deeppink2", fill="deeppink2", size=2.5) +
    scale_y_continuous(limits=c(1.5, 3), breaks=c(1.5,1.75,2,2.25,2.5,2.75,3)) + 
    theme_minimal() + 
   stat_summary(fun=mean, geom="point", colour="deeppink2", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=4, show.legend = FALSE, 
               vjust=-4, aes(label=round(..y.., digits=2))) +
    stat_compare_means(aes(x=Timepoint, y=Agreement), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Process Lonely Mindset",x="Timepoint", y = "Agreement") + 
 scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(process_lonely_time_plot)
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

#Process Depriving Mindset
process_depriving_time <- t2 %>% 
  select(external_id, process_depriving_t1, process_depriving_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(process_depriving_t1, process_depriving_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Mindset= as.factor(
    case_when(grepl("process_depriving_t", name) ~ "Process Depriving"))) %>%
  group_by(Mindset, Timepoint)%>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Mindset' (override with `.groups` argument)
process_depriving_time_plot <- process_depriving_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, color=Mindset)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("deepskyblue4"))+
    geom_point(shape=21, color="deepskyblue4", fill="deepskyblue4", size=2.5) +
    scale_y_continuous(limits=c(1.5, 3), breaks=c(1.5,1.75,2,2.25,2.5,2.75,3)) + 
    theme_minimal() + 
   stat_summary(fun=mean, geom="point", colour="deepskyblue4", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=4, show.legend = FALSE, 
               vjust=-4, aes(label=round(..y.., digits=2))) +
    stat_compare_means(aes(x=Timepoint, y=Agreement), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Process Depriving Mindset",x="Timepoint", y = "Agreement") + 
 scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(process_depriving_time_plot)
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

Change in Activity Mindsets

se <- function(x) sqrt(var(x)/length(x))

activity_time <- t2 %>% 
  select(external_id, activity_adequacy_mindset_t1, activity_adequacy_mindset_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(activity_adequacy_mindset_t1, activity_adequacy_mindset_t2))%>% 
  mutate(Timepoint=
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2", 
              )) %>% 
  mutate(Mindset=as.factor(
    case_when(grepl("activity_adequacy_mindset_t", name) ~ "Adequacy of Activity"))) %>%
  group_by(Mindset, Timepoint) %>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Mindset' (override with `.groups` argument)
activity_time_plot <- activity_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, color=Mindset)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("darkorchid4"))+
    geom_point(shape=21, color="grey21", fill="grey21", size=2.5) +
    scale_y_continuous(limits=c(1,6), breaks=c(1,2,3,4,5,6)) + 
    theme_minimal() + 
   stat_summary(fun=mean, geom="point", colour="black", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=4, show.legend = FALSE, 
               vjust=-4, aes(label=round(..y.., digits=2))) +
    stat_compare_means(aes(x=Timepoint, y=Agreement), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Activity Adequacy Mindset",x="Timepoint", y = "Agreement") + 
 scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(activity_time_plot)
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

Change in Health Growth Mindsets

se <- function(x) sqrt(var(x)/length(x))

growth_time <- t2 %>% 
  select(external_id, health_growth_mindset_t1, health_growth_mindset_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(health_growth_mindset_t1, health_growth_mindset_t2))%>% 
  mutate(Timepoint=
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2", 
              )) %>% 
  mutate(Mindset=as.factor(
    case_when(grepl("health_growth_mindset_t", name) ~ "Health Growth Mindset"))) %>%
  group_by(Mindset, Timepoint) %>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Mindset' (override with `.groups` argument)
growth_time_plot <- growth_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, color=Mindset)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("darkslateblue"))+
    geom_point(shape=21, color="grey21", fill="grey21", size=2.5) +
    scale_y_continuous(limits=c(1,6), breaks=c(1,2,3,4,5,6)) + 
    theme_minimal() + 
   stat_summary(fun=mean, geom="point", colour="darkslateblue", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=4, show.legend = FALSE, 
               vjust=-4, aes(label=round(..y.., digits=2))) +
    stat_compare_means(aes(x=Timepoint, y=Agreement), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Health Growth Mindset",x="Timepoint", y = "Agreement") + 
 scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(growth_time_plot)
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

Change in Stress Mindsets

se <- function(x) sqrt(var(x)/length(x))

stress_time <- t2 %>% 
  select(external_id, stress_enhancing_t1, stress_enhancing_t2, stress_debilitating_t1, stress_debilitating_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(stress_enhancing_t1, stress_enhancing_t2, stress_debilitating_t1, stress_debilitating_t2))%>% 
  mutate(Timepoint=
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2", 
              )) %>% 
  mutate(Mindset=as.factor(
    case_when(grepl("stress_enhancing_t", name) ~ "Enhancing",
              grepl("stress_debilitating_t", name) ~ "Debilitating"))) %>%
  group_by(Mindset, Timepoint) %>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Mindset' (override with `.groups` argument)
stress_time_graph <- stress_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, group=Mindset, color=Mindset)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("darkred", "deepskyblue4"))+
    geom_point(shape=21, color="grey21", fill="grey21", size=2.5) +
    scale_y_continuous(limits=c(1, 6), breaks=c(1,2,3,4,5,6)) + 
    theme_minimal() + 
  theme(legend.position="bottom") + 
  theme(legend.text = element_text(color="grey21", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(stress_time_graph)

#Stress Enhancing Mindset
stress_enhancing_time <- t2 %>% 
  select(external_id, stress_enhancing_t1, stress_enhancing_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(stress_enhancing_t1, stress_enhancing_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Mindset= as.factor(
    case_when(grepl("stress_enhancing_t", name) ~ "Enhancing"))) %>%
  group_by(Mindset, Timepoint)%>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Mindset' (override with `.groups` argument)
stress_enhancing_time_plot <- stress_enhancing_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, color=Mindset)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("deepskyblue4"))+
    geom_point(shape=21, color="grey21", fill="grey21", size=2.5) +
    scale_y_continuous(limits=c(1, 6), breaks=c(1,2,3,4,5,6)) + 
    theme_minimal() + 
   stat_summary(fun=mean, geom="point", colour="deepskyblue4", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=4, show.legend = FALSE, 
               vjust=-4, aes(label=round(..y.., digits=2))) +
    stat_compare_means(aes(x=Timepoint, y=Agreement), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Stress Enhancing Mindset",x="Timepoint", y = "Agreement") + 
 scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(stress_enhancing_time_plot)
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

#Stress Debilitating Mindset
stress_debilitating_time <- t2 %>% 
  select(external_id, stress_debilitating_t1, stress_debilitating_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(stress_debilitating_t1, stress_debilitating_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Mindset= as.factor(
    case_when(grepl("stress_debilitating_t", name) ~ "Debilitating"))) %>%
  group_by(Mindset, Timepoint)%>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Mindset' (override with `.groups` argument)
stress_debilitating_time_plot <- stress_debilitating_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, color=Mindset)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("darkred"))+
    geom_point(shape=21, color="darkred", fill="darkred", size=2.5) +
    scale_y_continuous(limits=c(1, 6), breaks=c(1,2,3,4,5,6)) + 
    theme_minimal() + 
   stat_summary(fun=mean, geom="point", colour="darkred", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=4, show.legend = FALSE, 
               vjust=-4, aes(label=round(..y.., digits=2))) +
    stat_compare_means(aes(x=Timepoint, y=Agreement), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Stress Debilitating Mindset",x="Timepoint", y = "Agreement") + 
 scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(stress_debilitating_time_plot)
## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?

Change in SF8

se <- function(x) sqrt(var(x)/length(x))

sf8_time <- t2 %>% 
  select(external_id, sf8_health_t1, sf8_health_t2, sf8_pain_t1, sf8_pain_t2, sf8_vitality_t1, sf8_vitality_t2, sf8_mental_t1, sf8_mental_t2, sf8_physical_t1, sf8_physical_t2, sf8_role_physical_t1, sf8_role_physical_t2, sf8_social_t1, sf8_social_t2, sf8_role_emotional_t1, sf8_role_emotional_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(sf8_health_t1, sf8_health_t2, sf8_pain_t1, sf8_pain_t2, sf8_vitality_t1, sf8_vitality_t2, sf8_mental_t1, sf8_mental_t2, sf8_physical_t1, sf8_physical_t2, sf8_role_physical_t1, sf8_role_physical_t2, sf8_social_t1, sf8_social_t2, sf8_role_emotional_t1, sf8_role_emotional_t2))%>% 
  mutate(Timepoint=
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2", 
              )) %>% 
  mutate(Variable=as.factor(
    case_when(grepl("sf8_health_t", name) ~ "Gen. Health",
              grepl("sf8_pain_t", name) ~ "Pain",
              grepl("sf8_vitality_t", name) ~ "Vitality",
              grepl("sf8_mental_t", name) ~ "Mental Health",
              grepl("sf8_physical_t", name) ~ "Physical Health",
              grepl("sf8_role_physical_t", name) ~ "Role Physical",
              grepl("sf8_social_t", name) ~ "Social",
              grepl("sf8_role_emotional_t", name) ~ "Role Emotional"))) %>%
  group_by(Variable, Timepoint) %>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Variable' (override with `.groups` argument)
sf8_time_graph <- sf8_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, group=Variable, color=Variable)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("darkred", "deepskyblue4", "darkolivegreen", "darkorchid4", "deeppink2", "firebrick1", "orange2", "goldenrod"))+
    geom_point(shape=21, color="grey21", fill="grey21", size=2.5) +
    scale_y_continuous(limits=c(2.5,5), breaks=c(2.5,3,3.5,4,4.5,5)) + 
    theme_minimal() + 
  theme(legend.position="bottom") + 
  theme(legend.text = element_text(color="grey21", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(sf8_time_graph)

#SF8-Physical Health Composite 
sf8_phys_time <- t2 %>% 
  select(external_id, sf8_physical_health_t1, sf8_physical_health_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(sf8_physical_health_t1, sf8_physical_health_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Variable= as.factor(
    case_when(grepl("sf8_physical_health_t", name) ~ "Physical Health Composite"))) %>%
  group_by(Variable, Timepoint)

sf8_phys_time_plot <- sf8_phys_time %>%
ggplot(aes(x=Timepoint, y=value, fill=Timepoint)) +  
  geom_boxplot(outlier.shape = NA) + 
  expand_limits(y = 1) +
  scale_y_continuous(breaks=c(1,2,3,4,5,6)) +
  stat_summary(fun=mean, geom="point", colour="black", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=2.5, show.legend = FALSE, 
               vjust=2.2, aes(label=round(..y.., digits=2))) +
  stat_compare_means(aes(x=Timepoint, y=value), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="SF8 Physical Health Composite",x="Timepoint", y = "Agreement") +
  scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))

print(sf8_phys_time_plot)

#SF8-Mental Health Composite 
sf8_mental_time <- t2 %>% 
  select(external_id, sf8_mental_health_t1, sf8_mental_health_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(sf8_mental_health_t1, sf8_mental_health_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Variable= as.factor(
    case_when(grepl("sf8_mental_health_t", name) ~ "Mental Health Composite"))) %>%
  group_by(Variable, Timepoint)

sf8_mental_time_plot <- sf8_mental_time %>%
ggplot(aes(x=Timepoint, y=value, fill=Timepoint)) +  
  geom_boxplot(outlier.shape = NA) + 
  expand_limits(y = 1) +
  scale_y_continuous(breaks=c(1,2,3,4,5,6)) +
  stat_summary(fun=mean, geom="point", colour="black", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=2.5, show.legend = FALSE, 
               vjust=2.2, aes(label=round(..y.., digits=2))) +
  stat_compare_means(aes(x=Timepoint, y=value), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="SF8 Mental Health Composite",x="Timepoint", y = "Agreement") +
  scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))

print(sf8_mental_time_plot)

Change in Motivation

se <- function(x) sqrt(var(x)/length(x))

motivation_time <- t2 %>% 
  select(external_id, motivation_1_t1, motivation_1_t2, motivation_2_t1, motivation_2_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(motivation_1_t1, motivation_1_t2, motivation_2_t1, motivation_2_t2))%>% 
  mutate(Timepoint=
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2", 
              )) %>% 
  mutate(Variable=as.factor(
    case_when(grepl("motivation_1_t", name) ~ "Motivation - Improve Health",
              grepl("motivation_2_t", name) ~ "Motivation - Avoid Sickness"))) %>%
  group_by(Variable, Timepoint) %>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Variable' (override with `.groups` argument)
motivation_time_graph <- motivation_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, group=Variable, color=Variable)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("darkred", "deepskyblue4"))+
    geom_point(shape=21, color="grey21", fill="grey21", size=2.5) +
    scale_y_continuous(limits=c(1,6), breaks=c(1,2,3,4,5,6)) + 
    theme_minimal() + 
  theme(legend.position="bottom") + 
  theme(legend.text = element_text(color="grey21", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(motivation_time_graph)

#Motivation - Improve Health 
motivation_1_time <- t2 %>% 
  select(external_id, motivation_1_t1, motivation_1_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(motivation_1_t1, motivation_1_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Variable= as.factor(
    case_when(grepl("motivation_1_t", name) ~ "Motivation - Improve Health"))) %>%
  group_by(Variable, Timepoint)

motivation_1_time_plot <- motivation_1_time %>%
ggplot(aes(x=Timepoint, y=value, fill=Timepoint)) +  
  geom_boxplot(outlier.shape = NA) + 
  expand_limits(y = 1) +
  scale_y_continuous(breaks=c(1,2,3,4,5,6)) +
  stat_summary(fun=mean, geom="point", colour="black", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=2.5, show.legend = FALSE, 
               vjust=2.2, aes(label=round(..y.., digits=2))) +
  stat_compare_means(aes(x=Timepoint, y=value), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Motivation - Improve Health",x="Timepoint", y = "Agreement") +
  scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(motivation_1_time_plot)

#Motivation - Avoid Illness 
motivation_2_time <- t2 %>% 
  select(external_id, motivation_2_t1, motivation_2_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(motivation_2_t1, motivation_2_t2))%>% 
  mutate(Timepoint=as.factor(
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2"
              ))) %>% 
  mutate(Variable= as.factor(
    case_when(grepl("motivation_2_t", name) ~ "Motivation - Avoid Sickness"))) %>%
  group_by(Variable, Timepoint)

motivation_2_time_plot <- motivation_2_time %>%
ggplot(aes(x=Timepoint, y=value, fill=Timepoint)) +  
  geom_boxplot(outlier.shape = NA) + 
  expand_limits(y = 1) +
  scale_y_continuous(breaks=c(1,2,3,4,5,6)) +
  stat_summary(fun=mean, geom="point", colour="black", shape=18, size=3, show.legend = FALSE) +
  stat_summary(fun=mean, colour="black", geom="text", size=2.5, show.legend = FALSE, 
               vjust=2.2, aes(label=round(..y.., digits=2))) +
  stat_compare_means(aes(x=Timepoint, y=value), label = "p.signif", comparisons=mindset_comparisons, bracket.size = 0.3, symnum.args = list(cutpoints = c(0, 0.001, 0.01, 0.05, 1), symbols = c( "***", "**", "*", "ns"))) + 
  labs(title="Motivation - Avoid Sickness",x="Timepoint", y = "Agreement") +
  scale_fill_manual(breaks = c("Baseline", "T2"), values=c("azure2", "azure4")) + 
  theme(plot.title = element_text(hjust = 0.5)) + 
  theme(legend.position="none") + 
  theme(legend.text = element_text(color="black", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(motivation_2_time_plot)

Change in Social Support

Change in Motivation

se <- function(x) sqrt(var(x)/length(x))

soc_time <- t2 %>% 
  select(external_id, support_inst_t1, support_inst_t2, support_emotional_t1, support_emotional_t2, support_health_t1, support_health_t2) %>%
  na.omit() %>%
  pivot_longer(
    cols = c(support_inst_t1, support_inst_t2, support_emotional_t1, support_emotional_t2, support_health_t1, support_health_t2))%>% 
  mutate(Timepoint=
    case_when(grepl("_t1", name) ~ "Baseline", 
              grepl("_t2", name)~ "T2", 
              )) %>% 
  mutate(Variable=as.factor(
    case_when(grepl("motivation_1_t", name) ~ "Motivation - Improve Health",
              grepl("motivation_2_t", name) ~ "Motivation - Avoid Sickness"))) %>%
  group_by(Variable, Timepoint) %>%
    summarise(Agreement = mean(value),
              sd = sd(value),
              n = n()) %>%
    mutate(std_err = se(sd),
           lower.ci = Agreement - (qnorm(0.975)*(sd/sqrt(n))),
           upper.ci = Agreement + (qnorm(0.975)*(sd/sqrt(n))))
## `summarise()` regrouping output by 'Variable' (override with `.groups` argument)
motivation_time_graph <- motivation_time %>%
  ggplot(aes(x=Timepoint, y=Agreement, group=Variable, color=Variable)) +
    geom_errorbar(aes(ymin=lower.ci, ymax=upper.ci), width=0.07, color="black") +
    geom_line(size=1) + 
    scale_color_manual(values=c("darkred", "deepskyblue4"))+
    geom_point(shape=21, color="grey21", fill="grey21", size=2.5) +
    scale_y_continuous(limits=c(1,6), breaks=c(1,2,3,4,5,6)) + 
    theme_minimal() + 
  theme(legend.position="bottom") + 
  theme(legend.text = element_text(color="grey21", size=12)) + 
  theme(legend.title = element_blank()) +
  theme(axis.text.x = element_text(color="black", size=10, hjust=0.5))
print(motivation_time_graph)

Correlations

Illness & Body Mindsets

t1t2_corplot_bmi <- t2 %>%
  select(sf8_mental_health_t2, sf8_physical_health_t2, motivation_1_t2, motivation_2_t2, social_support_t2, bmi_t1, initial_weight_t1, prediabetes_risk_score_t1, lesson_count_t2, coach_messages_sent_t2, coach_messages_received_t2, logins_t2, meals_logged_t2, physical_activity_steps_t2, ill_catastrophe_t2, ill_manageable_t2, ill_opportunity_t2, body_adversary_t2, body_capable_t2, body_responsive_t2) %>%
  na.omit()

colnames(t1t2_corplot_bmi) <- c("Mental Total T2", "Physical Total T2", "Motivation - Improve Health", "Motivation - Avoid Illness", "Soc. Support", "BMI", "Weight", "Risk Score", "Lesson Count", "Coach Msg. Sent", "Coach Msg. Rec.", "Logins", "Meals", "Steps", "Catastrophe Mindset", "Manageable Mindset", "Opportunity Mindset", "Body Adversary", "Body Capable", "Body Responsive")

t1t2_cor_bmi <- rcorr(as.matrix(t1t2_corplot_bmi))
t1t2_bmi_r <- t1t2_cor_bmi$r
t1t2_bmi_sig <- t1t2_cor_bmi$P

# Corplot with colors
corrplot(t1t2_bmi_r, method="color", type="lower", addCoef.col="black", number.cex = 0.75, p.mat = t1t2_bmi_sig, sig.level = c(.001, .01, .05), insig = "blank", addgrid.col="black", tl.srt=45, tl.col="midnightblue",  col = colorRampPalette(c("blue4", "white", "red3"))(100))

Process Mindsets

t1t2_corplot_process <- t2 %>%
  select(sf8_mental_health_t2, sf8_physical_health_t2, motivation_1_t2, motivation_2_t2, social_support_t2, bmi_t1, initial_weight_t1, prediabetes_risk_score_t1, lesson_count_t2, coach_messages_sent_t2, coach_messages_received_t2, logins_t2, meals_logged_t2, physical_activity_steps_t2, process_difficult_t2, process_unpleasant_t2, process_stressful_t2, process_inconvenient_t2, process_boring_t2, process_lonely_t2, process_depriving_t2) %>%
  na.omit()

colnames(t1t2_corplot_process) <- c("Mental Total T2", "Physical Total T2", "Motivation - Improve Health", "Motivation - Avoid Illness", "Soc. Support", "BMI", "Weight", "Risk Score", "Lesson Count", "Coach Msg. Sent", "Coach Msg. Rec.", "Logins", "Meals", "Steps", "T2: Difficult-Easy", "T2: Unpleasant-Pleasurable", "T2: Stressful-Relaxing", "T2: Inconvenient-Convenient", "T2: Boring-Fun", "T2: Lonely-Social", "T2: Depriving-Indugent")

t1t2_cor_process <- rcorr(as.matrix(t1t2_corplot_process))
t1t2_process_r <- t1t2_cor_process$r
t1t2_process_sig <- t1t2_cor_process$P

# Corplot with colors
corrplot(t1t2_process_r, method="color", type="lower", addCoef.col="black", number.cex = 0.75, p.mat = t1t2_process_sig, sig.level = c(.001, .01, .05), insig = "blank", addgrid.col="black", tl.srt=45, tl.col="midnightblue",  col = colorRampPalette(c("blue4", "white", "red3"))(100))

Stress, Growth, & Activity Mindsets

t1t2_corplot_stressgrowact <- t2 %>%
  select(sf8_mental_health_t2, sf8_physical_health_t2, motivation_1_t2, motivation_2_t2, social_support_t2, bmi_t1, initial_weight_t1, prediabetes_risk_score_t1, lesson_count_t2, coach_messages_sent_t2, coach_messages_received_t2, logins_t2, meals_logged_t2, physical_activity_steps_t2, activity_adequacy_mindset_t2, health_growth_mindset_t2, stress_enhancing_t2, stress_debilitating_t2) %>%
  na.omit()

colnames(t1t2_corplot_stressgrowact) <- c("Mental Total T2", "Physical Total T2", "Motivation - Improve Health", "Motivation - Avoid Illness", "Soc. Support", "BMI", "Weight", "Risk Score", "Lesson Count", "Coach Msg. Sent", "Coach Msg. Rec.", "Logins", "Meals", "Steps", "Activity Adequacy Mindset", "Health Growth Mindset", "Stress Enhancing Mindset", "Stress Debilitating Mindset")

t1t2_cor_stressgrowact<- rcorr(as.matrix(t1t2_corplot_stressgrowact))
t1t2_stressgrowact_r <- t1t2_cor_stressgrowact$r
t1t2_stressgrowact_sig <- t1t2_cor_stressgrowact$P

# Corplot with colors
corrplot(t1t2_stressgrowact_r, method="color", type="lower", addCoef.col="black", number.cex = 0.75, p.mat = t1t2_stressgrowact_sig, sig.level = c(.001, .01, .05), insig = "blank", addgrid.col="black", tl.srt=45, tl.col="midnightblue",  col = colorRampPalette(c("blue4", "white", "red3"))(100))

Mixed Effects Models

Illness Mindsets

t1t2_mods_cat_phys <- t2 %>% 
  select(external_id, sf8_physical_health_t1, sf8_physical_health_t2, ill_catastrophe_t1, ill_catastrophe_t2) %>%
  pivot_longer(
    cols = c(sf8_physical_health_t1, sf8_physical_health_t2, ill_catastrophe_t1, ill_catastrophe_t2))%>% 
  mutate(time=as.factor(
    case_when(grepl("_t1", name)~ "time 1", 
              grepl("_t2", name)~ "time 2"
              ))) %>% 
  mutate(name= case_when(
    grepl("ill_catastrophe_t", name) ~ "catastrophe", 
    grepl("sf8_physical_health_t", name) ~ "physical"))

  t1t2_mods_cat_phys= t1t2_mods_cat_phys %>% 
  pivot_wider(names_from = "name", values_from= "value") 

t1t2_mods_cat_phys <- t1t2_mods_cat_phys %>%
  filter(external_id != "")

t1t2_mods_cat_phys <-  t1t2_mods_cat_phys %>%
  mutate(
    time_1=if_else(time=="time 1", 1, 0),
    time_2=if_else(time=="time 2", 1, 0))

#Contrast for time 3: 
#contrasts(pandemic_mods_cat_mental$time)= cbind(
#T1vsT3 = c(1 - (1/3), -1/3, -1/3),
#T2vsT3 = c(-1/3, 1 - (1/3), -1/3))

t1t2_mods_cat_phys=t1t2_mods_cat_phys %>%
  mutate(catastrophe = as.numeric(catastrophe),
         physical = as.numeric(physical)) %>%
  group_by(external_id) %>% 
  mutate(cat_btw= mean(catastrophe, na.rm=TRUE)) %>% #mindset mean per participant across times
  mutate(cat_within=catastrophe-cat_btw) #participants' deviation from their individual mindset

Change in DV: Physical Health

phys_time = lmer(physical ~ time + (1|external_id), data=t1t2_mods_cat_phys)
tab_model(phys_time)
  physical
Predictors Estimates CI p
(Intercept) 3.67 3.63 – 3.70 <0.001
time [time 2] 0.14 0.07 – 0.21 <0.001
Random Effects
σ2 0.13
τ00 external_id 0.11
ICC 0.46
N external_id 843
Observations 1003
Marginal R2 / Conditional R2 0.011 / 0.465
physical_change <- Rmisc::summarySEwithin(t1t2_mods_cat_phys, measurevar="physical", 
                      withinvars=c("time"), idvar="external_id", na.rm = T)

ggplot(physical_change, aes(x=time, y=physical, group=1, color=time)) +
                              geom_line() +
                              geom_errorbar(width=.1, aes(ymin=physical-ci, ymax=physical+ci)) +
                              geom_point(shape=21, size=3, fill="white") +
                              labs(title= "Change in physical Health",
                              y= "Physical Health", x= "Timepoint")

LMER Model Output

catastrophe_physical_mod <- lmer(physical ~ time_1 + time_2 +
                            cat_btw + cat_within + 
                            (cat_within*time) +
                            (cat_btw*time) +
                            (1|external_id), 
                            data=t1t2_mods_cat_phys)
## fixed-effect model matrix is rank deficient so dropping 2 columns / coefficients
tab_model(catastrophe_physical_mod, show.std = T)
## fixed-effect model matrix is rank deficient so dropping 2 columns / coefficients
  physical
Predictors Estimates std. Beta CI standardized CI p
(Intercept) 3.95 -0.03 3.75 – 4.15 -0.09 – 0.04 <0.001
time_1 -0.15 -0.09 -0.35 – 0.05 -0.14 – -0.04 0.145
cat_btw -0.04 -0.12 -0.07 – -0.02 -0.18 – -0.06 <0.001
cat_within 0.10 0.10 0.01 – 0.20 0.01 – 0.18 0.030
cat_within : timetime 2 -0.24 -0.22 -0.40 – -0.08 -0.37 – -0.07 0.003
cat_btw : timetime 2 -0.01 -0.02 -0.07 – 0.05 -0.19 – 0.14 0.792
Random Effects
σ2 0.13
τ00 external_id 0.11
ICC 0.44
N external_id 836
Observations 994
Marginal R2 / Conditional R2 0.039 / 0.465

Within Participant Data Visualization

t1t2_mods_cat_phys %>% 
  ggplot(aes(x=cat_within, y=physical, group=as.numeric(external_id))) +
  geom_smooth(method="lm")+
  labs(title= "Physical Health and Catastrophe Mindset Over Time Within Individuals",
       y= "Physical Health", x= "Catastrophe Mindset (Within)")
## `geom_smooth()` using formula 'y ~ x'

 t1t2_mods_cat_phys %>% 
  ggplot(aes(cat_within, physical, color=time)) +
  geom_smooth(method = "lm")
## `geom_smooth()` using formula 'y ~ x'

Between Participant Data Visualization

t1t2_mods_cat_phys %>% 
  ggplot(aes(x=cat_btw, y=physical, group= as.numeric(external_id))) +
  geom_smooth(method="lm")+
  labs(title= "Physical Health and Catastrophe Mindset Over Time Between Individuals",
       y= "Physical Health", x= "Catastrophe Mindset (Between)")
## `geom_smooth()` using formula 'y ~ x'

t1t2_mods_cat_phys %>% 
  ggplot(aes(cat_btw, physical, color=time)) +
  geom_smooth(method = "lm")
## `geom_smooth()` using formula 'y ~ x'

Pandemic Manageable Mindset (IV)

t1t2_mods_man_phys <- t2 %>% 
  select(external_id, sf8_physical_health_t1, sf8_physical_health_t2, ill_manageable_t1, ill_manageable_t2) %>%
  pivot_longer(
    cols = c(sf8_physical_health_t1, sf8_physical_health_t2, ill_manageable_t1, ill_manageable_t2))%>% 
  mutate(time=as.factor(
    case_when(grepl("_t1", name)~ "time 1", 
              grepl("_t2", name)~ "time 2"
              ))) %>% 
  mutate(name= case_when(
    grepl("ill_manageable_t", name) ~ "manageable", 
    grepl("sf8_physical_health_t", name) ~ "physical"))

  t1t2_mods_man_phys= t1t2_mods_man_phys %>% 
  pivot_wider(names_from = "name", values_from= "value") 

t1t2_mods_man_phys <- t1t2_mods_man_phys %>%
  filter(external_id != "")

t1t2_mods_man_phys <-  t1t2_mods_man_phys %>%
  mutate(
    time_1=if_else(time=="time 1", 1, 0),
    time_2=if_else(time=="time 2", 1, 0))

t1t2_mods_man_phys <-  t1t2_mods_man_phys %>%
  mutate(manageable = as.numeric(manageable),
         physical = as.numeric(physical)) %>%
  group_by(external_id) %>% 
  mutate(man_btw= mean(manageable, na.rm=TRUE)) %>% #mindset mean per participant across times
  mutate(man_within=manageable-man_btw) #participants' deviation from their individual mindset

Change in DV: Physical Health

phys_time = lmer(physical ~ time + (1|external_id), data=t1t2_mods_cat_phys)
tab_model(phys_time)
  physical
Predictors Estimates CI p
(Intercept) 3.67 3.63 – 3.70 <0.001
time [time 2] 0.14 0.07 – 0.21 <0.001
Random Effects
σ2 0.13
τ00 external_id 0.11
ICC 0.46
N external_id 843
Observations 1003
Marginal R2 / Conditional R2 0.011 / 0.465
physical_change <- Rmisc::summarySEwithin(t1t2_mods_cat_phys, measurevar="physical", 
                      withinvars=c("time"), idvar="external_id", na.rm = T)

ggplot(physical_change, aes(x=time, y=physical, group=1, color=time)) +
                              geom_line() +
                              geom_errorbar(width=.1, aes(ymin=physical-ci, ymax=physical+ci)) +
                              geom_point(shape=21, size=3, fill="white") +
                              labs(title= "Change in physical Health",
                              y= "Physical Health", x= "Timepoint")

LMER Model Output

manageable_physical_mod <- lmer(physical ~ time_1 + time_2 +
                            man_btw + man_within + 
                            (man_within*time) +
                            (man_btw*time) +
                            (1|external_id), 
                            data=t1t2_mods_man_phys)
## fixed-effect model matrix is rank deficient so dropping 2 columns / coefficients
tab_model(manageable_physical_mod, show.std = T)
## fixed-effect model matrix is rank deficient so dropping 2 columns / coefficients
  physical
Predictors Estimates std. Beta CI standardized CI p
(Intercept) 2.94 -0.02 2.55 – 3.34 -0.08 – 0.05 <0.001
time_1 0.47 -0.10 0.07 – 0.88 -0.15 – -0.05 0.020
man_btw 0.05 0.11 0.02 – 0.08 0.04 – 0.17 0.001
man_within -0.13 -0.09 -0.25 – -0.00 -0.17 – -0.00 0.045
man_within : timetime 2 0.25 0.18 0.04 – 0.46 0.03 – 0.32 0.018
man_btw : timetime 2 0.12 0.26 0.04 – 0.20 0.09 – 0.42 0.002
Random Effects
σ2 0.13
τ00 external_id 0.10
ICC 0.44
N external_id 841
Observations 998
Marginal R2 / Conditional R2 0.042 / 0.465

Within Participant Data Visualization

t1t2_mods_cat_phys %>% 
  ggplot(aes(x=cat_within, y=physical, group=as.numeric(external_id))) +
  geom_smooth(method="lm")+
  labs(title= "Physical Health and Catastrophe Mindset Over Time Within Individuals",
       y= "Physical Health", x= "Catastrophe Mindset (Within)")
## `geom_smooth()` using formula 'y ~ x'

 t1t2_mods_cat_phys %>% 
  ggplot(aes(cat_within, physical, color=time)) +
  geom_smooth(method = "lm")
## `geom_smooth()` using formula 'y ~ x'

Between Participant Data Visualization

t1t2_mods_cat_phys %>% 
  ggplot(aes(x=cat_btw, y=physical, group= as.numeric(external_id))) +
  geom_smooth(method="lm")+
  labs(title= "Physical Health and Catastrophe Mindset Over Time Between Individuals",
       y= "Physical Health", x= "Catastrophe Mindset (Between)")
## `geom_smooth()` using formula 'y ~ x'

t1t2_mods_cat_phys %>% 
  ggplot(aes(cat_btw, physical, color=time)) +
  geom_smooth(method = "lm")
## `geom_smooth()` using formula 'y ~ x'