SOCIAL CONNECTION SCALE
Exclusion Criteria (per scale):
Step 1: If Pp has complete or partial data for 15% of EMA timepoints > included
Step 2: If Pp has completed 15% of all item responses > included
Step 4: Series means will be imputed for any remaining missing data
Step 5: Create composite score with included, imputed items
Evaluating missingness for state social connection items
Step 1 - Percentage of participants who are excluded based on total timepoints completed
library(dplyr)
# Extract column for the daily social connection scale
socialconnect_scale <- eq_EMA_data %>%
dplyr::select(contains("soc_"))
socialconnect_scale$PID <- eq_EMA_data$PID
socialconnect_scale$EMA_timepoint <- eq_EMA_data$EMA_timepoint
socialconnect_scale$Condition <- eq_EMA_data$Condition
#socialconnect_scale
#Count the total number of timepoints completed per participant
socialconnect_NumComplete <- count(socialconnect_scale, vars = PID)
socialconnect_NumComplete$PercentComplete <- socialconnect_NumComplete$n / 14
colnames(socialconnect_NumComplete)[1:2] <- c("PID", "surveyComplete")
# Extract the PID with less than 15% completion rate across all timepoints
socialconnect_exclude1 <- socialconnect_NumComplete$PID[socialconnect_NumComplete$PercentComplete < 0.15]
#socialconnect_exclude1
# Calculate the percentage of participants who are excluded based on total timepoints completed
socialconnect_percent_AllTime <- length(socialconnect_exclude1)/113
socialconnect_percent_AllTime
## [1] 0.01769912
#Remove participants from the scale dataset who have been excluded based on the first criteria
socialconnect_scale_include1 <- socialconnect_scale %>%
filter(! PID %in% socialconnect_exclude1)
Step 2 - Percentage of remaining participants excluded due to less than 15% of all item responses completed
# Calculate the number of total completed data per row
socialconnect_scale_include1$itemComplete <- rowSums(!is.na(socialconnect_scale_include1[,1:7]))
#socialconnect_scale_include1
# Aggregate within subject
socialconnect_itemComplete <- aggregate(itemComplete ~ PID, data = socialconnect_scale_include1 [,8:11], sum)
#socialconnect_itemComplete
# Calculate the percentage of missing
socialconnect_totalItem <- 7 * 14 #4 items * 14 timepoints
socialconnect_itemComplete$percentComplete <- round(socialconnect_itemComplete$itemComplete/socialconnect_totalItem,3) #round to 3 decimal points
#socialconnect_itemComplete #NEEDS UPDATED - MORE THAN 100% COMPLETE - WHY?
# Extract the PID with less than 15% completion rate across both row and column
#Brendan suggests higher threshold here bc it is related to the reliability of the items. You can systematically look at the reliability and plot it as a functions of items.
socialconnect_exclude2 <- socialconnect_itemComplete$PID[socialconnect_itemComplete$percentComplete < 0.15]
#socialconnect_exclude2
# Calculate the percentage of participant who are excluded based on this scale
length(socialconnect_exclude2)/113
## [1] 0
#Remove participants from the scale dataset who have been excluded based on the second criteria
socialconnect_scale_include2 <- socialconnect_scale_include1 %>%
filter(! PID %in% socialconnect_exclude2)
#socialconnect_scale_include2
Step 3: If a scale has 70% of participant responses after previous steps, scale included, Count the percentage of participants remaining after step 1 and 2 who are included in the scale.
# Count the percentage of participants remaining after step 1 and 2 who are included in the scale
totalIncluded <- length(unique(socialconnect_scale_include2$PID))
percentageIncluded <- round((totalIncluded/113),3)
percentageIncluded
## [1] 0.982
Step 4: Impute series means for any remaining missing data
socialconnect_scale_include2$soc_numdifpeople_imp <- ifelse(is.na(socialconnect_scale_include2$soc_numdifpeople), mean(socialconnect_scale_include2$soc_numdifpeople, na.rm=TRUE), socialconnect_scale_include2$soc_numdifpeople)
socialconnect_scale_include2$soc_numpeople_imp <- ifelse(is.na(socialconnect_scale_include2$soc_numpeople), mean(socialconnect_scale_include2$soc_numpeople, na.rm=TRUE), socialconnect_scale_include2$soc_numpeople)
socialconnect_scale_include2$soc_positive_imp <- ifelse(is.na(socialconnect_scale_include2$soc_positive), mean(socialconnect_scale_include2$soc_positive, na.rm=TRUE), socialconnect_scale_include2$soc_positive)
socialconnect_scale_include2$soc_neg_imp <- ifelse(is.na(socialconnect_scale_include2$soc_neg), mean(socialconnect_scale_include2$soc_neg, na.rm=TRUE), socialconnect_scale_include2$soc_neg)
socialconnect_scale_include2$soc_howpos_imp <- ifelse(is.na(socialconnect_scale_include2$soc_howpos),
mean(socialconnect_scale_include2$soc_howpos, na.rm=TRUE),
socialconnect_scale_include2$soc_howpos) #WHY ISN'T THIS ONE IMPUTING?
socialconnect_scale_include2$soc_howneg_imp <- ifelse(is.na(socialconnect_scale_include2$soc_howneg), mean(socialconnect_scale_include2$soc_howneg, na.rm=TRUE), socialconnect_scale_include2$soc_howneg)
socialconnect_scale_include2$soc_closeness_imp <- ifelse(is.na(socialconnect_scale_include2$soc_closeness), mean(socialconnect_scale_include2$soc_closeness, na.rm=TRUE), socialconnect_scale_include2$soc_closeness)
Step 5: Creating composite scores for Social Connection
Re-coding score “soc_closeness” - score will now reflect that higher scores on soc_closeness_imp will equate to greater social connectedness.
socialconnect_scale_include2$soc_closeness_imp <- 5-socialconnect_scale_include2$soc_closeness_imp
Correlation Matrix - All items
socialconnect_scale_include_cor <- dplyr::select(socialconnect_scale_include2, soc_numdifpeople_imp:soc_closeness_imp)
# All Items
sapply(socialconnect_scale_include_cor, is.factor)
## soc_numdifpeople_imp soc_numpeople_imp soc_positive_imp
## FALSE FALSE FALSE
## soc_neg_imp soc_howpos_imp soc_howneg_imp
## FALSE FALSE FALSE
## soc_closeness_imp
## FALSE
cor <- round(cor(socialconnect_scale_include_cor[sapply(socialconnect_scale_include_cor, function(x) !is.factor(x))], use = "complete.obs"),2) #Correlation matrix of indices
#cor
library(reshape2)
melted_cormat <- melt(cor)
#head(melted_cormat)
# Get lower triangle of the correlation matrix
get_lower_tri<-function(cormat){
cormat[upper.tri(cormat)] <- NA
return(cormat)
}
# Get upper triangle of the correlation matrix
get_upper_tri <- function(cormat){
cormat[lower.tri(cormat)]<- NA
return(cormat)
}
upper_tri <- get_upper_tri(cor)
#upper_tri
# Melt the correlation matrix
library(reshape2)
melted_cormat <- melt(upper_tri, na.rm = TRUE)
reorder_cormat <- function(cor){
# Use correlation between variables as distance
dd <- as.dist((1-cor)/2)
hc <- hclust(dd)
cor <-cor[hc$order, hc$order]
}
# Reorder the correlation matrix
cor <- reorder_cormat(cor)
upper_tri <- get_upper_tri(cor)
# Melt the correlation matrix
melted_cormat <- melt(upper_tri, na.rm = TRUE)
# Create a ggheatmap
library(ggplot2)
ggheatmap <- ggplot(melted_cormat, aes(Var2, Var1, fill = value))+
geom_tile(color = "white")+
scale_fill_gradient2(low = "blue", high = "red", mid = "white",
midpoint = 0, limit = c(-1,1), space = "Lab",
name="Pearson\nCorrelation") +
theme_minimal()+ # minimal theme
theme(axis.text.x = element_text(angle = 45, vjust = 1,
size = 12, hjust = 1))+
coord_fixed()
cor_heatmap <- ggheatmap +
geom_text(aes(Var2, Var1, label = value), color = "black", size = 4) +
theme(
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.grid.major = element_blank(),
panel.border = element_blank(),
panel.background = element_blank(),
axis.ticks = element_blank(),
legend.justification = c(1, 0),
legend.position = c(0.6, 0.7),
legend.direction = "horizontal")+
guides(fill = guide_colorbar(barwidth = 7, barheight = 1,
title.position = "top", title.hjust = 0.5))
cor_heatmap

