Last updated: 2020-05-27

Checks: 7 0

Knit directory: mcfa-para-est/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). 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 results in this page were generated with repository version eecb366. 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:    fig/
    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:  analysis/ml-cfa-parameter-convergence-correlation-pubfigure.Rmd
    Untracked:  analysis/ml-cfa-parameter-convergence-trace-plots-factor-loadings.Rmd

Unstaged changes:
    Modified:   analysis/ml-cfa-parameter-convergence-correlation-factor-loadings.Rmd
    Modified:   code/load_packages.R

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.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/ml-cfa-ci-coverage.Rmd) and HTML (docs/ml-cfa-ci-coverage.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd eecb366 noah-padgett 2020-05-06 updated para recovery
html eecb366 noah-padgett 2020-05-06 updated para recovery

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

theme_set(theme_bw())
sessionInfo()
R version 4.0.0 (2020-04-24)
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      cowplot_1.0.0        
 [4] MplusAutomation_0.7-3 data.table_1.12.8     patchwork_1.0.0      
 [7] forcats_0.5.0         stringr_1.4.0         dplyr_0.8.5          
[10] purrr_0.3.4           readr_1.3.1           tidyr_1.1.0          
[13] tibble_3.0.1          ggplot2_3.3.0         tidyverse_1.3.0      
[16] workflowr_1.6.2      

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6      lubridate_1.7.8   lattice_0.20-41   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.4      rlang_0.4.6      
[17] readxl_1.3.1      rstudioapi_0.11   whisker_0.4       texreg_1.36.23   
[21] gsubfn_0.7        rmarkdown_2.1     proto_1.0.0       webshot_0.5.2    
[25] pander_0.6.3      munsell_0.5.0     broom_0.5.6       compiler_4.0.0   
[29] httpuv_1.5.2      modelr_0.1.8      xfun_0.14         pkgconfig_2.0.3  
[33] htmltools_0.4.0   tidyselect_1.1.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_4.0.0        nlme_3.1-147      jsonlite_1.6.1    gtable_0.3.0     
[45] lifecycle_0.2.0   DBI_1.1.0         git2r_0.27.1      magrittr_1.5     
[49] scales_1.1.1      cli_2.0.2         stringi_1.4.6     fs_1.4.1         
[53] promises_1.1.0    xml2_1.3.2        ellipsis_0.3.1    generics_0.0.2   
[57] vctrs_0.3.0       boot_1.3-24       tools_4.0.0       glue_1.4.1       
[61] hms_0.5.3         parallel_4.0.0    yaml_2.2.1        colorspace_1.4-1 
[65] rvest_0.3.5       knitr_1.28        haven_2.3.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)

Plots

cols <- c("Upper Limit"="#56B4E9", "Estimate"="#CC79A7","Lower Limit"="#E69F00")

p <- ggplot(sim_results1)+
  geom_boxplot(aes(y=ul,x=parameter, 
                   group=parameter,
                   color="Upper Limit", fill="Upper Limit"),
               outlier.shape = NA, coef = 0, alpha=0.5)+
  geom_boxplot(aes(y=theta,x=parameter, 
                   group=parameter,
                   color="Estimate",fill="Estimate"),
               outlier.shape = NA, coef = 0, alpha=0.5)+
  geom_boxplot(aes(y=ll,x=parameter,
                   group=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")+
  facet_grid(icc_ov + icc_lv ~.) +
  scale_color_manual(name=" ", values=cols)+
  scale_fill_manual(name=" ", values=cols)+
  lims(y=c(-0.25, 2))+
  labs(y="Parameter Estimate",
       title="Interquartile range plots for Estimates and CI Limits",
       subtitle="Conditional on ICCs (latent and observed)")+
  theme(axis.text.x = element_text(size=7, angle=60,hjust=1),
        axis.title.x = element_blank(),
        legend.position = "bottom")
p
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 4.0.0 (2020-04-24)
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      cowplot_1.0.0        
 [4] MplusAutomation_0.7-3 data.table_1.12.8     patchwork_1.0.0      
 [7] forcats_0.5.0         stringr_1.4.0         dplyr_0.8.5          
[10] purrr_0.3.4           readr_1.3.1           tidyr_1.1.0          
[13] tibble_3.0.1          ggplot2_3.3.0         tidyverse_1.3.0      
[16] workflowr_1.6.2      

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