Last updated: 2020-05-06

Checks: 6 1

Knit directory: mcfa-para-est/

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


The R Markdown is untracked by Git. To know which version of the R Markdown file created these results, you’ll want to first commit it to the Git repo. If you’re still working on the analysis, you can ignore this warning. When you’re finished, you can run wflow_publish to commit the R Markdown file and build the HTML.

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 results in this page were generated with repository version 95dd5a6. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

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:    references/
    Ignored:    sera-presentation/

Untracked files:
    Untracked:  LICENSE.txt
    Untracked:  analysis/ml-cfa-ci-coverage.Rmd
    Untracked:  analysis/ml-cfa-parameter-bias-level2-residual-variances.Rmd
    Untracked:  analysis/ml-cfa-parameter-convergence-correlation-L1-factor-covariance.Rmd
    Untracked:  analysis/ml-cfa-parameter-convergence-correlation-L2-factor-covariance.Rmd
    Untracked:  analysis/ml-cfa-parameter-convergence-correlation-L2-factor-variances.Rmd
    Untracked:  analysis/ml-cfa-parameter-convergence-correlation-L2-residual-variances.Rmd
    Untracked:  analysis/ml-cfa-parameter-convergence-correlation-factor-loadings.Rmd

Unstaged changes:
    Modified:   .gitignore
    Modified:   analysis/index.Rmd
    Modified:   analysis/license.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.


rm(list=ls())
source(paste0(getwd(),"/code/load_packages.R"))
source(paste0(getwd(),"/code/get_data.R"))

theme_set(theme_bw())
sessionInfo()
R version 3.6.3 (2020-02-29)
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     

other attached packages:
 [1] xtable_1.8-4          kableExtra_1.1.0      MplusAutomation_0.7-3
 [4] data.table_1.12.8     patchwork_1.0.0       forcats_0.5.0        
 [7] stringr_1.4.0         dplyr_0.8.5           purrr_0.3.4          
[10] readr_1.3.1           tidyr_1.0.2           tibble_3.0.1         
[13] ggplot2_3.3.0         tidyverse_1.3.0       workflowr_1.6.1      

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6      lubridate_1.7.8   lattice_0.20-38   assertthat_0.2.1 
 [5] rprojroot_1.3-2   digest_0.6.25     R6_2.4.1          cellranger_1.1.0 
 [9] plyr_1.8.6        backports_1.1.6   reprex_0.3.0      evaluate_0.14    
[13] coda_0.19-3       httr_1.4.1        pillar_1.4.3      rlang_0.4.5      
[17] readxl_1.3.1      rstudioapi_0.11   texreg_1.36.23    gsubfn_0.7       
[21] rmarkdown_2.1     proto_1.0.0       webshot_0.5.2     pander_0.6.3     
[25] munsell_0.5.0     broom_0.5.6       compiler_3.6.3    httpuv_1.5.2     
[29] modelr_0.1.7      xfun_0.13         pkgconfig_2.0.3   htmltools_0.4.0  
[33] tidyselect_1.0.0  viridisLite_0.3.0 fansi_0.4.1       crayon_1.3.4     
[37] dbplyr_1.4.3      withr_2.2.0       later_1.0.0       grid_3.6.3       
[41] nlme_3.1-144      jsonlite_1.6.1    gtable_0.3.0      lifecycle_0.2.0  
[45] DBI_1.1.0         git2r_0.26.1      magrittr_1.5      scales_1.1.0     
[49] cli_2.0.2         stringi_1.4.6     fs_1.4.1          promises_1.1.0   
[53] xml2_1.3.2        ellipsis_0.3.0    generics_0.0.2    vctrs_0.2.4      
[57] boot_1.3-24       tools_3.6.3       glue_1.4.0        hms_0.5.3        
[61] parallel_3.6.3    yaml_2.2.1        colorspace_1.4-1  rvest_0.3.5      
[65] knitr_1.28        haven_2.2.0      
# take out unconverged/inadmissible cases
sim_results <- filter(sim_results, Converge==1, Admissible==1)

ids <- c("Condition", "Replication", "Estimator", "ss_l1", "ss_l2", "icc_ov", "icc_lv")
# set up vectors of variable names
pvec <- c(paste0('lambda1',1:6), paste0('lambda2',6:10), 'psiW12','psiB1', 'psiB2', 'psiB12', paste0('thetaB',1:10))
# now get standard errors
sevec <- c(paste0('selambda1',1:6), paste0('selambda2',6:10), 'sepsiW12','sepsiB1', 'sepsiB2', 'sepsiB12', paste0('sethetaB',1:10))
# stored "true" values of parameters by each condition
ptvec <- c(paste0('lambdaT1',1:6), paste0('lambdaT2',6:10), 'psiW12T', 'psiB1T', 'psiB2T', 'psiB12T', paste0("thetaBT", 1:10))