Looking at the correlation matrix for the social connection items, we see that soc_neg_imp and soc_howneg_imp do not correlate well with the other scale items. We will create a composite of the remaining items and then a composite of the negative social connection items. (see below).
Items / Composites that will be analyzed
Positive, close, and connected social interactions
1a - Total number of social interactions (soc_numpeople_imp) (N/N/N)
1b - Number different people interacted with (soc_numdifpeople_imp) (N/Y/Y)
2 - Social closeness/connection (soc_closeness_imp) (N/Y/Y)(N/Y/Y)
3a - Number of positive social interactions (soc_positive_imp) (N/N/N)
3b - Degree of positive social interactions (soc_howpos_imp) (N/N/N)
Negative Interactions
3c - Number of negative social interactions (soc_neg_imp) (N/N/Y)
3d - Degree of negative social interactions (soc_howneg_imp) (N/N/N)
4 - Composite of positive, close, and connected social interactions items (EMA_social_comp) (N/Y/Y)
5 - Composite of negative interactions (EMA_social_comp_neg) (N/Y/Y)
Checking for internal validity of Social connection composite. and creating composite score.
#Checking for internal validity of positive, close, and connected social connection composite
df_social_connect_comp <- dplyr::select(socialconnect_scale_include2, soc_numdifpeople_imp, soc_numpeople_imp, soc_positive_imp, soc_howpos_imp, soc_closeness_imp)
psych::alpha(df_social_connect_comp) #calculating chronbach's alpha for pos social connect items
##
## Reliability analysis
## Call: psych::alpha(x = df_social_connect_comp)
##
## raw_alpha std.alpha G6(smc) average_r S/N ase mean sd median_r
## 0.74 0.79 0.8 0.43 3.7 0.01 2.5 0.91 0.38
##
## lower alpha upper 95% confidence boundaries
## 0.72 0.74 0.76
##
## Reliability if an item is dropped:
## raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r
## soc_numdifpeople_imp 0.67 0.73 0.74 0.40 2.7 0.0126 0.036
## soc_numpeople_imp 0.65 0.72 0.70 0.39 2.5 0.0128 0.023
## soc_positive_imp 0.62 0.69 0.70 0.36 2.2 0.0149 0.042
## soc_howpos_imp 0.75 0.82 0.81 0.52 4.4 0.0115 0.041
## soc_closeness_imp 0.80 0.78 0.78 0.46 3.5 0.0067 0.070
## med.r
## soc_numdifpeople_imp 0.38
## soc_numpeople_imp 0.38
## soc_positive_imp 0.30
## soc_howpos_imp 0.54
## soc_closeness_imp 0.47
##
## Item statistics
## n raw.r std.r r.cor r.drop mean sd
## soc_numdifpeople_imp 1345 0.75 0.78 0.73 0.62 3.0 1.03
## soc_numpeople_imp 1345 0.78 0.80 0.79 0.64 3.2 1.19
## soc_positive_imp 1345 0.84 0.85 0.83 0.73 2.6 1.24
## soc_howpos_imp 1345 0.49 0.58 0.41 0.39 2.2 0.53
## soc_closeness_imp 1345 0.76 0.68 0.54 0.44 1.7 2.01
alpha_connect <- psych::alpha(df_social_connect_comp)$total$std.alpha #extracting just the alpha value for items
alpha_connect <- round(alpha_connect, 2)
print(alpha_connect) #Good internal consistency
## [1] 0.79
#Creating column with social connection composite score ("EMA_social_comp")
socialconnect_scale_include2$EMA_social_comp <-socialconnect_scale_include2$soc_numdifpeople_imp + socialconnect_scale_include2$soc_numpeople_imp + socialconnect_scale_include2$soc_positive_imp + socialconnect_scale_include2$soc_howpos_imp + socialconnect_scale_include2$soc_closeness_imp
Checking for internal validity of positive, close, and connected social connection composite reveals a chrnobach’s alpha (a= .79).
Checking for internal validity of negative social interaction composite.
#Checking for internal validity of Negative social connection composite
df_neg_social_connect_comp <- dplyr::select(socialconnect_scale_include2, soc_neg_imp, soc_howneg_imp)
psych::alpha(df_neg_social_connect_comp) #calculating chronbach's alpha for neg social connect items
##
## Reliability analysis
## Call: psych::alpha(x = df_neg_social_connect_comp)
##
## raw_alpha std.alpha G6(smc) average_r S/N ase mean sd median_r
## 0.55 0.6 0.43 0.43 1.5 0.021 0.93 0.58 0.43
##
## lower alpha upper 95% confidence boundaries
## 0.51 0.55 0.59
##
## Reliability if an item is dropped:
## raw_alpha std.alpha G6(smc) average_r S/N alpha se var.r med.r
## soc_neg_imp 0.43 0.43 0.19 0.43 NA NA 0.43 0.43
## soc_howneg_imp 0.19 0.43 NA NA NA NA 0.19 0.43
##
## Item statistics
## n raw.r std.r r.cor r.drop mean sd
## soc_neg_imp 1345 0.92 0.85 0.56 0.43 0.6 0.84
## soc_howneg_imp 1345 0.75 0.85 0.56 0.43 1.3 0.51
##
## Non missing response frequency for each item
## 0 0.602400600150037 1 1.25987841945289 2 3 4 5
## soc_neg_imp 0.57 0.01 0.30 0.00 0.09 0.03 0.01 0
## soc_howneg_imp 0.00 0.00 0.76 0.02 0.18 0.04 0.00 0
## miss
## soc_neg_imp 0
## soc_howneg_imp 0
alpha_neg <- psych::alpha(df_neg_social_connect_comp)$total$std.alpha #extracting just the alpha value for items
alpha_neg <- round(alpha_neg, 2)
print(alpha_neg) #Acceptable internal consistency
## [1] 0.6
#Creating column with social connection composite score ("EMA_social_comp")
socialconnect_scale_include2$EMA_neg_social_comp <-socialconnect_scale_include2$soc_neg_imp + socialconnect_scale_include2$soc_howneg_imp
Checking for internal validity of negative social connection composite reveals a chronbach’s alpha (a= .60)
Re-labeling condition labels. The conditions were originally labeled as 1 and 2 in the dataset, this function changes this such that condition 1 is now condition 0 and condition 2 is now condition 1.
library(tidyr)
socialconnect_scale_include2 <- socialconnect_scale_include2 %>%
separate (EMA_timepoint, into = c("pre_post", "timepoint")) %>%
mutate(Condition = Condition -1) #the conditions were originally labeled as 1 and 2 in the dataset, this function changes this such that condition 1 is now condition 0 and condition 2 is now condition 1.
#Note:
# Original condition 1 in the dataset is now "Condition 0"
# Original condition 2 in the dataset is now "Condition 1"
#socialconnect_scale_include2
Creating separate dataframes for 1-week and 14-week follow-up
socialconnect_scale_1wkpost <- socialconnect_scale_include2 %>%
filter(pre_post == 'Base')
socialconnect_scale_14wkpost <- socialconnect_scale_include2 %>%
filter(pre_post == 'End')
Mixed models for EMA Social Connection Scales
library(lme4)
library(lmerTest)
socialconnect_scale_include2 <- socialconnect_scale_include2 %>%
mutate(pre_post = as.factor(pre_post),
timepoint = as.factor(timepoint))
POSITIVE, CLOSE, and CONNECTED SOCIAL CONNECTION COMPOSITE
Describing the data
# Descriptives - EMA Social Connection Composite (EMA_social_comp)
# 1-week post
psych::describeBy(socialconnect_scale_1wkpost$EMA_social_comp, socialconnect_scale_1wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 323 13.57223 3.910311 14 13.80629 4.4478 0 22 22
## X12 2 1 1 347 12.90287 4.359070 13 13.17271 4.4478 1 22 21
## skew kurtosis se
## X11 -0.5183477 0.07009815 0.2175755
## X12 -0.5203587 -0.16305883 0.2340071
# 14-weeks post
psych::describeBy(socialconnect_scale_14wkpost$EMA_social_comp, socialconnect_scale_14wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 344 12.65017 4.463040 13 12.74781 4.4478 -2 22 24
## X12 2 1 1 331 11.58084 5.138869 12 11.79064 5.9304 -2 22 24
## skew kurtosis se
## X11 -0.2983468 0.3683010 0.2406310
## X12 -0.3430122 -0.3647332 0.2824578
# Post
psych::describeBy(socialconnect_scale_include2$EMA_social_comp, socialconnect_scale_include2$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max
## X11 1 0 1 667 13.09669 4.226561 13 13.25728 4.44780 -2 22
## X12 2 1 1 678 12.25745 4.798022 13 12.51417 4.76008 -2 22
## range skew kurtosis se
## X11 24 -0.4221188 0.3060899 0.1636531
## X12 24 -0.4717985 -0.1965581 0.1842669
boxplot(EMA_social_comp~Condition,socialconnect_scale_include2, main="Brief Social Connection Scores by Condition",
xlab="Condition", ylab="Social Connection Comp Score")

Mixed model for Social Connection Composite (POST)
# NEED TO UPDATE THESE TO REMOVE "PRE_POST" FROM (1 + pre_post | PID) once I confirm with David.
# Model 1 Social Comp
EQ_MM_Social_model <- lmer (EMA_social_comp ~ pre_post * Condition + #fixed effects
(1 + pre_post | PID), data = socialconnect_scale_include2)
#this is a group by time interaction
#3 predictors: 1) Condition(Group), 2) Time, 3) time by condition (group x time)
# "1 + pre_post | PID" estimate a random intercept and a random slope for each individual
summary(EQ_MM_Social_model)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: EMA_social_comp ~ pre_post * Condition + (1 + pre_post | PID)
## Data: socialconnect_scale_include2
##
## REML criterion at convergence: 7280.5
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.3066 -0.5551 0.0798 0.6238 3.3182
##
## Random effects:
## Groups Name Variance Std.Dev. Corr
## PID (Intercept) 7.245 2.692
## pre_postEnd 2.284 1.511 0.37
## Residual 10.426 3.229
## Number of obs: 1345, groups: PID, 111
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 13.6231 0.4060 110.2270 33.551 < 2e-16 ***
## pre_postEnd -0.9319 0.3251 103.6763 -2.867 0.00502 **
## Condition -0.6194 0.5704 109.1143 -1.086 0.27990
## pre_postEnd:Condition -0.3074 0.4598 103.2911 -0.669 0.50522
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) pr_psE Condtn
## pre_postEnd -0.045
## Condition -0.712 0.032
## pr_pstEnd:C 0.032 -0.707 -0.038
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model)
|
|
EMA social comp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
13.62
|
12.83 – 14.42
|
<0.001
|
|
pre_post [End]
|
-0.93
|
-1.57 – -0.29
|
0.004
|
|
Condition
|
-0.62
|
-1.74 – 0.50
|
0.278
|
pre_post [End] * Condition
|
-0.31
|
-1.21 – 0.59
|
0.504
|
|
Random Effects
|
|
σ2
|
10.43
|
|
τ00 PID
|
7.24
|
|
τ11 PID.pre_postEnd
|
2.28
|
|
ρ01 PID
|
0.37
|
|
ICC
|
0.49
|
|
N PID
|
111
|
|
Observations
|
1345
|
|
Marginal R2 / Conditional R2
|
0.021 / 0.498
|
#This model does not yet account for person-level predictors
# Plotting model
library(sjPlot)
plot_model(model = EQ_MM_Social_model, type = "int")

WRITE UP - Collapsing 1-week + 14-week in Mixed Model Post Social Composite
Running a regression model to look at the effect of condition at fourteen-week post for composite score for positive, close, and connected social interactions reveals a non-significant effect (t(?)=-1.09, p = 0.28).
Regression for Social Connection Composite (1-WEEK POST)
# Regression for Social Connection Composite (1-WEEK POST)
EQ_MM_Social_model_1wk <- lm (EMA_social_comp ~ Condition, data = socialconnect_scale_1wkpost)
View(socialconnect_scale_1wkpost)
summary(EQ_MM_Social_model_1wk)
##
## Call:
## lm(formula = EMA_social_comp ~ Condition, data = socialconnect_scale_1wkpost)
##
## Residuals:
## Min 1Q Median 3Q Max
## -13.5722 -2.5722 0.3678 3.3078 9.0971
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 13.5722 0.2308 58.793 <2e-16 ***
## Condition -0.6694 0.3208 -2.087 0.0373 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.149 on 668 degrees of freedom
## Multiple R-squared: 0.006477, Adjusted R-squared: 0.004989
## F-statistic: 4.355 on 1 and 668 DF, p-value: 0.03729
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model_1wk)
|
|
EMA social comp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
13.57
|
13.12 – 14.03
|
<0.001
|
|
Condition
|
-0.67
|
-1.30 – -0.04
|
0.037
|
|
Observations
|
670
|
|
R2 / R2 adjusted
|
0.006 / 0.005
|
WRITE UP - 1-week Post Composite
Running a regression model to look at the effect of condition at one-week post for composite score for positive, close, and connected social interactions reveals a significant effect (t(668)=-2.09, p = 0.04).
Regression for Social Connection Composite (14-WEEK POST)
# Regression for Social Connection Composite (14-WEEK POST)
EQ_MM_Social_model_14wk <- lm (EMA_social_comp ~ Condition, data = socialconnect_scale_14wkpost)
summary(EQ_MM_Social_model_14wk)
##
## Call:
## lm(formula = EMA_social_comp ~ Condition, data = socialconnect_scale_14wkpost)
##
## Residuals:
## Min 1Q Median 3Q Max
## -14.6502 -3.5808 0.3498 3.4192 10.4192
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 12.6502 0.2591 48.82 < 2e-16 ***
## Condition -1.0693 0.3701 -2.89 0.00398 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.806 on 673 degrees of freedom
## Multiple R-squared: 0.01225, Adjusted R-squared: 0.01079
## F-statistic: 8.35 on 1 and 673 DF, p-value: 0.003981
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model_14wk)
|
|
EMA social comp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
12.65
|
12.14 – 13.16
|
<0.001
|
|
Condition
|
-1.07
|
-1.80 – -0.34
|
0.004
|
|
Observations
|
675
|
|
R2 / R2 adjusted
|
0.012 / 0.011
|
WRITE UP - 14-week Post Composite
Running a regression model to look at the effect of condition at fourteen-week post for composite score for positive, close, and connected social interactions reveals a significant effect (t(673)=-2.89, p = 0.00).
Plotting EMA_comp scores
library(ggplot2)
#+++++++++++++++++++++++++
# Function to calculate the mean and the standard deviation
# for each group
#+++++++++++++++++++++++++
## Summarizes data.
## Gives count, mean, standard deviation, standard error of the mean, and confidence interval (default 95%).
## data: a data frame.
## measurevar: the name of a column that contains the variable to be summariezed
## groupvars: a vector containing names of columns that contain grouping variables
## na.rm: a boolean that indicates whether to ignore NA's
## conf.interval: the percent range of the confidence interval (default is 95%)
summarySE <- function(data=NULL, measurevar, groupvars=NULL, na.rm=FALSE,
conf.interval=.95, .drop=TRUE) {
library(plyr)
# New version of length which can handle NA's: if na.rm==T, don't count them
length2 <- function (x, na.rm=FALSE) {
if (na.rm) sum(!is.na(x))
else length(x)
}
# This does the summary. For each group's data frame, return a vector with
# N, mean, and sd
datac <- ddply(data, groupvars, .drop=.drop,
.fun = function(xx, col) {
c(N = length2(xx[[col]], na.rm=na.rm),
mean = mean (xx[[col]], na.rm=na.rm),
sd = sd (xx[[col]], na.rm=na.rm)
)
},
measurevar
)
# Rename the "mean" column
datac <- rename(datac, c("mean" = measurevar))
datac$se <- datac$sd / sqrt(datac$N) # Calculate standard error of the mean
# Confidence interval multiplier for standard error
# Calculate t-statistic for confidence interval:
# e.g., if conf.interval is .95, use .975 (above/below), and use df=N-1
ciMult <- qt(conf.interval/2 + .5, datac$N-1)
datac$ci <- datac$se * ciMult
return(datac)
}
soc_connect_summary <- summarySE(socialconnect_scale_include2, measurevar="EMA_social_comp", groupvars=c("pre_post", "Condition"))
soc_connect_summary
## pre_post Condition N EMA_social_comp sd se ci
## 1 Base 0 323 13.57223 3.910311 0.2175755 0.4280490
## 2 Base 1 347 12.90287 4.359070 0.2340071 0.4602555
## 3 End 0 344 12.65017 4.463040 0.2406310 0.4732981
## 4 End 1 331 11.58084 5.138869 0.2824578 0.5556450
soc_connect_summary$Condition <- as.factor(soc_connect_summary$Condition)
library(plyr)
soc_connect_summary$pre_post<- revalue(soc_connect_summary$pre_post, c("Base"="1-Week Post", "End"="14-Weeks Post"))
#Basic line plot
p<- ggplot(data=soc_connect_summary, aes(x=as.factor(pre_post), y=EMA_social_comp, group=Condition, color=Condition)) +
geom_line(aes(linetype=Condition)) + geom_point(aes(shape=Condition))+
scale_color_brewer(palette="Paired")+
labs(title="Social Connection at 1-week and 14-weeks Post",x="Timepoint", y = "Social Connection")+
theme_classic()
p + theme_classic() + scale_color_manual(values=c('orange1','olivedrab3'))

