Any help and papers welcome!
However, I want to know the effect size such a sample can identify given my model.
TBV.model <- 'TBV =~ NA*CorticalWhiteMatterVol_log + Brain_Stem_log + Left_VentralDC_log + Right_VentralDC_log + lhCortexVol_log + rhCortexVol_log+ Left_Accumbens_area_log + Right_Accumbens_area_log+ Left_Cerebellum_Cortex_log + Right_Cerebellum_Cortex_log + Left_Caudate_log + Right_Caudate_log + Left_Hippocampus_log + Right_Hippocampus_log+ Left_Pallidum_log + Right_Pallidum_log + Left_Putamen_log + Right_Putamen_log + Right_Thalamus_Proper_log + Left_Thalamus_Proper_log+ Left_Amygdala_log + Right_Amygdala_log
TBV ~~ 1*TBVTBV ~ c(0, 0.053)* 1lhCortexVol_log ~~ rhCortexVol_logLeft_Caudate_log ~~ Right_Caudate_logLeft_Putamen_log ~~ Right_Putamen_logLeft_Cerebellum_Cortex_log ~~ Right_Cerebellum_Cortex_logRight_Thalamus_Proper_log ~~ Left_Thalamus_Proper_logLeft_Accumbens_area_log ~~ Right_Accumbens_area_logLeft_VentralDC_log ~~ Right_VentralDC_logLeft_Amygdala_log ~~ Right_Amygdala_logLeft_Hippocampus_log ~~ Right_Hippocampus_logLeft_Pallidum_log ~~ Right_Pallidum_log
Right_Putamen_log ~~ Right_Amygdala_logRight_Caudate_log ~~ Right_Putamen_log
Left_Caudate_log~~Left_Thalamus_Proper_log'
loadingVal_Control <-as.matrix(parameterEstimates(Control_fit_TBV1, standardized=TRUE) %>% filter(op == "=~") %>% select(Beta=std.all))
loadingVal_ASD <-as.matrix(parameterEstimates(ASD_fit_TBV1, standardized=TRUE) %>% filter(op == "=~") %>% select(Beta=std.all))
LY_not_free = list(loadingVal_Control, loadingVal_ASD)
TYControl_all <-as.matrix(parameterEstimates(Configural_Model, standardized=TRUE) %>% select(Beta=std.all))TY1 <- TYControl_all[196:217,]
TYASD_all <-as.matrix(parameterEstimates(Configural_Model, standardized=TRUE) %>% select(Beta=std.all))TY2 <- TYASD_all[196:217,]
AL1 <-c(0)
AL2 <- c(0.053)AL_not_free= list(AL1, AL2)
Corr_ASD <- as.matrix(parameterEstimates(ASD_fit_TBV1, standardized=TRUE) %>% filter(op == "~~") %>% select(Beta=std.all))Corr_Control <- as.matrix(parameterEstimates(Control_fit_TBV1, standardized=TRUE) %>% filter(op == "~~") %>% select(Beta=std.all))
Var_Control_all <- as.matrix(parameterEstimates(Control_fit_TBV1, standardized=TRUE) %>% select(Beta=std.all))Var_Control <- Var_Control_all[173:194,]
Var_ASD_all <- as.matrix(parameterEstimates(ASD_fit_TBV1, standardized=TRUE) %>% select(Beta=std.all))Var_ASD <- Var_ASD_all[173:194,]
can't seem to understand how to do this with the simsem package or the lavaanList() option.
## write functions for simulation
makeData <- function(group2loading2 = 0.7, group2intercept1 = 3) {
pop.model <- paste0(' factor =~ c(0.7, 0.7)*x1 + c(0.7, ',
group2loading2, ')*x2 + c(0.8, 0.8)*x3
x1 ~ c(3, ', group2intercept1, ')*1
x2 ~ c(3, 3)*1
x3 ~ c(3, 3)*1 ')
simulateData(pop.model, standardized = TRUE, sample.nobs = c(100, 100))
}
testMetric <- function(data) {
mod.config <- ' f =~ x1 + x2 + x3 '
mod.metric <- ' f =~ c(L1, L1)*x1 + c(L2, L2)*x2 + c(L3, L3)*x3
f ~~ c(1, NA)*f
'
fit.config <- cfa(mod.config, data = data, std.lv = TRUE, group = "group")
fit.metric <- cfa(mod.metric, data = data, std.lv = TRUE, group = "group")
LRT <- lavTestLRT(fit.metric, fit.config)
LRT[2, "Pr(>Chisq)"] < .05 # reject H0 at alpha = .05?
}
testScalar <- function(data) {
mod.metric <- ' f =~ c(L1, L1)*x1 + c(L2, L2)*x2 + c(L3, L3)*x3
f ~~ c(1, NA)*f
'
mod.scalar <- ' f =~ c(L1, L1)*x1 + c(L2, L2)*x2 + c(L3, L3)*x3
f ~~ c(1, NA)*f
x1 ~ c(T1, T1)*1
x2 ~ c(T2, T2)*1
x3 ~ c(T3, T3)*1
f ~ c(0, NA)*1
'
fit.metric <- cfa(mod.metric, data = data, std.lv = TRUE, group = "group")
fit.scalar <- cfa(mod.scalar, data = data, std.lv = TRUE, group = "group")
LRT <- lavTestLRT(fit.scalar, fit.metric)
LRT[2, "Pr(>Chisq)"] < .05 # reject H0 at alpha = .05?
}
nReps <- 100
## power analysis for difference in loadings of 0.7 - 0.4 = 0.3
reject.load.4 <- rep(NA, nReps)
set.seed(12345)
for (i in 1:nReps) {
dat <- makeData(group2loading2 = 0.4)
reject.load.4[i] <- testMetric(dat)
}
mean(reject.load.4) # empirical power
## power analysis for difference in intercepts of 3 - 2 = 1
reject.int.2 <- rep(NA, nReps)
set.seed(12345)
for (i in 1:nReps) {
dat <- makeData(group2intercept1 = 2)
reject.int.2[i] <- testScalar(dat)
}
mean(reject.int.2) # empirical power