Last updated: 2020-03-31

Checks: 7 0

Knit directory: mcfa-para-est/

This reproducible R Markdown analysis was created with workflowr (version 1.5.0). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20190614) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility. The version displayed above was the version of the Git repository at the time these results were generated.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/compiled_para_results.txt
    Ignored:    data/results_bias_est.csv
    Ignored:    manuscript/
    Ignored:    output/fact-cov-converge-largeN.pdf
    Ignored:    output/fact-cov-converge-medN.pdf
    Ignored:    output/fact-cov-converge-smallN.pdf
    Ignored:    output/loading-converge-largeN.pdf
    Ignored:    output/loading-converge-medN.pdf
    Ignored:    output/loading-converge-smallN.pdf
    Ignored:    sera-presentation/

Untracked files:
    Untracked:  analysis/ml-cfa-parameter-bias-factor-loadings.Rmd
    Untracked:  analysis/ml-cfa-parameter-bias-level1-factor-covariances.Rmd
    Untracked:  analysis/ml-cfa-parameter-bias-level2-factor-covariances.Rmd
    Untracked:  analysis/ml-cfa-parameter-bias-level2-factor-variances.Rmd
    Untracked:  analysis/ml-cfa-parameter-bias-overview.Rmd

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


There are no past versions. Publish this analysis with wflow_publish() to start tracking its development.


The following two chunks of code are what were used to take the Mplus outcome and turn it into something we could analyze. This page contains the code two these two separate R scripts.

Script 1: comine_files_para.R

# ============================================= #
#      ML-CFA Parameter Recovery Project  
#             Padgett & Morgan               
# ============================================= #
# Data Created: 2019-06-14
# Date Modified: 2019-06-14
# By: R. Noah Padgett                   
# ============================================= #
# ============================================= #
# Purpose:
# This R script is for extracting the parameter
#   estimates and the summary information from 
#   all 15 results files
#   to create one parsed down data file with
#   with the fit information and identification
#   information.
#
# The output will be a single file that I 
#   will use for all data analyses.
# ============================================= #
library(dplyr)

## Variables to extract from simulation
var.names <- c(
    'Condition', 'Replication',
    'Model', 'Estimator', 'Converge', 'Admissible', 'chisqu_value', 'chisqu_df', 
    'chisqu_pvalue', 'CFI', 'TLI', 'RMSEA', 'SRMRW', 'SRMRB',
    "lambda11", "lambda12", "lambda13", "lambda14", "lambda15", "lambda16", 
    "lambda26", "lambda27", "lambda28", "lambda29", "lambda210", 
    "thetaW1", "thetaW2", "thetaW3", "thetaW4", "thetaW5", 
    "thetaW6", "thetaW7", "thetaW8", "thetaW9", "thetaW10", 
    "psiW12", 
    "nu1", "nu2", "nu3", "nu4", "nu5", "nu6", "nu7", "nu8", "nu9", "nu10", 
    "thetaB1", "thetaB2", "thetaB3", "thetaB4", 
    "thetaB5", "thetaB6", "thetaB7", "thetaB8", "thetaB9", "thetaB10", 
    "psiB1", "psiB12", "psiB2", 
    "tau11", "tau12", "tau13", "tau14", "tau21", "tau22", "tau23", "tau24", 
    "tau31", "tau32", "tau33", "tau34", "tau41", "tau42", "tau43", "tau44", 
    "tau51", "tau52", "tau53", "tau54", "tau61", "tau62", "tau63", "tau64", 
    "tau71", "tau72", "tau73", "tau74", "tau81", "tau82", "tau83", "tau84", 
    "tau91", "tau92", "tau93", "tau94", "tau101", "tau102", "tau103", "tau104",
    
    "selambda11", "selambda12", "selambda13", "selambda14", 
    "selambda15", "selambda16", "selambda26", "selambda27", "selambda28", 
    "selambda29", "selambda210", "sethetaW1", "sethetaW2", "sethetaW3", 
    "sethetaW4", "sethetaW5", "sethetaW6", "sethetaW7", "sethetaW8", "sethetaW9", 
    "sethetaW10", "sepsiW12", "senu1", "senu2", "senu3", "senu4", "senu5", 
    "senu6", "senu7", "senu8", "senu9", "senu10", "sethetaB1", "sethetaB2", 
    "sethetaB3", "sethetaB4", "sethetaB5", "sethetaB6", "sethetaB7", "sethetaB8", 
    "sethetaB9", "sethetaB10", "sepsiB1", "sepsiB12", "sepsiB2",
    "setau11", "setau12", "setau13", "setau14", "setau21", "setau22", "setau23", 
    "setau24", "setau31", "setau32", "setau33", "setau34", "setau41", "setau42", 
    "setau43", "setau44", "setau51", "setau52", "setau53", "setau54", "setau61", 
    "setau62", "setau63", "setau64", "setau71", "setau72", "setau73", "setau74", 
    "setau81", "setau82", "setau83", "setau84", "setau91", "setau92", "setau93", 
    "setau94", "setau101", "setau102", "setau103", "setau104")
    
## initialize dataframe (helps with speed i think)
mydata <- as.data.frame(matrix(NA, ncol=length(var.names)))
colnames(mydata) <- var.names
#mydata$Model <- as.factor(mydata$Model)
#mydata$Estimator <- as.factor(mydata$Estimator)
## Set up iterations
EST <- c('MLR', 'ULSMV', 'WLSMV')
MOD <- c('C')
CON <- c('1t18', '19t36', '37t54', '55t71', '72')