#Basic line plot with confidence intervals
p<- ggplot(data=soc_connect_summary, aes(x=as.factor(pre_post), y=EMA_social_comp, group=Condition, color=Condition)) +
geom_line(aes(linetype=Condition)) + geom_point(aes(shape=Condition))+
scale_color_brewer(palette="Paired")+
labs(title="Social Connection at 1-week and 14-weeks Post",x="Timepoint", y = "Social Connection")+
theme_classic() +
geom_errorbar(aes(ymin=EMA_social_comp-ci, ymax=EMA_social_comp+ci), width=.2,
position=position_dodge(0.05))
p + theme_classic() + scale_color_manual(values=c('orange1','olivedrab3'))

# Does it make sense to have an N? Do I use N for Pps or for observations
Removing Outliers
#Obtaining values of outliers
library(dplyr)
library(ggplot2)
is_outlier <- function(x) {
return(x < quantile(x, 0.25) - 1.5 * IQR(x) | x > quantile(x, 0.75) + 1.5 * IQR(x))
}
socialconnect_scale_include2 %>%
group_by(Condition) %>%
mutate(outlier = ifelse(is_outlier(EMA_social_comp), EMA_social_comp, as.numeric(NA))) %>%
ggplot(., aes(x = factor(Condition), y = EMA_social_comp)) +
geom_boxplot() +
geom_text(aes(label = outlier), na.rm = TRUE, hjust = -0.3)

# NEED TO FIGURE OUT HOW TO Remove outliers at both levels
Removing Outliers
socialconnect_scale_include2_out <- socialconnect_scale_include2 %>%
filter(Condition == 0, EMA_social_comp > 3)
socialconnect_scale_include2_1 <- socialconnect_scale_include2 %>%
filter(Condition == 1, EMA_social_comp > -2)
socialconnect_scale_out <- rbind(socialconnect_scale_include2_out, socialconnect_scale_include2_1)
#run the models with and without these outliers
Mixed model for EMA Social Connection (outliers removed)
library(lme4)
library(lmerTest)
socialconnect_scale_out <- socialconnect_scale_out %>%
mutate(pre_post = as.factor(pre_post),
timepoint = as.factor(timepoint))
EQ_MM_SocialConnect_model_out <- lmer (EMA_social_comp ~ pre_post * Condition + #fixed effects
(1 + pre_post | PID), data = socialconnect_scale_out)
#this is a group by time interaction
#3 predictors: 1) Condition(Group), 2) Time, 3) time by condition (group x time)
# "1 + pre_post | PID" estimate a random intercept and a random slope for each individual
#summary(EQ_MM_SocialConnect_model_out)
sjPlot::tab_model(EQ_MM_SocialConnect_model_out)
|
|
EMA social comp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
13.68
|
12.90 – 14.47
|
<0.001
|
|
pre_post [End]
|
-0.73
|
-1.33 – -0.12
|
0.019
|
|
Condition
|
-0.67
|
-1.77 – 0.43
|
0.230
|
pre_post [End] * Condition
|
-0.45
|
-1.31 – 0.41
|
0.305
|
|
Random Effects
|
|
σ2
|
9.74
|
|
τ00 PID
|
7.06
|
|
τ11 PID.pre_postEnd
|
1.92
|
|
ρ01 PID
|
0.29
|
|
ICC
|
0.48
|
|
N PID
|
111
|
|
Observations
|
1328
|
|
Marginal R2 / Conditional R2
|
0.022 / 0.494
|
#This model does not yet account for person-level predictors
library(sjPlot)
plot_model(model = EQ_MM_SocialConnect_model_out, type = "int")

