Last updated: 2020-11-04

Checks: 6 1

Knit directory: pools-projects/

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.


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(20201007) 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 76332d3. 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/

Untracked files:
    Untracked:  IRB/
    Untracked:  analysis/pilot-study-power-calculation.Rmd
    Untracked:  analysis/pools-definitions.Rmd
    Untracked:  analysis/power-calculation.Rmd
    Untracked:  code/load_packages.R
    Untracked:  code/r_functions.R
    Untracked:  item-review-1/
    Untracked:  papers/

Unstaged changes:
    Modified:   analysis/_site.yml
    Modified:   analysis/index.Rmd
    Modified:   pools-projects.Rproj

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.


POOLS Model

The POOLS model is generally a four factor model with 10-14 items per factor.

Power Analysis Simulation Study

Here, we vary the sample size between 100 and 1000 (steps of 50) to determine the approximate minimal sample size needed to reject that the data fails to fit the model.

Populaiton Model

pop_model <- "
  # POOLS Items (~40)
  EF =~ .6*p11 + .6*p12 + .6*p13 + .6*p14 + .6*p15 + .6*p16 + .6*p17 + .6*p18 + .6*p19 + .6*p110
  ST =~ .6*p21 + .6*p22 + .6*p23 + .6*p24 + .6*p25 + .6*p26 + .6*p27 + .6*p28 + .6*p29 + .6*p210
  IN =~ .6*p31 + .6*p32 + .6*p33 + .6*p34 + .6*p35 + .6*p36 + .6*p37 + .6*p38 + .6*p39 + .6*p310
  EN =~ .6*p41 + .6*p42 + .6*p43 + .6*p44 + .6*p45 + .6*p46 + .6*p47 + .6*p48 + .6*p49 + .6*p410
  
  # Self-Efficacy Items (12)
  #   omegas: .85, .82, .8
  se1 =~ .75*eff1 + .75*eff2 + .75*eff3 +.75*eff4
  se2 =~ .75*eff5 + .75*eff6 + .7*eff7 +.7*eff8
  se3 =~ .7*eff9 + .7*eff10 + .7*eff11 +.7*eff12
  
  # Teacher-Team Inno Scale (omega = .89)
  tt =~ .8*ttis1 + .8*ttis2 + .8*ttis3 + .8*ttis4 
  
  # NEO FFM
  # Alphas: .77, .81, .82, .86, .86
  A =~ .7*ffmA1 + .7*ffmA2 + .7*ffmA3 + .7*ffmA4 + .7*ffmA5 + .7*ffmA6 + .7*ffmA7 + .7*ffmA8 + .7*ffmA9 + .7*ffmA10
  C =~ .7*ffmC1 + .7*ffmC2 + .7*ffmC3 + .7*ffmC4 + .7*ffmC5 + .7*ffmC6 + .7*ffmC7 + .7*ffmC8 + .7*ffmC9 + .7*ffmC10
  O =~ .7*ffmO1 + .7*ffmO2 + .7*ffmO3 + .7*ffmO4 + .7*ffmO5 + .7*ffmO6 + .7*ffmO7 + .7*ffmO8 + .7*ffmO9 + .7*ffmO10
  E =~ .7*ffmE1 + .7*ffmE2 + .7*ffmE3 + .7*ffmE4 + .7*ffmE5 + .7*ffmE6 + .7*ffmE7 + .7*ffmE8 + .7*ffmE9 + .7*ffmE10
  N =~ .7*ffmN1 + .7*ffmN2 + .7*ffmN3 + .7*ffmN4 + .7*ffmN5 + .7*ffmN6 + .7*ffmN7 + .7*ffmN8 + .7*ffmN9 + .7*ffmN10
  
  # Latent Variable Covariance Matrix
  #   POOLS
  EF ~~ 1*EF + .3*ST + .2*In + .2*EN
  ST ~~ 1*ST + .1*IN + .3*EN
  IN ~~ 1*IN + .3*EN
  EN ~~ 1*EN
  #   SE
  se1 ~~ 1*se1 + .5*se2 + .4*se3
  se2 ~~ 1*se2 + .3*se3
  se3 ~~ 1*se3
  # FFM (taken from deyoung table 6)
  A ~~ 1*A + (0.38)*C + (0.11)*O + (0.15)*E + (-0.24)*N
  C ~~ 1*C + (0.11)*O + (0.18)*E + (-0.24)*N
  O ~~ 1*O + (0.26)*E + (-0.13)*N
  E ~~ 1*E + (-0.33)*N
  N ~~ 1*N
  
  # Research questions
  # 1. FFM accounting for variance of POOLS
  # (need to come up with better values)
  EF ~ .1*A + .3*C + .4*O + .1*E + (-0.2)*N
  ST ~ .1*A + .3*C + .4*O + .1*E + (-0.2)*N
  EN ~ .1*A + .3*C + .4*O + .1*E + (-0.2)*N
  IN ~ .1*A + .3*C + .4*O + .1*E + (-0.2)*N
  
  # 2. relationship between SE & Pools
  EF ~ .3*se1 + .2*se2 + .4*se3
  ST ~ .3*se1 + .2*se2 + .4*se3
  IN ~ .3*se1 + .2*se2 + .4*se3
  EN ~ .3*se1 + .2*se2 + .4*se3
  
  # 3. Team inno predicting POOLS
  EF ~ .2*tt
  ST ~ .2*tt
  IN ~ .2*tt
  EN ~ .2*tt
  
  # 4. demographics
  EF ~ 0.1*sex
  ST ~ 0.1*sex
  IN ~ 0.1*sex
  EN ~ 0.1*sex
  
  # categorical variables
  sex | 0.4*t1
  