# need to reshape into "long" format and compute CIs

sim_results0 <- sim_results[,c(ids, pvec)] %>%
  pivot_longer(
    cols =all_of(pvec),
    names_to= "parameter",
    values_to = c("theta"))
sim_results1 <- sim_results[,c(ids, sevec)] %>%
  pivot_longer(
    cols =all_of(sevec),
    names_to= "parameterSE",
    values_to = c("se"))
# add new columns for lambda truth
# paste0('lambda1',1:6), paste0('lambda2',6:10)
sim_results2 <- sim_results %>%
  mutate(lambdaT11=lambdaT, lambdaT26=lambdaT,
         lambdaT12=lambdaT, lambdaT27=lambdaT,
         lambdaT13=lambdaT, lambdaT28=lambdaT,
         lambdaT14=lambdaT, lambdaT29=lambdaT,
         lambdaT15=lambdaT, lambdaT210=lambdaT,
         lambdaT16=lambdaT,
         thetaBT1=thetaBT, thetaBT6=thetaBT,
         thetaBT2=thetaBT, thetaBT7=thetaBT,
         thetaBT3=thetaBT, thetaBT8=thetaBT,
         thetaBT4=thetaBT, thetaBT9=thetaBT,
         thetaBT5=thetaBT, thetaBT10=thetaBT)
sim_results2 <- sim_results2[,c(ids, ptvec)] %>%
  pivot_longer(
    cols =all_of(ptvec),
    names_to= "paraTruth",
    values_to = c("truth"))

sim_results0$se <- sim_results1$se
sim_results0$truth <- sim_results2$truth

zcrit <- 1.96
theta <- sim_results0$theta
se <- sim_results0$se
truth <- sim_results0$truth
ll <- theta - zcrit*se
ul <- theta + zcrit*se
contain <- data.table::fifelse(truth > ll & truth < ul, 1, 0)
sim_results0$ll <- ll
sim_results0$ul <- ul
sim_results0$contain <- contain


# recode parameter names
sim_results0$parameter <- recode(
  sim_results0$parameter,
  `lambda11`="lambda[1,1]", `lambda26`="lambda[2,6]",
  `lambda12`="lambda[1,2]", `lambda27`="lambda[2,7]",
  `lambda13`="lambda[1,3]", `lambda28`="lambda[2,8]",
  `lambda14`="lambda[1,4]", `lambda29`="lambda[2,9]",
  `lambda15`="lambda[1,5]", `lambda210`="lambda[2,10]",
  `lambda16`="lambda[1,6]",
  `thetaB1`="thetaB[1,1]", `thetaB6`="thetaB[6,6]",
  `thetaB2`="thetaB[2,2]", `thetaB7`="thetaB[7,7]",
  `thetaB3`="thetaB[3,3]", `thetaB8`="thetaB[8,8]",
  `thetaB4`="thetaB[4,4]", `thetaB9`="thetaB[9,9]",
  `thetaB5`="thetaB[5,5]", `thetaB10`="thetaB[10,10]",
  `psiW12`="psiW[1,2]",`psiB12`="psiB[1,2]",
  `psiB1`="psiB[1,1]", `psiB2`="psiB[2,2]"
  )

level_ord <- c("lambda[1,1]", "lambda[1,2]", "lambda[1,3]",   "lambda[1,4]", "lambda[1,5]", "lambda[1,6]", "lambda[2,6]", "lambda[2,7]", "lambda[2,8]", "lambda[2,9]", "lambda[2,10]", "psiW[1,2]", "psiB[1,2]", "psiB[1,1]", "psiB[2,2]",  "thetaB[1,1]", "thetaB[2,2]", "thetaB[3,3]", "thetaB[4,4]", "thetaB[5,5]", "thetaB[6,6]", "thetaB[7,7]", "thetaB[8,8]", "thetaB[9,9]", "thetaB[10,10]")
sim_results0$parameter <- factor(
  sim_results0$parameter,
  levels=level_ord,
  ordered=T)
sim_results0$parameterRev <- factor(
  sim_results0$parameter,
  levels=rev(level_ord),
  ordered=T)

# ggplot(sim_results0, aes(y=theta,x=parameter, group=parameter))+
#   geom_boxplot()+
#   theme(axis.text.x = element_text(size=7, angle=60,hjust=1))
# 
# 
# ggplot(sim_results0, aes(y=theta,x=parameter, group=parameter))+
#   geom_boxplot()+
#   lims(y=c(-1,2))+
#   theme(axis.text.x = element_text(size=7, angle=60,hjust=1))

# so clearly we need to remove some replications with impossible values...