Creating separate dataframes for 1-week and 14-week follow-up (outliers removed)
socialconnect_scale_out_1wkpost <- socialconnect_scale_out %>%
filter(pre_post == 'Base')
socialconnect_scale_out_14wkpost <- socialconnect_scale_out %>%
filter(pre_post == 'End')
Regression for Social Connection Composite (1-WEEK POST / outliers removed)
EQ_MM_Social_model_1wk <- lm (EMA_social_comp ~ Condition, data = socialconnect_scale_out_1wkpost)
summary(EQ_MM_Social_model_1wk)
##
## Call:
## lm(formula = EMA_social_comp ~ Condition, data = socialconnect_scale_out_1wkpost)
##
## Residuals:
## Min 1Q Median 3Q Max
## -11.9029 -2.6537 0.3463 3.3078 9.0971
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 13.6537 0.2284 59.776 <2e-16 ***
## Condition -0.7508 0.3169 -2.369 0.0181 *
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.092 on 666 degrees of freedom
## Multiple R-squared: 0.008357, Adjusted R-squared: 0.006868
## F-statistic: 5.613 on 1 and 666 DF, p-value: 0.01811
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model_1wk)
|
|
EMA social comp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
13.65
|
13.21 – 14.10
|
<0.001
|
|
Condition
|
-0.75
|
-1.37 – -0.13
|
0.018
|
|
Observations
|
668
|
|
R2 / R2 adjusted
|
0.008 / 0.007
|
#ggplot(socialconnect_scale_out_1wkpost) +
#geom_bar( aes(x=Condition, y=EMA_social_comp), stat="identity", fill="skyblue", #alpha=0.7)
Running a regression model to look at the effect of condition at one-week post for composite score for positive, close, and connected social interactions reveals a significant effect (t(666)=-2.37, p = 0.02).
Regression for Social Connection Composite (14-WEEK POST / outliers removed)
EQ_MM_Social_model_14wk <- lm (EMA_social_comp ~ Condition, data = socialconnect_scale_out_14wkpost)
summary(EQ_MM_Social_model_14wk)
##
## Call:
## lm(formula = EMA_social_comp ~ Condition, data = socialconnect_scale_out_14wkpost)
##
## Residuals:
## Min 1Q Median 3Q Max
## -12.7051 -3.0592 -0.0592 3.2949 10.2949
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 13.0592 0.2473 52.817 < 2e-16 ***
## Condition -1.3542 0.3507 -3.861 0.000124 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 4.505 on 658 degrees of freedom
## Multiple R-squared: 0.02215, Adjusted R-squared: 0.02067
## F-statistic: 14.91 on 1 and 658 DF, p-value: 0.0001241
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model_14wk)
|
|
EMA social comp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
13.06
|
12.57 – 13.54
|
<0.001
|
|
Condition
|
-1.35
|
-2.04 – -0.67
|
<0.001
|
|
Observations
|
660
|
|
R2 / R2 adjusted
|
0.022 / 0.021
|
Running a regression model to look at the effect of condition at one-week post for composite score for positive, close, and connected social interactions reveals a significant effect (t(658)=-3.86, p = 0.00).
Plotting EMA_comp scores w/ outliers removed
library(ggplot2)
soc_connect_summary_out <- summarySE(socialconnect_scale_out, measurevar="EMA_social_comp", groupvars=c("pre_post", "Condition"))
soc_connect_summary_out
## pre_post Condition N EMA_social_comp sd se ci
## 1 Base 0 321 13.65368 3.782837 0.2111374 0.4153927
## 2 Base 1 347 12.90287 4.359070 0.2340071 0.4602555
## 3 End 0 332 13.05921 3.963221 0.2175100 0.4278763
## 4 End 1 328 11.70506 4.994264 0.2757621 0.5424916
soc_connect_summary_out$Condition <- as.factor(soc_connect_summary_out$Condition)
library(plyr)
soc_connect_summary_out$pre_post<- revalue(soc_connect_summary_out$pre_post, c("Base"="1-Week Post", "End"="14-Weeks Post"))
#Basic line plot
p<- ggplot(data=soc_connect_summary_out, aes(x=as.factor(pre_post), y=EMA_social_comp, group=Condition, color=Condition)) +
geom_line(aes(linetype=Condition)) + geom_point(aes(shape=Condition))+
scale_color_brewer(palette="Paired")+
labs(title="Social Connection at 1-week and 14-weeks Post",x="Timepoint", y = "Social Connection")+
theme_classic()
p + theme_classic() + scale_color_manual(values=c('orange1','olivedrab3'))

#Basic line plot with confidence intervals
p<- ggplot(data=soc_connect_summary_out, aes(x=as.factor(pre_post), y=EMA_social_comp, group=Condition, color=Condition)) +
geom_line(aes(linetype=Condition)) + geom_point(aes(shape=Condition))+
scale_color_brewer(palette="Paired")+
labs(title="Social Connection at 1-week and 14-weeks Post",x="Timepoint", y = "Social Connection")+
theme_classic() +
geom_errorbar(aes(ymin=EMA_social_comp-ci, ymax=EMA_social_comp+ci), width=.2,
position=position_dodge(0.05))
p + theme_classic() + scale_color_manual(values=c('orange1','olivedrab3'))

# Does it make sense to have an N? Do I use N for Pps or for observations
///NEGATIVE SOCIAL INTERACTIONS COMPOSITE///
Describing the data
# Descriptives - EMA Social Connection Composite (EMA_social_comp)
# 1-week post
psych::describeBy(socialconnect_scale_1wkpost$EMA_neg_social_comp, socialconnect_scale_1wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min
## X11 1 0 1 323 1.956048 1.221739 1.259878 1.740402 0.3852957 1
## X12 2 1 1 347 1.926877 1.099753 2.000000 1.757586 1.4826000 1
## max range skew kurtosis se
## X11 6.000000 5.000000 1.2762762 0.94670774 0.06797938
## X12 5.259878 4.259878 0.9822507 -0.01134774 0.05903781
# 14-weeks post
psych::describeBy(socialconnect_scale_14wkpost$EMA_neg_social_comp, socialconnect_scale_14wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 344 1.871247 1.180213 1 1.645613 0 1 6 5
## X12 2 1 1 331 1.693735 1.132470 1 1.463573 0 1 8 7
## skew kurtosis se
## X11 1.316492 0.9790247 0.06363285
## X12 1.975102 4.5200139 0.06224619
# Post
psych::describeBy(socialconnect_scale_include2$EMA_neg_social_comp, socialconnect_scale_include2$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 667 1.912313 1.200348 1 1.691502 0 1 6 5
## X12 2 1 1 678 1.813057 1.121102 1 1.605171 0 1 8 7
## skew kurtosis se
## X11 1.300701 0.9831728 0.04647765
## X12 1.459353 2.0726548 0.04305567
boxplot(EMA_neg_social_comp~Condition,socialconnect_scale_include2, main="Brief Negative Social Connection Scores by Condition",
xlab="Condition", ylab="Negative Social Interactions Comp Score")

Mixed model for Negative Social Interactions Composite (POST)
# NEED TO UPDATE THESE TO REMOVE "PRE_POST" FROM (1 + pre_post | PID) once I confirm with David.
# Model 1 Comp
EQ_MM_Social_model_negcomp <- lmer (EMA_neg_social_comp ~ pre_post * Condition + #fixed effects
(1 + pre_post | PID), data = socialconnect_scale_include2)
#this is a group by time interaction
#3 predictors: 1) Condition(Group), 2) Time, 3) time by condition (group x time)
# "1 + pre_post | PID" estimate a random intercept and a random slope for each individual
#summary(EQ_MM_Social_model)
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model_negcomp)
|
|
EMA neg social comp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
1.95
|
1.74 – 2.16
|
<0.001
|
|
pre_post [End]
|
-0.07
|
-0.28 – 0.13
|
0.484
|
|
Condition
|
0.00
|
-0.29 – 0.30
|
0.993
|
pre_post [End] * Condition
|
-0.15
|
-0.44 – 0.14
|
0.310
|
|
Random Effects
|
|
σ2
|
0.89
|
|
τ00 PID
|
0.47
|
|
τ11 PID.pre_postEnd
|
0.30
|
|
ρ01 PID
|
-0.42
|
|
ICC
|
0.34
|
|
N PID
|
111
|
|
Observations
|
1345
|
|
Marginal R2 / Conditional R2
|
0.006 / 0.348
|
#This model does not yet account for person-level predictors
# Plotting model
library(sjPlot)
plot_model(model = EQ_MM_Social_model_negcomp, type = "int")
# Regression for Negative Social Interactions Composite (1-WEEK POST)
EQ_MM_Social_model_neg_1wk <- lm (EMA_neg_social_comp ~ Condition, data = socialconnect_scale_1wkpost)
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model_neg_1wk)
|
|
EMA neg social comp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
1.96
|
1.83 – 2.08
|
<0.001
|
|
Condition
|
-0.03
|
-0.21 – 0.15
|
0.745
|
|
Observations
|
670
|
|
R2 / R2 adjusted
|
0.000 / -0.001
|
Regression for Negative Social Interactions Composite (14-WEEK POST)
EQ_MM_Social_model_neg_14wk <- lm (EMA_neg_social_comp ~ Condition, data = socialconnect_scale_14wkpost)
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model_neg_14wk)
|
|
EMA neg social comp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
1.87
|
1.75 – 1.99
|
<0.001
|
|
Condition
|
-0.18
|
-0.35 – -0.00
|
0.047
|
|
Observations
|
675
|
|
R2 / R2 adjusted
|
0.006 / 0.004
|
Plotting EMA_neg_social_comp scores
library(ggplot2)
neg_soc_connect_summary <- summarySE(socialconnect_scale_include2, measurevar="EMA_neg_social_comp", groupvars=c("pre_post", "Condition"))
neg_soc_connect_summary
## pre_post Condition N EMA_neg_social_comp sd se ci
## 1 Base 0 323 1.956048 1.221739 0.06797938 0.1337398
## 2 Base 1 347 1.926877 1.099753 0.05903781 0.1161182
## 3 End 0 344 1.871247 1.180213 0.06363285 0.1251597
## 4 End 1 331 1.693735 1.132470 0.06224619 0.1224494
neg_soc_connect_summary$Condition <- as.factor(neg_soc_connect_summary$Condition)
library(plyr)
neg_soc_connect_summary$pre_post<- revalue(neg_soc_connect_summary$pre_post, c("Base"="1-Week Post", "End"="14-Weeks Post"))
#Basic line plot with confidence intervals
p<- ggplot(data=neg_soc_connect_summary, aes(x=as.factor(pre_post), y=EMA_neg_social_comp, group=Condition, color=Condition)) +
geom_line(aes(linetype=Condition)) + geom_point(aes(shape=Condition))+
scale_color_brewer(palette="Paired")+
labs(title="Negative Social Interactions at 1-week and 14-weeks Post",x="Timepoint", y = "Negative Social Interactions")+
theme_classic() +
geom_errorbar(aes(ymin=EMA_neg_social_comp-ci, ymax=EMA_neg_social_comp+ci), width=.2,
position=position_dodge(0.05))
p + theme_classic() + scale_color_manual(values=c('orange1','olivedrab3'))

