library(readxl)
library(tidyr)
library(tidyverse)microgoal 1st round data
Let’s read in the data first
Hey folks I started writing this at the airport……so sorry for the delay I will see how much I can do,
I will assign some to-dos at the end of the document for Bingcheng to follow it up (sorry Bingcheng and thank you Bingcheng! Will bring food for you from China :D)
df <- read_xlsx('/Users/haochensong/Desktop/micro-goal data/Cleaned_Data.xlsx', skip = 2)db <- df %>% select(
`Expectation Arm`,
`Activity Arm`,
`Benefit and Barrier Arm`,
`Example Arm`,
`Bigger Goal Arm`,
Pre_Commitment,
Post_Commitment
)
db$id <- 1:nrow(db)Model Building, let’s see
turn into long format first:
db_long <- db %>%
gather(key = "Time", value = "Commitment", Pre_Commitment, Post_Commitment) %>%
mutate(Time = factor(ifelse(Time == "Pre_Commitment", "Pre", "Post")))looks good, let’s fit the mixed effect model:
library(lme4)
model <- lmer(Commitment ~ Time * (`Expectation Arm` + `Activity Arm` + `Benefit and Barrier Arm` + `Example Arm` + `Bigger Goal Arm`) + (1 | id), data = db_long)summary(model)Linear mixed model fit by REML ['lmerMod']
Formula:
Commitment ~ Time * (`Expectation Arm` + `Activity Arm` + `Benefit and Barrier Arm` +
`Example Arm` + `Bigger Goal Arm`) + (1 | id)
Data: db_long
REML criterion at convergence: 1068.1
Scaled residuals:
Min 1Q Median 3Q Max
-1.88709 -0.52336 -0.01723 0.44097 2.83113
Random effects:
Groups Name Variance Std.Dev.
id (Intercept) 4.500 2.121
Residual 4.932 2.221
Number of obs: 220, groups: id, 110
Fixed effects:
Estimate Std. Error t value
(Intercept) 10.93677 0.78334 13.962
TimePre 0.72413 0.80108 0.904
`Expectation Arm`N 0.59992 0.59763 1.004
`Activity Arm`m 0.92340 0.72671 1.271
`Activity Arm`r 1.04736 0.72111 1.452
`Benefit and Barrier Arm`o -0.40193 0.60500 -0.664
`Example Arm`v 0.33022 0.60013 0.550
`Bigger Goal Arm`o 0.10406 0.59104 0.176
TimePre:`Expectation Arm`N 0.30415 0.61116 0.498
TimePre:`Activity Arm`m -0.73854 0.74317 -0.994
TimePre:`Activity Arm`r -0.09366 0.73745 -0.127
TimePre:`Benefit and Barrier Arm`o 0.41947 0.61871 0.678
TimePre:`Example Arm`v 0.73074 0.61372 1.191
TimePre:`Bigger Goal Arm`o 0.01531 0.60442 0.025
Correlation matrix not shown by default, as p = 14 > 12.
Use print(x, correlation=TRUE) or
vcov(x) if you need it
also anova table:
anova_table <- anova(model)
print(anova_table)Analysis of Variance Table
npar Sum Sq Mean Sq F value
Time 1 78.005 78.005 15.8172
`Expectation Arm` 1 8.110 8.110 1.6445
`Activity Arm` 2 14.592 7.296 1.4794
`Benefit and Barrier Arm` 1 0.212 0.212 0.0429
`Example Arm` 1 8.934 8.934 1.8116
`Bigger Goal Arm` 1 0.239 0.239 0.0484
Time:`Expectation Arm` 1 0.400 0.400 0.0812
Time:`Activity Arm` 2 8.667 4.334 0.8788
Time:`Benefit and Barrier Arm` 1 3.479 3.479 0.7055
Time:`Example Arm` 1 6.989 6.989 1.4171
Time:`Bigger Goal Arm` 1 0.003 0.003 0.0006
ToDo for Bingcheng:
it looks like Benefit and Barrier Arm definitely is good, so is the interaction between Time and Bigger Goal Arm
I don’t have the time now to write out the summary as my plane is boarding in 5 minutes…
can you try out other models, and consult Ilya for more interpretation?
we could decrease the number of interaction terms here?
we could use this info to better fit our power analysis?
this is quite good results, consult Ilya how we should report it?