#SEM Approach #install and activate packages install.packages("metafor") install.packages("meta") install.packages("metaSEM") library(metafor) library(meta) library(metaSEM) #Two studies investigated the effect of precise diet goals vs round diet goals on weight loss. Both goal groups were compared to a control group, who did not set a goal. #Calculate effect sizes and covariances for Study 1 (control group vs precise group vs round group vs both goals groups on weight loss) m <- c(0.06,0.57,0.93,0.78) #the last number is both goal groups togehter v <- c(1.14,1.41,1.57,1.51) n <- c(41,32,48,80) smdMTS(m, v, n, homogeneity=c("variance"), bias.adjust=TRUE, all.comparisons=TRUE, list.output=TRUE, lavaan.output=FALSE) #Calculate effect sizes and covariances for Study 2 (control group vs round group vs precise group vs both goal groups on weight loss) m <- c(0.30,0.71,0.41,0.55) v <- c(1.33,1.96,1.64,1.80) n <- c(47,49,54,103) smdMTS(m, v, n, homogeneity=c("variance"), bias.adjust=TRUE, all.comparisons=TRUE, list.output=TRUE, lavaan.output=FALSE) #Create data frame in order to use meta function Study <-c(1,2) contrast1_control_vs_round <-c(0.422,0.311) # I put here "y", the effect size of the output of the smdMTS function contrast2_control_vs_precise <-c(0.720,0.083) contrast3_round_vs_precise <-c(0.298,-0.228) contrast4_control_vs_goal_groups <- c(0.598,0.190) var_contrast1 <-c(0.056,0.0414) # I put here the number from the covariance matrix (y2_1 & y2_1). Is this correct? It should be the variance of the contrast, right? cov_contrast1_contrast2 <-c(0.025,0.030) var_contrast2 <-c(0.047,0.039) cov_contrast2_contrast3 <- c(0.021,0.018) var_contrast3 <- c(0.051,0.039) cov_contrast1_contrast3 <-c(-0.030,-0.020) #Which covariance do I have to use when I have three groups and I compare all groups with each other? #The precise group is also used in contrast 2 and the round group also in contrast 1, so I would have to use two covariances? var_contrast4 <- c(0.037,0.037) cov_contrast1_contrast4 <-c (0.025,-0.021) dietGoals<- data.frame (Study,contrast1_control_vs_round,contrast2_control_vs_precise,contrast3_round_vs_precise, contrast4_control_vs_goal_groups,var_contrast1,cov_contrast1_contrast2,var_contrast2,cov_contrast2_contrast3, var_contrast3,cov_contrast1_contrast3,var_contrast4,cov_contrast1_contrast4) #In which order I have to put these variables in here? View(dietGoals) #Multivariate meta-analysis, fixed-effects meta(y = cbind(contrast1_control_vs_round,contrast2_control_vs_precise,contrast3_round_vs_precise,contrast4_control_vs_goal_groups), v = cbind(var_contrast1,cov_contrast1_contrast2,var_contrast2, cov_contrast2_contrast3,var_contrast3,cov_contrast1_contrast3,var_contrast4,cov_contrast1_contrast4), data = dietGoals,RE.constraints=0)