## Run loop to extract and combine data into one file
for(est in EST){
  for(m in MOD){
    for(c in CON){
      ## Read in specified data file
      dat <- read.table(
        paste0('Results/output_results_',est,'_',m,'_Con',c,'.txt'),
        header = T, sep = "\t", fill= T
      )
      ## ~~ 
      ## subset to the variables of interest 
      dat <- dat[, colnames(dat) %in% var.names]
      ## merge data into one dataset 
      mydata <- merge(mydata, dat, all=T)
      cat('.')
    } ## End conditions
  } ## End Model specification
} ## End Estimator
mydata <- mydata[-108001, ]
mydata <- mydata[, var.names]

## Write out Results text file
write.table( x = mydata,
             file = paste0('Results/compiled_parameter_results.txt'),
             sep = '\t',row.names = F
) ## End write data.table

Script 2: get_data.R

# ============================================= #
# script: get_data.R
# Project: ML-CFA Parameter Recovery
# Author(s): R.N. Padgett & G.B. Morgan           
# ============================================= #
# Data Created: 2019-10-16
# Date Modified: 2019-10-16
# By: R. Noah Padgett                   
# ============================================= #
# Stems from Padgett's MA thesis                   
# ============================================= #
# Purpose:
# This R script is for loading and formating 
#   the data file for use in analyses.
#
# The output is a data.frame (tibble) object
# ============================================= #


sim_results <- as_tibble(read.table('data/compiled_para_results.txt', header=T,sep='\t'))

## Next, turn condition into a factor for plotting
sim_results$Condition <- as.factor(sim_results$Condition)

## level-1 Sample size
ss_l1 <- c(5, 10, 30) ## 6 conditions each
ss_l2 <- c(30, 50, 100, 200) ## 18 condition each
icc_ov <- c(.1, .3, .5) ## 2 conditions each
icc_lv <- c(.1, .5) ## every other condition
nCon <- 72 # number of conditions
nRep <- 500 # number of replications per condition
nMod <- 3 ## numberof estimated models per conditions
## Total number of rows: 108,000
ss_l2 <- c(rep(ss_l2[1], 18*nRep*nMod), rep(ss_l2[2], 18*nRep*nMod), 
           rep(ss_l2[3], 18*nRep*nMod), rep(ss_l2[4], 18*nRep*nMod))
ss_l1 <- rep(c(rep(ss_l1[1],6*nRep*nMod), rep(ss_l1[2],6*nRep*nMod), rep(ss_l1[3],6*nRep*nMod)), 4)
icc_ov <- rep(c(rep(icc_ov[1], 2*nRep*nMod), rep(icc_ov[2], 2*nRep*nMod), rep(icc_ov[3], 2*nRep*nMod)), 12)
icc_lv <- rep(c(rep(icc_lv[1], nRep*nMod), rep(icc_lv[2], nRep*nMod)), 36)
## Force these vectors to be column vectors
ss_l1 <- matrix(ss_l1, ncol=1)
ss_l2 <- matrix(ss_l2, ncol=1)
icc_ov <- matrix(icc_ov, ncol=1)
icc_lv <- matrix(icc_lv, ncol=1)
## Add the labels to the results data frame
sim_results <- sim_results[order(sim_results$Condition),]
sim_results <- cbind(sim_results, ss_l1, ss_l2, icc_ov, icc_lv)

## Set up iterators for remainder of script
ests <- c('MLR', 'ULSMV', 'WLSMV')

# Add in true parameter values
## Loadings (0.6) forall conditions
sim_results$lambdaT <- 0.6
## level-1 factor covariance
sim_results$psiW12T <- 0.3
## level-2 factor (co)variance
lv_var <- c(.111, 1)
sim_results$psiB1T <- rep(c(rep(lv_var[1], nRep*nMod), rep(lv_var[2], nRep*nMod)), 36)
sim_results$psiB2T <- rep(c(rep(lv_var[1], nRep*nMod), rep(lv_var[2], nRep*nMod)), 36)
lv_cov <- c(.0333, .3)
sim_results$psiB12T <- rep(c(rep(lv_cov[1], nRep*nMod), rep(lv_cov[2], nRep*nMod)), 36)
## level-2 observed variable residual variance 
ob_var <- c(.111, .43, 1 )
sim_results$thetaBT <- rep(c(rep(ob_var[1], 2*nRep*nMod), rep(ob_var[2], 2*nRep*nMod), rep(ob_var[3], 2*nRep*nMod)), 12)

# Compute ICC estimates
# latent variables
sim_results$icc_lv1_est <- sim_results$psiB1/(sim_results$psiB1+1)
sim_results$icc_lv2_est <- sim_results$psiB2/(sim_results$psiB2+1)
#observed variables
i <- 1
for(i in 1:10){
  varb <- paste0('thetaB',i)
  varw <- paste0('thetaW',i)
  
  icc_est <- ifelse(sim_results$Estimator=="MLR", 
                    sim_results[, varb]/( sim_results[, varb] + sim_results[, varw]),
                    sim_results[, varb]/( sim_results[, varb] + 1))
  
  sim_results$icc_est <- icc_est
  colnames(sim_results)[ncol(sim_results)] <- paste0('icc_ov', i,'_est')
}

sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] workflowr_1.5.0 Rcpp_1.0.3      rprojroot_1.3-2 digest_0.6.23  
 [5] later_1.0.0     R6_2.4.1        backports_1.1.5 git2r_0.26.1   
 [9] magrittr_1.5    evaluate_0.14   stringi_1.4.3   rlang_0.4.2    
[13] fs_1.3.1        promises_1.1.0  rmarkdown_1.18  tools_3.6.1    
[17] stringr_1.4.0   glue_1.3.1      httpuv_1.5.2    xfun_0.11      
[21] yaml_2.2.0      compiler_3.6.1  htmltools_0.4.0 knitr_1.26