"
dat <- simulateData(pop_model, model.type = "sem")
Warning in lav_partable_flat(FLAT, blocks = "group", meanstructure =
meanstructure, : lavaan WARNING: thresholds are defined for exogenous variables:
sex
#Impose missing
datmiss <- imposeMissing(
  dat,
  nforms = 7,
  itemGroups = list(c(1:107),
                    c(),
                    c(41:56),
                    c(                     77:86, 87:96, 97:106),
                    c(       57:66,               87:96, 97:106),
                    c(       57:66, 67:76,               97:106),
                    c(       57:66, 67:76, 77:86               ),
                    c(              67:76, 77:86, 87:96        )
                    ))



naniar::vis_miss(datmiss)

Estimation Model

est_model <- '
  # 1. Latent variable definition
  # POOLS
  EF =~ 1*p11 + p12 + p13 + p14 + p15# + p16 + p17 + p18 + p19 + p110
  ST =~ 1*p21 + p22 + p23 + p24 + p25# + p26 + p27 + p28 + p29 + p210
  IN =~ 1*p31 + p32 + p33 + p34 + p35# + p36 + p37 + p38 + p39 + p310
  EN =~ 1*p41 + p42 + p43 + p44 + p45# + p46 + p47 + p48 + p49 + p410
  
  # Self-Efficacy Items
  se1 =~ NA*eff1 + eff2 + eff3 + eff4
  se2 =~ NA*eff5 + eff6 + eff7 + eff8
  se3 =~ NA*eff9 + eff10 + eff11 + eff12
  
  # Teacher-Team Inno Scale
  tt =~ NA*ttis1 + ttis2 + ttis3 + ttis4 
  
  # NEO FFM
  A =~ NA*ffmA1 + ffmA2 + ffmA3 + ffmA4 + ffmA5 + ffmA6 + ffmA7 + ffmA8 + ffmA9 + ffmA10
  C =~ NA*ffmC1 + ffmC2 + ffmC3 + ffmC4 + ffmC5 + ffmC6 + ffmC7 + ffmC8 + ffmC9 + ffmC10
  O =~ NA*ffmO1 + ffmO2 + ffmO3 + ffmO4 + ffmO5 + ffmO6 + ffmO7 + ffmO8 + ffmO9 + ffmO10
  E =~ NA*ffmE1 + ffmE2 + ffmE3 + ffmE4 + ffmE5 + ffmE6 + ffmE7 + ffmE8 + ffmE9 + ffmE10
  N =~ NA*ffmN1 + ffmN2 + ffmN3 + ffmN4 + ffmN5 + ffmN6 + ffmN7 + ffmN8 + ffmN9 + ffmN10
  
  
  # 2. Latent variable covariances
  #   POOLS
    EF ~~ EF + ST + IN + EN
    ST ~~ ST + IN + EN
    IN ~~ IN + EN
  #   SE
    se1 ~~ 1*se1 + se2 + se3
    se2 ~~ 1*se2 + se3
    se3 ~~ 1*se3
  #   Team Inno.
    tt ~~ 1*tt
  #   FFM
    A ~~ 1*A + C + O + E + N
    C ~~ 1*C + O + E + N
    O ~~ 1*O + E + N
    E ~~ 1*E + N
    N ~~ 1*N
  
  # Research questions
  # 1. FFM accounting for variance of POOLS
  EF ~ A + C + O + E + N
  ST ~ A + C + O + E + N
  IN ~ A + C + O + E + N
  EN ~ A + C + O + E + N
  
  # 2. relationship between SE & Pools
  EF ~ se1 + se2 + se3
  ST ~ se1 + se2 + se3
  IN ~ se1 + se2 + se3
  EN ~ se1 + se2 + se3
  
  # 3. Team inno predicting POOLS
  EF ~ tt
  ST ~ tt
  IN ~ tt
  EN ~ tt

'

# use missing = "ML" for FIML
fit <- cfa(est_model, datmiss, estimator = "ML", missing = "ML")
summary(fit, standardized=T, fit.measures=T)

# ================================== #
# funciton:
#   data_function_categorization()
#
# Purpose:
#   categorize the continuous response 
# into the 5 discrete categories we
# will observe in the analysis.
# We plan to treat the data as continuous.
# But, we will also use a robust estimation
# method DWLS and 
# PML (pairwise maximum likelihood)
data_function_categorization <- function(data){
  tauCreate <- function(x){
    e <- rnorm(4,0, 0.01)
    BREAKS <- c(-Inf, -1.4+e[1], -0.4+e[2], 0.2+e[3], 1+e[4], Inf)
    
    x <- cut(x,
             breaks=BREAKS,
             labels = c(-2, -1, 0, 1, 2))
    as.numeric(x)-3 # center at 0
  }
  data[,1:106] <- apply(data[,1:106], 2, tauCreate)
  data
}


missdata_mech <- miss(
  nforms = 7,
  itemGroups = list(c(1:107),
                    c(),
                    c(41:56),
                    c(                     77:86, 87:96, 97:106),
                    c(       57:66,               87:96, 97:106),
                    c(       57:66, 67:76,               97:106),
                    c(       57:66, 67:76, 77:86               ),
                    c(              67:76, 77:86, 87:96        ))
)



sim_res <- sim(
  nRep = 5, n = 500,
  lavaanfun = "sem",
  model = list(model=est_model, estimator = "ML", missing = "ML"),
  generate = pop_model,
  miss = missdata_mech,
  datafun = data_function_categorization
)

sessionInfo()
R version 4.0.2 (2020-06-22)
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  mvtnorm_1.1-1     naniar_0.6.0     
 [5] simsem_0.5-15     lavaanPlot_0.5.1  semTools_0.5-3    lavaan_0.6-7     
 [9] data.table_1.13.0 patchwork_1.0.1   forcats_0.5.0     stringr_1.4.0    
[13] dplyr_1.0.1       purrr_0.3.4       readr_1.3.1       tidyr_1.1.1      
[17] tibble_3.0.3      ggplot2_3.3.2     tidyverse_1.3.0   workflowr_1.6.2  

loaded via a namespace (and not attached):
 [1] fs_1.5.0           lubridate_1.7.9    webshot_0.5.2      RColorBrewer_1.1-2
 [5] httr_1.4.2         rprojroot_1.3-2    tools_4.0.2        backports_1.1.7   
 [9] R6_2.4.1           DBI_1.1.0          colorspace_1.4-1   withr_2.2.0       
[13] tidyselect_1.1.0   mnormt_2.0.1       emmeans_1.4.8      compiler_4.0.2    
[17] git2r_0.27.1       cli_2.0.2          rvest_0.3.6        xml2_1.3.2        
[21] sandwich_2.5-1     labeling_0.3       scales_1.1.1       digest_0.6.25     
[25] pbivnorm_0.6.0     rmarkdown_2.3      pkgconfig_2.0.3    htmltools_0.5.0   
[29] dbplyr_1.4.4       htmlwidgets_1.5.1  rlang_0.4.7        readxl_1.3.1      
[33] rstudioapi_0.11    farver_2.0.3       visNetwork_2.0.9   generics_0.0.2    
[37] zoo_1.8-8          jsonlite_1.7.0     magrittr_1.5       Matrix_1.2-18     
[41] Rcpp_1.0.5         munsell_0.5.0      fansi_0.4.1        visdat_0.5.3      
[45] lifecycle_0.2.0    stringi_1.4.6      multcomp_1.4-13    yaml_2.2.1        
[49] MASS_7.3-51.6      grid_4.0.2         blob_1.2.1         promises_1.1.1    
[53] crayon_1.3.4       lattice_0.20-41    haven_2.3.1        splines_4.0.2     
[57] hms_0.5.3          tmvnsim_1.0-2      knitr_1.29         pillar_1.4.6      
[61] estimability_1.3   codetools_0.2-16   stats4_4.0.2       reprex_0.3.0      
[65] glue_1.4.1         evaluate_0.14      modelr_0.1.8       vctrs_0.3.2       
[69] httpuv_1.5.4       cellranger_1.1.0   gtable_0.3.0       assertthat_0.2.1  
[73] xfun_0.16          broom_0.7.0        coda_0.19-3        later_1.1.0.1     
[77] viridisLite_0.3.0  survival_3.2-3     DiagrammeR_1.0.6.1 TH.data_1.0-10    
[81] ellipsis_0.3.1