# Does it make sense to have an N? Do I use N for Pps or for observations
MODELS FOR INDIVIDUAL ITEMS
NUMBER OF SOCIAL INTERACTIONS
Describing the data
# Total number of social interactions (soc_numpeople_imp)
# 1-week post
psych::describeBy(socialconnect_scale_1wkpost$soc_numpeople_imp, socialconnect_scale_1wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 323 3.431447 1.140636 3 3.472423 1.4826 1 5 4
## X12 2 1 1 347 3.303624 1.068567 3 3.302357 1.4826 1 5 4
## skew kurtosis se
## X11 -0.21942506 -0.8245707 0.06346670
## X12 -0.05801778 -0.7291598 0.05736367
# 14-weeks post
psych::describeBy(socialconnect_scale_14wkpost$soc_numpeople_imp, socialconnect_scale_14wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 344 3.080047 1.241756 3 3.110639 1.4826 0 5 5
## X12 2 1 1 331 2.903863 1.241911 3 2.902561 1.4826 0 5 5
## skew kurtosis se
## X11 -0.03365631 -0.8264586 0.06695100
## X12 -0.01720361 -0.6383279 0.06826158
# Post
psych::describeBy(socialconnect_scale_include2$soc_numpeople_imp, socialconnect_scale_include2$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 667 3.250216 1.205842 3 3.285783 1.4826 0 5 5
## X12 2 1 1 678 3.108461 1.172758 3 3.127824 1.4826 0 5 5
## skew kurtosis se
## X11 -0.1448039 -0.8151606 0.04669038
## X12 -0.1068199 -0.5861024 0.04503951
boxplot(soc_numpeople_imp~Condition,socialconnect_scale_include2, main="Brief Social Connection Scores by Condition",
xlab="Condition", ylab="Total number of social interactions")

Mixed model for Number of social interactions (POST)
# NEED TO UPDATE THESE TO REMOVE "PRE_POST" FROM (1 + pre_post | PID) once I confirm with David.
EQ_MM_Social_model7 <- lmer (soc_numpeople_imp ~ pre_post * Condition + #fixed effects
(1 + pre_post | PID), data = socialconnect_scale_include2)
sjPlot::tab_model(EQ_MM_Social_model7)
|
|
soc numpeople imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
3.43
|
3.21 – 3.66
|
<0.001
|
|
pre_post [End]
|
-0.33
|
-0.52 – -0.14
|
0.001
|
|
Condition
|
-0.09
|
-0.40 – 0.22
|
0.570
|
pre_post [End] * Condition
|
-0.05
|
-0.31 – 0.22
|
0.722
|
|
Random Effects
|
|
σ2
|
0.65
|
|
τ00 PID
|
0.59
|
|
τ11 PID.pre_postEnd
|
0.27
|
|
ρ01 PID
|
0.02
|
|
ICC
|
0.53
|
|
N PID
|
111
|
|
Observations
|
1345
|
|
Marginal R2 / Conditional R2
|
0.024 / 0.541
|
#This model does not yet account for person-level predictors
# Plotting model
library(sjPlot)
plot_model(model = EQ_MM_Social_model7, type = "int")

Regression for Number of social interactions (1-WEEK POST)
EQ_MM_Social_model7_1wk <- lm (soc_numpeople_imp ~ Condition, data = socialconnect_scale_1wkpost)
summary(EQ_MM_Social_model7_1wk)
##
## Call:
## lm(formula = soc_numpeople_imp ~ Condition, data = socialconnect_scale_1wkpost)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.4314 -0.4315 -0.3036 0.6964 1.6964
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.43145 0.06142 55.866 <2e-16 ***
## Condition -0.12782 0.08535 -1.498 0.135
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.104 on 668 degrees of freedom
## Multiple R-squared: 0.003347, Adjusted R-squared: 0.001855
## F-statistic: 2.243 on 1 and 668 DF, p-value: 0.1347
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model7_1wk)
|
|
soc numpeople imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
3.43
|
3.31 – 3.55
|
<0.001
|
|
Condition
|
-0.13
|
-0.30 – 0.04
|
0.135
|
|
Observations
|
670
|
|
R2 / R2 adjusted
|
0.003 / 0.002
|
Running a regression model to look at the effect of condition at one-week post for number of social interactions reveals a non-significant effect (t(668)=-1.50, p = 0.14).
Regression for Number of social interactions (14-WEEK POST)
EQ_MM_Social_model7_14wk <- lm (soc_numpeople_imp ~ Condition, data = socialconnect_scale_14wkpost)
summary(EQ_MM_Social_model7_14wk)
##
## Call:
## lm(formula = soc_numpeople_imp ~ Condition, data = socialconnect_scale_14wkpost)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.08005 -0.90386 -0.08005 0.91995 2.09614
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.08005 0.06696 46.002 <2e-16 ***
## Condition -0.17618 0.09561 -1.843 0.0658 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.242 on 673 degrees of freedom
## Multiple R-squared: 0.00502, Adjusted R-squared: 0.003541
## F-statistic: 3.395 on 1 and 673 DF, p-value: 0.06582
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model7_14wk)
|
|
soc numpeople imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
3.08
|
2.95 – 3.21
|
<0.001
|
|
Condition
|
-0.18
|
-0.36 – 0.01
|
0.066
|
|
Observations
|
675
|
|
R2 / R2 adjusted
|
0.005 / 0.004
|
Running a regression model to look at the effect of condition at fourteen-week post for number of social interactions reveals a non-significant effect (t(673)=-1.84, p = 0.07).
NUMBER OF UNIQUE SOCIAL INTERACTIONS
Describing the data
# Number of unique social interactions (soc_numdifpeople_imp)
# 1-week post
psych::describeBy(socialconnect_scale_1wkpost$soc_numdifpeople_imp, socialconnect_scale_1wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max
## X11 1 0 1 323 3.213456 0.9656918 3 3.188981 1.4826 0 5
## X12 2 1 1 347 3.066127 0.9758412 3 3.039234 1.4826 1 5
## range skew kurtosis se
## X11 5 -0.02211768 -0.01772336 0.05373253
## X12 4 0.09159777 -0.39869228 0.05238590
# 14-weeks post
psych::describeBy(socialconnect_scale_14wkpost$soc_numdifpeople_imp, socialconnect_scale_14wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 344 2.961974 1.091318 3 2.927244 1.4826 0 5 5
## X12 2 1 1 331 2.652487 1.022515 3 2.637634 1.4826 0 5 5
## skew kurtosis se
## X11 0.1288718 -0.2819911 0.05883995
## X12 0.2051521 0.2586399 0.05620252
# Post
psych::describeBy(socialconnect_scale_include2$soc_numdifpeople_imp, socialconnect_scale_include2$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 667 3.083756 1.039263 3 3.053954 1.4826 0 5 5
## X12 2 1 1 678 2.864188 1.019381 3 2.847278 1.4826 0 5 5
## skew kurtosis se
## X11 0.02519652 -0.17335532 0.04024041
## X12 0.11463383 -0.08426436 0.03914910
boxplot(soc_numdifpeople_imp~Condition,socialconnect_scale_include2, main="Brief Social Connection Scores by Condition",
xlab="Condition", ylab="Total number of unique social interactions")

#THIS LOOKS OFF....
Mixed model for Number of unique social interactions (POST)
# NEED TO UPDATE THESE TO REMOVE "PRE_POST" FROM (1 + pre_post | PID) once I confirm with David.
EQ_MM_Social_model6 <- lmer (soc_numdifpeople_imp ~ pre_post * Condition + #fixed effects
(1 + pre_post | PID), data = socialconnect_scale_include2)
sjPlot::tab_model(EQ_MM_Social_model6)
|
|
soc numdifpeople imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
3.22
|
3.04 – 3.40
|
<0.001
|
|
pre_post [End]
|
-0.25
|
-0.42 – -0.07
|
0.005
|
|
Condition
|
-0.14
|
-0.40 – 0.11
|
0.269
|
pre_post [End] * Condition
|
-0.13
|
-0.38 – 0.12
|
0.301
|
|
Random Effects
|
|
σ2
|
0.60
|
|
τ00 PID
|
0.37
|
|
τ11 PID.pre_postEnd
|
0.23
|
|
ρ01 PID
|
-0.11
|
|
ICC
|
0.43
|
|
N PID
|
111
|
|
Observations
|
1345
|
|
Marginal R2 / Conditional R2
|
0.033 / 0.449
|
#This model does not yet account for person-level predictors
# Plotting model
library(sjPlot)
plot_model(model = EQ_MM_Social_model6, type = "int")
# Running models with outliers removed
Detecting Outliers
#Obtaining values of outliers
library(dplyr)
library(ggplot2)
is_outlier <- function(x) {
return(x < quantile(x, 0.25) - 1.5 * IQR(x) | x > quantile(x, 0.75) + 1.5 * IQR(x))
}
socialconnect_scale_include2 %>%
group_by(Condition) %>%
mutate(outlier = ifelse(is_outlier(soc_numdifpeople_imp), soc_numdifpeople_imp, as.numeric(NA))) %>%
ggplot(., aes(x = factor(Condition), y = soc_numdifpeople_imp)) +
geom_boxplot() +
geom_text(aes(label = outlier), na.rm = TRUE, hjust = -0.3)
# Removing Outliers
socialconnect_out1 <- socialconnect_scale_include2 %>%
filter(Condition == 1, soc_numdifpeople_imp > 0)
socialconnect_out2 <- socialconnect_scale_include2 %>%
filter(Condition == 2, 5 > soc_numdifpeople_imp, soc_numdifpeople_imp > 0)
socialconnect_out <- rbind(socialconnect_out1, socialconnect_out2)
Re-running Mixed model for Number of unique social interactions (POST, outliers removed)
# NEED TO UPDATE THESE TO REMOVE "PRE_POST" FROM (1 + pre_post | PID) once I confirm with David.
EQ_MM_Social_model_out <- lmer (soc_numdifpeople_imp ~ pre_post * Condition + #fixed effects
(1 + pre_post | PID), data = socialconnect_out)
## fixed-effect model matrix is rank deficient so dropping 2 columns / coefficients
sjPlot::tab_model(EQ_MM_Social_model_out) #Why isn't condition showing up???
|
|
soc numdifpeople imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
3.08
|
2.89 – 3.26
|
<0.001
|
|
pre_post [End]
|
-0.35
|
-0.53 – -0.17
|
<0.001
|
|
Random Effects
|
|
σ2
|
0.56
|
|
τ00 PID
|
0.40
|
|
τ11 PID.pre_postEnd
|
0.26
|
|
ρ01 PID
|
-0.29
|
|
ICC
|
0.44
|
|
N PID
|
56
|
|
Observations
|
673
|
|
Marginal R2 / Conditional R2
|
0.030 / 0.457
|
#This model does not yet account for person-level predictors
# Plotting model
library(sjPlot)
plot_model(model = EQ_MM_Social_model_out, type = "int")
## Error: Confidence intervals could not be computed.
## * Reason: "non-conformable arguments"
## * Source: mm %*% vcm

Regression for Number of unique social interactions (1-WEEK POST, outliers included)
EQ_MM_Social_model6_1wk <- lm (soc_numdifpeople_imp ~ Condition, data = socialconnect_scale_1wkpost)
summary(EQ_MM_Social_model6_1wk)
##
## Call:
## lm(formula = soc_numdifpeople_imp ~ Condition, data = socialconnect_scale_1wkpost)
##
## Residuals:
## Min 1Q Median 3Q Max
## -3.2135 -0.2135 -0.0661 0.7865 1.9339
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 3.21346 0.05403 59.480 <2e-16 ***
## Condition -0.14733 0.07507 -1.963 0.0501 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.971 on 668 degrees of freedom
## Multiple R-squared: 0.005733, Adjusted R-squared: 0.004244
## F-statistic: 3.851 on 1 and 668 DF, p-value: 0.05012
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model6_1wk)
|
|
soc numdifpeople imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
3.21
|
3.11 – 3.32
|
<0.001
|
|
Condition
|
-0.15
|
-0.29 – 0.00
|
0.050
|
|
Observations
|
670
|
|
R2 / R2 adjusted
|
0.006 / 0.004
|
Running a regression model to look at the effect of condition at one-week post for number of unique social interactions reveals a significant effect (t(668)=-1.96, p = 0.05).
Regression for Number of unique social interactions (14-WEEK POST, outliers included)
EQ_MM_Social_model6_14wk <- lm (soc_numdifpeople_imp ~ Condition, data = socialconnect_scale_14wkpost)
summary(EQ_MM_Social_model6_14wk)
##
## Call:
## lm(formula = soc_numdifpeople_imp ~ Condition, data = socialconnect_scale_14wkpost)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.96197 -0.65249 0.03803 0.34751 2.34751
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.96197 0.05705 51.918 < 2e-16 ***
## Condition -0.30949 0.08147 -3.799 0.000159 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.058 on 673 degrees of freedom
## Multiple R-squared: 0.02099, Adjusted R-squared: 0.01954
## F-statistic: 14.43 on 1 and 673 DF, p-value: 0.0001586
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model6_14wk)
|
|
soc numdifpeople imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
2.96
|
2.85 – 3.07
|
<0.001
|
|
Condition
|
-0.31
|
-0.47 – -0.15
|
<0.001
|
|
Observations
|
675
|
|
R2 / R2 adjusted
|
0.021 / 0.020
|
Running a regression model to look at the effect of condition at fourteen-week post for number of unique social interactions reveals a significant effect (t(668)=-1.96, p = 0.05).
/// SOCIAL CLOSENESS / CONNECTION ///
# Descriptives - Social closeness/connection (soc_closeness_imp)
# 1-week post
psych::describeBy(socialconnect_scale_1wkpost$soc_closeness_imp, socialconnect_scale_1wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 323 2.029290 1.781433 3 2.264327 1.4826 -3 4 7
## X12 2 1 1 347 1.625134 2.027648 3 1.874270 1.4826 -3 4 7
## skew kurtosis se
## X11 -1.075461 0.5779050 0.09912159
## X12 -0.906075 -0.1162136 0.10884983
# 14-weeks post
psych::describeBy(socialconnect_scale_14wkpost$soc_closeness_imp, socialconnect_scale_14wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 344 1.823230 1.970237 3 2.076779 1.4826 -3 4 7
## X12 2 1 1 331 1.452358 2.210033 1 1.682001 2.9652 -3 4 7
## skew kurtosis se
## X11 -0.9601319 0.1325495 0.1062281
## X12 -0.6562069 -0.7061560 0.1214744
# Post
psych::describeBy(socialconnect_scale_include2$soc_closeness_imp, socialconnect_scale_include2$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max
## X11 1 0 1 667 1.923016 1.882594 3.000000 2.167573 1.482600 -3 4
## X12 2 1 1 678 1.540784 2.118843 1.730337 1.780610 1.882402 -3 4
## range skew kurtosis se
## X11 7 -1.0252306 0.3657528 0.07289433
## X12 7 -0.7804077 -0.4308346 0.08137366
boxplot(soc_closeness_imp~Condition,socialconnect_scale_include2, main="Brief Social Connection Scores by Condition",
xlab="Condition", ylab="Perceived social closeness / connection")

Mixed model for social closeness (POST)
#Model 4 social closeness
EQ_MM_Social_model_close <- lmer (soc_closeness_imp ~ pre_post * Condition + #fixed effects
(1 + pre_post | PID), data = socialconnect_scale_include2)
#this is a group by time interaction
#3 predictors: 1) Condition(Group), 2) Time, 3) time by condition (group x time)
# "1 + pre_post | PID" estimate a random intercept and a random slope for each individual
summary(EQ_MM_Social_model_close)
## Linear mixed model fit by REML. t-tests use Satterthwaite's method [
## lmerModLmerTest]
## Formula: soc_closeness_imp ~ pre_post * Condition + (1 + pre_post | PID)
## Data: socialconnect_scale_include2
##
## REML criterion at convergence: 5452.8
##
## Scaled residuals:
## Min 1Q Median 3Q Max
## -3.1960 -0.4915 0.1954 0.6618 3.2262
##
## Random effects:
## Groups Name Variance Std.Dev. Corr
## PID (Intercept) 0.8587 0.9267
## pre_postEnd 0.5958 0.7719 0.07
## Residual 2.8257 1.6810
## Number of obs: 1345, groups: PID, 111
##
## Fixed effects:
## Estimate Std. Error df t value Pr(>|t|)
## (Intercept) 2.05936 0.15678 113.45533 13.136 <2e-16 ***
## pre_postEnd -0.23918 0.16792 104.66484 -1.424 0.1573
## Condition -0.40727 0.21975 111.25272 -1.853 0.0665 .
## pre_postEnd:Condition 0.03363 0.23742 104.35512 0.142 0.8876
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Correlation of Fixed Effects:
## (Intr) pr_psE Condtn
## pre_postEnd -0.305
## Condition -0.713 0.217
## pr_pstEnd:C 0.216 -0.707 -0.296
sjPlot::tab_model(EQ_MM_Social_model_close)
|
|
soc closeness imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
2.06
|
1.75 – 2.37
|
<0.001
|
|
pre_post [End]
|
-0.24
|
-0.57 – 0.09
|
0.154
|
|
Condition
|
-0.41
|
-0.84 – 0.02
|
0.064
|
pre_post [End] * Condition
|
0.03
|
-0.43 – 0.50
|
0.887
|
|
Random Effects
|
|
σ2
|
2.83
|
|
τ00 PID
|
0.86
|
|
τ11 PID.pre_postEnd
|
0.60
|
|
ρ01 PID
|
0.07
|
|
ICC
|
0.30
|
|
N PID
|
111
|
|
Observations
|
1345
|
|
Marginal R2 / Conditional R2
|
0.012 / 0.308
|
#This model does not yet account for person-level predictors
#Model 4
library(sjPlot)
plot_model(model = EQ_MM_Social_model_close, type = "int")

Regression for Social closeness/connection (1-WEEK POST)
EQ_MM_Social_model2_1wk <- lm (soc_closeness_imp ~ Condition, data = socialconnect_scale_1wkpost)
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model2_1wk)
|
|
soc closeness imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
2.03
|
1.82 – 2.24
|
<0.001
|
|
Condition
|
-0.40
|
-0.69 – -0.11
|
0.006
|
|
Observations
|
670
|
|
R2 / R2 adjusted
|
0.011 / 0.010
|
Regression for Social closeness/connection (14-WEEK POST)
EQ_MM_Social_model2_14wk <- lm (soc_closeness_imp ~ Condition, data = socialconnect_scale_14wkpost)
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model2_14wk)
|
|
soc closeness imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
1.82
|
1.60 – 2.04
|
<0.001
|
|
Condition
|
-0.37
|
-0.69 – -0.05
|
0.022
|
|
Observations
|
675
|
|
R2 / R2 adjusted
|
0.008 / 0.006
|
Removing outliers
#Obtaining values of outliers
library(dplyr)
library(ggplot2)
is_outlier <- function(x) {
return(x < quantile(x, 0.25) - 1.5 * IQR(x) | x > quantile(x, 0.75) + 1.5 * IQR(x))
}
socialconnect_scale_include2 %>%
group_by(Condition) %>%
mutate(outlier = ifelse(is_outlier(soc_closeness_imp), soc_closeness_imp, as.numeric(NA))) %>%
ggplot(., aes(x = factor(Condition), y = soc_closeness_imp)) +
geom_boxplot() +
geom_text(aes(label = outlier), na.rm = TRUE, hjust = -0.3)

# NEED TO FIGURE OUT HOW TO Remove outliers at both levels
Removing Outliers
socialconnect_scale_include2_out4 <- socialconnect_scale_include2 %>%
filter(Condition == 0, soc_closeness_imp > -3)
socialconnect_scale_include2_1_4 <- socialconnect_scale_include2 %>%
filter(Condition == 1, soc_closeness_imp > -3)
socialconnect_scale_out4 <- rbind(socialconnect_scale_include2_out4, socialconnect_scale_include2_1_4)
#run the models with and without these outliers
Mixed model for EMA Social Connection - Closeness (outliers removed)
library(lme4)
library(lmerTest)
socialconnect_scale_out4 <- socialconnect_scale_out4 %>%
mutate(pre_post = as.factor(pre_post),
timepoint = as.factor(timepoint))
EQ_MM_SocialConnect_model_out4 <- lmer (soc_closeness_imp ~ pre_post * Condition + #fixed effects
(1 + pre_post | PID), data = socialconnect_scale_out4)
#this is a group by time interaction
#3 predictors: 1) Condition(Group), 2) Time, 3) time by condition (group x time)
# "1 + pre_post | PID" estimate a random intercept and a random slope for each individual
#summary(EQ_MM_SocialConnect_model_out4)
sjPlot::tab_model(EQ_MM_SocialConnect_model_out4)
|
|
soc closeness imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
2.22
|
1.99 – 2.45
|
<0.001
|
|
pre_post [End]
|
-0.12
|
-0.41 – 0.18
|
0.440
|
|
Condition
|
-0.22
|
-0.55 – 0.11
|
0.182
|
pre_post [End] * Condition
|
-0.05
|
-0.46 – 0.37
|
0.833
|
|
Random Effects
|
|
σ2
|
1.90
|
|
τ00 PID
|
0.44
|
|
τ11 PID.pre_postEnd
|
0.55
|
|
ρ01 PID
|
0.04
|
|
ICC
|
0.28
|
|
N PID
|
111
|
|
Observations
|
1253
|
|
Marginal R2 / Conditional R2
|
0.007 / 0.283
|
#This model does not yet account for person-level predictors
library(sjPlot)
plot_model(model = EQ_MM_SocialConnect_model_out4, type = "int")

Creating separate dataframes for 1-week and 14-week follow-up (outliers removed)
socialconnect_scale_out_1wkpost <- socialconnect_scale_out4 %>%
filter(pre_post == 'Base')
socialconnect_scale_out_14wkpost <- socialconnect_scale_out4 %>%
filter(pre_post == 'End')
###Check to see if outliers were adequately removed.
Regression for Social closeness/connection (1-WEEK POST / outliers removed)
EQ_MM_Social_model2_out_1wk <- lm (soc_closeness_imp ~ Condition, data = socialconnect_scale_1wkpost)
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model2_out_1wk)
|
|
soc closeness imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
2.03
|
1.82 – 2.24
|
<0.001
|
|
Condition
|
-0.40
|
-0.69 – -0.11
|
0.006
|
|
Observations
|
670
|
|
R2 / R2 adjusted
|
0.011 / 0.010
|
Regression for Social closeness/connection (14-WEEK POST / outliers removed)
EQ_MM_Social_model2_out_14wk <- lm (soc_closeness_imp ~ Condition, data = socialconnect_scale_14wkpost)
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model2_out_14wk)
|
|
soc closeness imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
1.82
|
1.60 – 2.04
|
<0.001
|
|
Condition
|
-0.37
|
-0.69 – -0.05
|
0.022
|
|
Observations
|
675
|
|
R2 / R2 adjusted
|
0.008 / 0.006
|
/// POSITIVE SOCIAL INTERACTIONS ///
# Number of positive social interactions (soc_positive_imp)
# 1-week post
psych::describeBy(socialconnect_scale_1wkpost$soc_positive_imp, socialconnect_scale_1wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 323 2.697095 1.116944 3 2.718771 1.4826 0 5 5
## X12 2 1 1 347 2.666172 1.183559 3 2.681583 1.4826 0 5 5
## skew kurtosis se
## X11 -0.06471052 -0.5336181 0.06214843
## X12 -0.06403106 -0.6010315 0.06353680
# 14-weeks post
psych::describeBy(socialconnect_scale_14wkpost$soc_positive_imp, socialconnect_scale_14wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 344 2.553266 1.277810 2 2.475809 1.4826 0 5 5
## X12 2 1 1 331 2.406589 1.338948 2 2.398418 1.4826 0 5 5
## skew kurtosis se
## X11 0.34129538 -0.5951527 0.06889492
## X12 0.07087303 -0.7941901 0.07359526
# Post
psych::describeBy(socialconnect_scale_include2$soc_positive_imp, socialconnect_scale_include2$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 667 2.622916 1.203855 3 2.591561 1.4826 0 5 5
## X12 2 1 1 678 2.539443 1.267544 3 2.543644 1.4826 0 5 5
## skew kurtosis se
## X11 0.16173932 -0.5744157 0.04661346
## X12 -0.02326539 -0.6910354 0.04867975
boxplot(soc_positive_imp~Condition,socialconnect_scale_include2, main="Brief Social Connection Scores by Condition",
xlab="Condition", ylab="Positive Interactions")

Mixed model for positive social interactions (POST)
#Model positive social interactions
EQ_MM_Social_model_pos <- lmer (soc_positive_imp ~ pre_post * Condition + #fixed effects
(1 + pre_post | PID), data = socialconnect_scale_include2)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.00279627 (tol = 0.002, component 1)
#this is a group by time interaction
#3 predictors: 1) Condition(Group), 2) Time, 3) time by condition (group x time)
# "1 + pre_post | PID" estimate a random intercept and a random slope for each individual
#summary(EQ_MM_Social_model_close)
sjPlot::tab_model(EQ_MM_Social_model_pos)
|
|
soc positive imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
2.70
|
2.46 – 2.94
|
<0.001
|
|
pre_post [End]
|
-0.14
|
-0.31 – 0.03
|
0.112
|
|
Condition
|
-0.02
|
-0.36 – 0.32
|
0.901
|
pre_post [End] * Condition
|
-0.06
|
-0.31 – 0.18
|
0.600
|
|
Random Effects
|
|
σ2
|
0.64
|
|
τ00 PID
|
0.71
|
|
τ11 PID.pre_postEnd
|
0.20
|
|
ρ01 PID
|
0.18
|
|
ICC
|
0.58
|
|
N PID
|
111
|
|
Observations
|
1345
|
|
Marginal R2 / Conditional R2
|
0.005 / 0.581
|
#This model does not yet account for person-level predictors
#Model 4
library(sjPlot)
plot_model(model = EQ_MM_Social_model_pos, type = "int")
# Regression for positive social interactions (1-WEEK POST)
EQ_MM_Social_model4_1wk <- lm (soc_positive_imp ~ Condition, data = socialconnect_scale_1wkpost)
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model4_1wk)
|
|
soc positive imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
2.70
|
2.57 – 2.82
|
<0.001
|
|
Condition
|
-0.03
|
-0.21 – 0.14
|
0.729
|
|
Observations
|
670
|
|
R2 / R2 adjusted
|
0.000 / -0.001
|
Regression for positive social interactions (14-WEEK POST)
EQ_MM_Social_model4_14wk <- lm (soc_positive_imp ~ Condition, data = socialconnect_scale_14wkpost)
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model4_14wk)
|
|
soc positive imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
2.55
|
2.41 – 2.69
|
<0.001
|
|
Condition
|
-0.15
|
-0.34 – 0.05
|
0.146
|
|
Observations
|
675
|
|
R2 / R2 adjusted
|
0.003 / 0.002
|
Removing Outliers
/// DEGREE OF POSITIVE SOCIAL INTERACTIONS ///
# Degree of positive social interactions (soc_howpos_imp)
# 1-week post
psych::describeBy(socialconnect_scale_1wkpost$soc_howpos_imp, socialconnect_scale_1wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max
## X11 1 0 1 323 2.200946 0.4747391 2.21063 2.200407 0.3122799 1 3
## X12 2 1 1 347 2.241808 0.5133123 2.21063 2.264901 0.3122799 1 3
## range skew kurtosis se
## X11 2 -0.06938184 0.9631913 0.02641519
## X12 2 -0.25338194 0.5105925 0.02755605
# 14-weeks post
psych::describeBy(socialconnect_scale_14wkpost$soc_howpos_imp, socialconnect_scale_14wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max
## X11 1 0 1 344 2.231654 0.5278829 2 2.241627 0.0000000 1 3
## X12 2 1 1 331 2.165545 0.5784341 2 2.206775 0.3122799 1 3
## range skew kurtosis se
## X11 2 -0.00536284 0.01646169 0.02846154
## X12 2 -0.20002055 -0.10722114 0.03179361
# Post
psych::describeBy(socialconnect_scale_include2$soc_howpos_imp, socialconnect_scale_include2$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max
## X11 1 0 1 667 2.216783 0.5027090 2.00000 2.221672 0.3122799 1 3
## X12 2 1 1 678 2.204576 0.5470021 2.21063 2.243939 0.3122799 1 3
## range skew kurtosis se
## X11 2 -0.02187152 0.4266876 0.01946497
## X12 2 -0.24739523 0.1921725 0.02100749
boxplot(soc_howpos_imp~Condition,socialconnect_scale_include2, main="Brief Social Connection Scores by Condition",
xlab="Condition", ylab="Degree of Positive Interactions")

Mixed model for Degree of positive social interactions (POST)
#Model degree of positive social interactions
EQ_MM_Social_model9 <- lmer (soc_howpos_imp ~ pre_post * Condition + #fixed effects
(1 + pre_post | PID), data = socialconnect_scale_include2)
sjPlot::tab_model(EQ_MM_Social_model9)
|
|
soc howpos imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
2.21
|
2.14 – 2.28
|
<0.001
|
|
pre_post [End]
|
0.03
|
-0.06 – 0.11
|
0.535
|
|
Condition
|
0.04
|
-0.06 – 0.14
|
0.438
|
pre_post [End] * Condition
|
-0.10
|
-0.22 – 0.02
|
0.097
|
|
Random Effects
|
|
σ2
|
0.22
|
|
τ00 PID
|
0.03
|
|
τ11 PID.pre_postEnd
|
0.03
|
|
ρ01 PID
|
0.33
|
|
ICC
|
0.21
|
|
N PID
|
111
|
|
Observations
|
1345
|
|
Marginal R2 / Conditional R2
|
0.003 / 0.213
|
#This model does not yet account for person-level predictors
#Model 4
library(sjPlot)
plot_model(model = EQ_MM_Social_model9, type = "int")
# Regression for Degree of positive social interactions (1-WEEK POST)
EQ_MM_Social_model9_1wk <- lm (soc_howpos_imp ~ Condition, data = socialconnect_scale_1wkpost)
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model9_1wk)
|
|
soc howpos imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
2.20
|
2.15 – 2.26
|
<0.001
|
|
Condition
|
0.04
|
-0.03 – 0.12
|
0.286
|
|
Observations
|
670
|
|
R2 / R2 adjusted
|
0.002 / 0.000
|
Regression for Degree of positive social interactions (14-WEEK POST)
EQ_MM_Social_model9_14wk <- lm (soc_howpos_imp ~ Condition, data = socialconnect_scale_14wkpost)
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model9_14wk)
|
|
soc howpos imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
2.23
|
2.17 – 2.29
|
<0.001
|
|
Condition
|
-0.07
|
-0.15 – 0.02
|
0.121
|
|
Observations
|
675
|
|
R2 / R2 adjusted
|
0.004 / 0.002
|
Removing Outliers
/// NEGATIVE SOCIAL INTERACTIONS ///
# Number of negative social interactions (soc_neg_imp)
# 1-week post
psych::describeBy(socialconnect_scale_1wkpost$soc_neg_imp, socialconnect_scale_1wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 323 0.7065164 0.9232930 0 0.5374703 0 0 5 5
## X12 2 1 1 347 0.6219228 0.7769684 0 0.4939326 0 0 4 4
## skew kurtosis se
## X11 1.556559 2.616528 0.05137340
## X12 1.213313 1.258263 0.04170985
# 14-weeks post
psych::describeBy(socialconnect_scale_14wkpost$soc_neg_imp, socialconnect_scale_14wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 344 0.6174698 0.8644165 0 0.4616290 0 0 5 5
## X12 2 1 1 331 0.4646743 0.7969989 0 0.3011593 0 0 5 5
## skew kurtosis se
## X11 1.580285 2.805182 0.04660621
## X12 2.477937 8.423070 0.04380702
# Post
psych::describeBy(socialconnect_scale_include2$soc_neg_imp, socialconnect_scale_include2$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 667 0.6605913 0.8938489 0 0.4983447 0 0 5 5
## X12 2 1 1 678 0.5451540 0.7901541 0 0.3889971 0 0 5 5
## skew kurtosis se
## X11 1.577675 2.758382 0.03460997
## X12 1.824306 4.592551 0.03034569
boxplot(soc_neg_imp~Condition,socialconnect_scale_include2, main="Brief Social Connection Scores by Condition",
xlab="Condition", ylab="Negative Interactions")

#WHY ARE THESE SO SIMILAR?
Mixed model for negative social interactions (POST)
#Model negative social interactions
EQ_MM_Social_model_neg <- lmer (soc_neg_imp ~ pre_post * Condition + #fixed effects
(1 + pre_post | PID), data = socialconnect_scale_include2)
#this is a group by time interaction
#3 predictors: 1) Condition(Group), 2) Time, 3) time by condition (group x time)
# "1 + pre_post | PID" estimate a random intercept and a random slope for each individual
#summary(EQ_MM_Social_model_close)
sjPlot::tab_model(EQ_MM_Social_model_neg)
|
|
soc neg imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
0.70
|
0.55 – 0.85
|
<0.001
|
|
pre_post [End]
|
-0.08
|
-0.24 – 0.08
|
0.320
|
|
Condition
|
-0.06
|
-0.27 – 0.15
|
0.585
|
pre_post [End] * Condition
|
-0.07
|
-0.29 – 0.15
|
0.556
|
|
Random Effects
|
|
σ2
|
0.47
|
|
τ00 PID
|
0.25
|
|
τ11 PID.pre_postEnd
|
0.19
|
|
ρ01 PID
|
-0.43
|
|
ICC
|
0.35
|
|
N PID
|
111
|
|
Observations
|
1345
|
|
Marginal R2 / Conditional R2
|
0.008 / 0.350
|
#This model does not yet account for person-level predictors
#Model 4
library(sjPlot)
plot_model(model = EQ_MM_Social_model_neg, type = "int")
# Regression for negative social interactions (1-WEEK POST)
EQ_MM_Social_model5_1wk <- lm (soc_neg_imp ~ Condition, data = socialconnect_scale_1wkpost)
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model5_1wk)
|
|
soc neg imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
0.71
|
0.61 – 0.80
|
<0.001
|
|
Condition
|
-0.08
|
-0.21 – 0.04
|
0.199
|
|
Observations
|
670
|
|
R2 / R2 adjusted
|
0.002 / 0.001
|
Regression for negative social interactions (14-WEEK POST)
EQ_MM_Social_model5_14wk <- lm (soc_neg_imp ~ Condition, data = socialconnect_scale_14wkpost)
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model5_14wk)
|
|
soc neg imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
0.62
|
0.53 – 0.71
|
<0.001
|
|
Condition
|
-0.15
|
-0.28 – -0.03
|
0.017
|
|
Observations
|
675
|
|
R2 / R2 adjusted
|
0.008 / 0.007
|
Removing outliers
/// DEGREE OF NEGATIVE SOCIAL INTERACTIONS ///
# Degree of negative social interactions (soc_howneg_imp)
# 1-week post
psych::describeBy(socialconnect_scale_1wkpost$soc_howneg_imp, socialconnect_scale_1wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 323 1.249532 0.5063675 1 1.141308 0 1 3 2
## X12 2 1 1 347 1.304954 0.5327504 1 1.210821 0 1 3 2
## skew kurtosis se
## X11 1.987501 3.157264 0.02817504
## X12 1.571219 1.567486 0.02859954
# 14-weeks post
psych::describeBy(socialconnect_scale_14wkpost$soc_howneg_imp, socialconnect_scale_14wkpost$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 344 1.253777 0.5127616 1 1.146012 0 1 3 2
## X12 2 1 1 331 1.229061 0.4957564 1 1.116299 0 1 3 2
## skew kurtosis se
## X11 1.936428 2.911768 0.02764625
## X12 2.142560 3.822752 0.02724924
# Post
psych::describeBy(socialconnect_scale_include2$soc_howneg_imp, socialconnect_scale_include2$Condition, mat = TRUE)
## item group1 vars n mean sd median trimmed mad min max range
## X11 1 0 1 667 1.251721 0.5092972 1 1.143735 0 1 3 2
## X12 2 1 1 678 1.267903 0.5160411 1 1.164776 0 1 3 2
## skew kurtosis se
## X11 1.965323 3.046739 0.01972007
## X12 1.827956 2.499665 0.01981844
boxplot(soc_howneg_imp~Condition,socialconnect_scale_include2, main="Brief Social Connection Scores by Condition",
xlab="Condition", ylab="Degree of Negative Interactions")

#WHY ARE THESE LIKE THIS?
Mixed model for degree of negative social interactions (POST)
EQ_MM_Social_model_negd <- lmer (soc_howneg_imp ~ pre_post * Condition + #fixed effects
(1 + pre_post | PID), data = socialconnect_scale_include2)
sjPlot::tab_model(EQ_MM_Social_model_negd)
|
|
soc howneg imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
1.25
|
1.17 – 1.32
|
<0.001
|
|
pre_post [End]
|
0.01
|
-0.07 – 0.08
|
0.865
|
|
Condition
|
0.06
|
-0.04 – 0.16
|
0.253
|
pre_post [End] * Condition
|
-0.08
|
-0.19 – 0.02
|
0.126
|
|
Random Effects
|
|
σ2
|
0.22
|
|
τ00 PID
|
0.04
|
|
τ11 PID.pre_postEnd
|
0.01
|
|
ρ01 PID
|
-0.17
|
|
ICC
|
0.16
|
|
N PID
|
111
|
|
Observations
|
1345
|
|
Marginal R2 / Conditional R2
|
0.003 / 0.160
|
#This model does not yet account for person-level predictors
#Model 4
library(sjPlot)
plot_model(model = EQ_MM_Social_model_negd, type = "int")
# Regression for degree of negative social interactions (1-WEEK POST)
EQ_MM_Social_model5d_1wk <- lm (soc_howneg_imp ~ Condition, data = socialconnect_scale_1wkpost)
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model5d_1wk)
|
|
soc howneg imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
1.25
|
1.19 – 1.31
|
<0.001
|
|
Condition
|
0.06
|
-0.02 – 0.13
|
0.169
|
|
Observations
|
670
|
|
R2 / R2 adjusted
|
0.003 / 0.001
|
Regression for degree of negative social interactions (14-WEEK POST)
EQ_MM_Social_model5d_14wk <- lm (soc_howneg_imp ~ Condition, data = socialconnect_scale_14wkpost)
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model5d_14wk)
|
|
soc howneg imp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
1.25
|
1.20 – 1.31
|
<0.001
|
|
Condition
|
-0.02
|
-0.10 – 0.05
|
0.525
|
|
Observations
|
675
|
|
R2 / R2 adjusted
|
0.001 / -0.001
|
Removing Outliers
******BELOW NEEDS TO BE UPDATED AND ADDED TO NEG COMP SECTION - CODE IS FROM COMP 1****** # Removing Outliers
#Obtaining values of outliers
library(dplyr)
library(ggplot2)
is_outlier <- function(x) {
return(x < quantile(x, 0.25) - 1.5 * IQR(x) | x > quantile(x, 0.75) + 1.5 * IQR(x))
}
socialconnect_scale_include2 %>%
group_by(Condition) %>%
mutate(outlier = ifelse(is_outlier(EMA_social_comp), EMA_social_comp, as.numeric(NA))) %>%
ggplot(., aes(x = factor(Condition), y = EMA_social_comp)) +
geom_boxplot() +
geom_text(aes(label = outlier), na.rm = TRUE, hjust = -0.3)

# NEED TO FIGURE OUT HOW TO Remove outliers at both levels
Removing Outliers
socialconnect_scale_include2_out <- socialconnect_scale_include2 %>%
filter(Condition == 0, EMA_social_comp > 3)
socialconnect_scale_include2_1 <- socialconnect_scale_include2 %>%
filter(Condition == 1, EMA_social_comp > -2)
socialconnect_scale_out <- rbind(socialconnect_scale_include2_out, socialconnect_scale_include2_1)
#run the models with and without these outliers
Mixed model for EMA Social Connection (outliers removed)
library(lme4)
library(lmerTest)
socialconnect_scale_out <- socialconnect_scale_out %>%
mutate(pre_post = as.factor(pre_post),
timepoint = as.factor(timepoint))
EQ_MM_SocialConnect_model_out <- lmer (EMA_social_comp ~ pre_post * Condition + #fixed effects
(1 + pre_post | PID), data = socialconnect_scale_out)
## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, :
## Model failed to converge with max|grad| = 0.00379648 (tol = 0.002, component 1)
#this is a group by time interaction
#3 predictors: 1) Condition(Group), 2) Time, 3) time by condition (group x time)
# "1 + pre_post | PID" estimate a random intercept and a random slope for each individual
#summary(EQ_MM_SocialConnect_model_out)
sjPlot::tab_model(EQ_MM_SocialConnect_model_out)
|
|
EMA social comp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
13.68
|
12.90 – 14.47
|
<0.001
|
|
pre_post [End]
|
-0.73
|
-1.33 – -0.12
|
0.019
|
|
Condition
|
-0.67
|
-1.77 – 0.43
|
0.230
|
pre_post [End] * Condition
|
-0.45
|
-1.31 – 0.41
|
0.305
|
|
Random Effects
|
|
σ2
|
9.74
|
|
τ00 PID
|
7.06
|
|
τ11 PID.pre_postEnd
|
1.92
|
|
ρ01 PID
|
0.29
|
|
ICC
|
0.48
|
|
N PID
|
111
|
|
Observations
|
1328
|
|
Marginal R2 / Conditional R2
|
0.022 / 0.494
|
#This model does not yet account for person-level predictors
library(sjPlot)
plot_model(model = EQ_MM_SocialConnect_model_out, type = "int")

Creating separate dataframes for 1-week and 14-week follow-up (outliers removed)
socialconnect_scale_out_1wkpost <- socialconnect_scale_out %>%
filter(pre_post == 'Base')
socialconnect_scale_out_14wkpost <- socialconnect_scale_out %>%
filter(pre_post == 'End')
Regression for Social Connection Composite (1-WEEK POST / outliers removed) (Note: unclear whether this is a meaningful composite score)
EQ_MM_Social_model_1wk <- lm (EMA_social_comp ~ Condition, data = socialconnect_scale_out_1wkpost)
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model_1wk)
|
|
EMA social comp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
13.65
|
13.21 – 14.10
|
<0.001
|
|
Condition
|
-0.75
|
-1.37 – -0.13
|
0.018
|
|
Observations
|
668
|
|
R2 / R2 adjusted
|
0.008 / 0.007
|
Regression for Social Connection Composite (14-WEEK POST / outliers removed) (Note: unclear whether this is a meaningful composite score)
EQ_MM_Social_model_14wk <- lm (EMA_social_comp ~ Condition, data = socialconnect_scale_out_14wkpost)
library(sjPlot)
sjPlot::tab_model(EQ_MM_Social_model_14wk)
|
|
EMA social comp
|
|
Predictors
|
Estimates
|
CI
|
p
|
|
(Intercept)
|
13.06
|
12.57 – 13.54
|
<0.001
|
|
Condition
|
-1.35
|
-2.04 – -0.67
|
<0.001
|
|
Observations
|
660
|
|
R2 / R2 adjusted
|
0.022 / 0.021
|
SOCIAL CONNECTION SCALE