sim_results0 <- sim_results0 %>%
  group_by(Condition, parameter) %>%
  mutate(
    ni = n(),
    q0.001 = quantile(theta, 0.001),
    q0.01 = quantile(theta, 0.01),
    q0.025 = quantile(theta, 0.025),
    q0.975 = quantile(theta, 0.975),
    q0.99 = quantile(theta, 0.99),
    q0.999 = quantile(theta, 0.999),
    flag0.975 = ifelse(theta >= q0.975 | theta <= q0.025, 1, 0),
    flag0.99 = ifelse(theta >= q0.99 | theta <= q0.01, 1, 0),
    flag0.999 = ifelse(theta >= q0.999 | theta <= q0.001, 1, 0)
  ) 

sim_results1 <- filter(sim_results0, flag0.99 != 1)


cols <- c("Upper Limit"="#56B4E9", "Estimate"="#CC79A7","Lower Limit"="#E69F00")
ggplot(sim_results1)+
  geom_boxplot(aes(y=ul,x=parameter, 
                   group=interaction(icc_ov, icc_lv, parameter),
                   color="Upper Limit", fill="Upper Limit"),
               outlier.shape = NA, coef = 0, alpha=0.5)+
  geom_boxplot(aes(y=theta,x=parameter, 
                   group=interaction(icc_ov, icc_lv, parameter),
                   color="Estimate",fill="Estimate"),
               outlier.shape = NA, coef = 0, alpha=0.5)+
  geom_boxplot(aes(y=ll,x=parameter,
                   group=interaction(icc_ov, icc_lv, parameter),
                   color="Lower Limit", fill="Lower Limit"),
               outlier.shape = NA, coef = 0, alpha=0.5)+
  geom_point(aes(y=truth,x=parameter, group= parameter),
             color="red")+
  scale_color_manual(name=" ", values=cols)+
  scale_fill_manual(name=" ", values=cols)+
  lims(y=c(-0.25, 2))+
  labs(y="Parameter Estimate")+
  theme(axis.text.x = element_text(size=7, angle=60,hjust=1),
        axis.title.x = element_blank(),
        legend.position = "bottom")
Warning: Removed 40712 rows containing non-finite values (stat_boxplot).
Warning: Removed 2199 rows containing non-finite values (stat_boxplot).
Warning: Removed 27121 rows containing non-finite values (stat_boxplot).


sessionInfo()
R version 3.6.3 (2020-02-29)
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     

other attached packages:
 [1] xtable_1.8-4          kableExtra_1.1.0      MplusAutomation_0.7-3
 [4] data.table_1.12.8     patchwork_1.0.0       forcats_0.5.0        
 [7] stringr_1.4.0         dplyr_0.8.5           purrr_0.3.4          
[10] readr_1.3.1           tidyr_1.0.2           tibble_3.0.1         
[13] ggplot2_3.3.0         tidyverse_1.3.0       workflowr_1.6.1      

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6      lubridate_1.7.8   lattice_0.20-38   assertthat_0.2.1 
 [5] rprojroot_1.3-2   digest_0.6.25     R6_2.4.1          cellranger_1.1.0 
 [9] plyr_1.8.6        backports_1.1.6   reprex_0.3.0      evaluate_0.14    
[13] coda_0.19-3       httr_1.4.1        pillar_1.4.3      rlang_0.4.5      
[17] readxl_1.3.1      rstudioapi_0.11   texreg_1.36.23    gsubfn_0.7       
[21] rmarkdown_2.1     labeling_0.3      proto_1.0.0       webshot_0.5.2    
[25] pander_0.6.3      munsell_0.5.0     broom_0.5.6       compiler_3.6.3   
[29] httpuv_1.5.2      modelr_0.1.7      xfun_0.13         pkgconfig_2.0.3  
[33] htmltools_0.4.0   tidyselect_1.0.0  viridisLite_0.3.0 fansi_0.4.1      
[37] crayon_1.3.4      dbplyr_1.4.3      withr_2.2.0       later_1.0.0      
[41] grid_3.6.3        nlme_3.1-144      jsonlite_1.6.1    gtable_0.3.0     
[45] lifecycle_0.2.0   DBI_1.1.0         git2r_0.26.1      magrittr_1.5     
[49] scales_1.1.0      cli_2.0.2         stringi_1.4.6     farver_2.0.3     
[53] fs_1.4.1          promises_1.1.0    xml2_1.3.2        ellipsis_0.3.0   
[57] generics_0.0.2    vctrs_0.2.4       boot_1.3-24       tools_3.6.3      
[61] glue_1.4.0        hms_0.5.3         parallel_3.6.3    yaml_2.2.1       
[65] colorspace_1.4-1  rvest_0.3.5       knitr_1.28        haven_2.2.0