Last updated: 2020-06-10

Checks: 6 1

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.


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 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:    data/results_bias_se.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-anova-estimates.Rmd
    Untracked:  analysis/ml-cfa-parameter-anova-relative-bias.Rmd
    Untracked:  analysis/ml-cfa-parameter-bias-latent-ICC.Rmd
    Untracked:  analysis/ml-cfa-parameter-bias-observed-ICC.Rmd
    Untracked:  analysis/ml-cfa-parameter-convergence-correlation-pubfigure.Rmd
    Untracked:  analysis/ml-cfa-parameter-convergence-trace-plots-factor-loadings.Rmd
    Untracked:  analysis/ml-cfa-standard-error-anova-logSE.Rmd
    Untracked:  analysis/ml-cfa-standard-error-anova-relative-bias.Rmd
    Untracked:  analysis/ml-cfa-standard-error-bias-factor-loadings.Rmd
    Untracked:  analysis/ml-cfa-standard-error-bias-level1-factor-covariances.Rmd
    Untracked:  analysis/ml-cfa-standard-error-bias-level2-factor-covariances.Rmd
    Untracked:  analysis/ml-cfa-standard-error-bias-level2-factor-variances.Rmd
    Untracked:  analysis/ml-cfa-standard-error-bias-level2-residual-variances.Rmd
    Untracked:  analysis/ml-cfa-standard-error-bias-overview.Rmd
    Untracked:  code/r_functions.R
    Untracked:  renv.lock
    Untracked:  renv/

Unstaged changes:
    Modified:   .gitignore
    Modified:   analysis/index.Rmd
    Modified:   analysis/ml-cfa-convergence-summary.Rmd
    Modified:   analysis/ml-cfa-parameter-convergence-correlation-factor-loadings.Rmd
    Modified:   code/get_data.R
    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.


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


On this page, we describe the methods that are used for decomposing the effects on parameter estimations in terms of different estimates of bias with respect to standard errors.

Empirical Standard Error

First, we need to compute what the true'' standard errors are with respect to each parameter. We have generated a sampling distribution for each parameter in our study, and so can use this sample distribution to compute anempirical standard error.’’ The empirical standard error is simply the standard deviation of the sampling distribution of the parameter (in that specific condition) (Bandalos & Gagné, 2012). Which we will call \(SE(\hat{\theta}_i)\), the empirical standard error of the \(i\)-th parameter.

Standard Error Bias

The bias of standard errors is formally computed as

\[ Bias\left(SE(\hat{\theta}_i)\right) = \sum_{j=1}^{n_r}\left(\frac{\widehat{SE}(\hat{\theta}_i)_j- SE(\hat{\theta}_i)}{SE(\hat{\theta}_i)}\right)/n_r\times 100 \] where, \(\widehat{SE}(\hat{\theta}_i)_j\) is the estimated standard error of the \(i\)-th parameter in the \(j\)-th replication. We will follow the suggestion of Hoogland and Boomsma (1998) that bias \(\leq \mid 5\%\mid\) is considered an ``acceptable’’ level of bias.

Bias will be estimated for

  1. Factor loadings (\(\lambda_{1-10}\)),
  2. Level-1 factor covariance (\(\psi_{W12}\)),
  3. Level-2 factor (co)variances (\(\psi_{B1}, \psi_{B2}, \psi_{B12}\)),
  4. Level-2 item residual variances (\(\theta_{B1-10}\)), and

Estimation Method Efficiency

Another aspect of the standard error estimates that was of interest was the variability in standard error estimates between estimation methods. Meaning, which estimation method was least variable relative to the other methods. We compute an efficiency ratio (or relative efficiency) between estimation methods (m = MLR, u = ULSMV, and w = WLSMV). \[ RE = \sqrt{\left(\frac{\sum_{\forall j}(\widehat{SE}(\hat{\theta}_i)_{mj}- SE(\hat{\theta}_i))^2}{\sum_{\forall j}(\widehat{SE}(\hat{\theta}_i)_{uj}- SE(\hat{\theta}_i))^2}\right)} \] where RE = relative efficiency, and the ratio was computed for all three pairwise comparisons of (m, u, w).

Computing bias and efficiency estimates

Here, we estimated the bias estimates.

First, we set up some functions to compute the values of interest.

#compute RB
# p = parameter estimate of interest
# pt = true value of parameter of interest
est_relative_bias <- function(data, p, pt){
  
  nr <- nrow(data)
  data[, pt] <- as.numeric(data[,pt, drop=T])
  
  rb <- sum((data[, p] - data[, pt])/data[,pt], na.rm = T)/nr*100
  names(rb) <- 'RB'
  return(rb)
}

# compute RMSE components
est_rmse <- function(data, p, pt){
  nr <- nrow(data)
  data[, pt] <- as.numeric(data[,pt, drop=T])
  
  est_a <- mean(data[,p, drop=T], na.rm = T)
  bias <- (est_a - data[,pt, drop=T][1])**2
  sv <- sum((data[, p, drop=T] - est_a)**2, na.rm=T)/nr
  rmse <- bias + sv
  out <- c(rmse, bias, sv)
  names(out) <- c('RMSE', 'Bias', 'SampVar')
  return(out)
}

# compute estimated relative efficiency of 
#  parameter est between two estimation methods
est_relative_efficiency <- function(data, p, pt, est1, est2){

  dat1 <- filter(data, Estimator == est1)
  dat2 <- filter(data, Estimator == est2)
  dat1[,pt] <- as.numeric(dat1[,pt, drop=T])
  dat2[,pt] <- as.numeric(dat2[,pt, drop=T])
  re <- sqrt(sum( (dat1[, p, drop=T] - dat1[, pt, drop=T])**2, na.rm=T)/sum( (dat2[, p, drop=T] - dat2[, pt, drop=T])**2, na.rm=T))
  names(re) <- 'RE'
  return(re)
}

Running Computations

Next, loop through the desired results to get the estimates of bias of interest. For more details on the naming of variables for the true values, see the Data Cleaning page.

source(paste0(getwd(),"/code/load_packages.R"))
source(paste0(getwd(),"/code/get_data.R"))

# take out non-converged/inadmissible cases
sim_results <- filter(sim_results, Converge==1, Admissible==1)

# set up vectors of variable names
pvec <- c(paste0('selambda1',1:6), paste0('selambda2',6:10), 'sepsiW12','sepsiB1', 'sepsiB2', 'sepsiB12', paste0('sethetaB',1:10))

# Compute empirical standard errors
sim_results <- sim_results %>%
  group_by(Condition, Estimator) %>%
  mutate(EmpSElambda11 = sd(lambda11), EmpSElambda12 = sd(lambda12),
         EmpSElambda13 = sd(lambda13), EmpSElambda14 = sd(lambda14),
         EmpSElambda15 = sd(lambda15), EmpSElambda16 = sd(lambda16),
         EmpSElambda26 = sd(lambda26), EmpSElambda27 = sd(lambda27),
         EmpSElambda28 = sd(lambda28), EmpSElambda29 = sd(lambda29),
         EmpSElambda210 = sd(lambda210),
         EmpSEpsiW12 = sd(psiW12), EmpSEpsiB1 = sd(psiB1),
         EmpSEpsiB2 = sd(psiB2), EmpSEpsiB12 = sd(psiB12),
         EmpSEthetaB1 = sd(thetaB1), EmpSEthetaB2 = sd(thetaB2),
         EmpSEthetaB3 = sd(thetaB3), EmpSEthetaB4 = sd(thetaB4),
         EmpSEthetaB5 = sd(thetaB5), EmpSEthetaB6 = sd(thetaB6),
         EmpSEthetaB7 = sd(thetaB7), EmpSEthetaB8 = sd(thetaB8),
         EmpSEthetaB9 = sd(thetaB9), EmpSEthetaB10 = sd(thetaB10))

# vector of empirical SE names
# set up vectors of variable names
ptvec <- c(paste0('EmpSElambda1',1:6), paste0('EmpSElambda2',6:10), 'EmpSEpsiW12','EmpSEpsiB1', 'EmpSEpsiB2', 'EmpSEpsiB12', paste0('EmpSEthetaB',1:10))

# iterators - conditions
N1 <- unique(sim_results$ss_l1)
N2 <- unique(sim_results$ss_l2)
ICC_LV <- unique(sim_results$icc_lv)
ICC_OV <- unique(sim_results$icc_ov)
EST <- unique(sim_results$Estimator)

# results matrix
result <- data.frame(matrix(nrow=length(N1)*length(N2)*length(ICC_LV)*length(ICC_OV)*length(pvec)*length(EST), ncol=(17)))
colnames(result) <- c('N1', 'N2', 'ICC_LV' ,'ICC_OV', 'Variable', 'Estimator','EmpSE', 'RB', 'RMSE', 'Bias', 'SampVar', 'muRE', 'mwRE', 'uwRE', 'nRep', 'estMean', 'estSD')

j <- 1 # row id
for(n1 in N1){
  for(n2 in N2){
    for(iccl in ICC_LV){
      for(icco in ICC_OV){
        for(i in 1:length(pvec)){
            
            dat <- filter(sim_results, ss_l1 == n1, ss_l2==n2,
                          icc_lv==iccl, icc_ov==icco)
            result[j:(j+2), 1:5] <- matrix(rep(c(n1,n2, iccl,icco, pvec[i]),3),
                                           ncol=5, byrow = T)
              
              # compute bias by each estimation method
              k <- 0
              for(est in EST){
                sdat <- filter(dat, Estimator==est)
                result[j+k, 6] <- est
                result[j+k, 7] <- sdat[1, ptvec[i], drop=T]
                result[j+k, 8] <- est_relative_bias(sdat, pvec[i], ptvec[i])
                result[j+k, 9:11] <- est_rmse(sdat, pvec[i], ptvec[i])
                result[j+k, 15] <- nrow(sdat) # number of converged replications
                result[j+k, 16] <- mean(sdat[, pvec[i], drop=T])
                result[j+k, 17] <- sd(sdat[, pvec[i], drop=T])
                k<-k+1
              }
              # Compute Relative Efficiency
              # MLR vs. ULSMV
              result[j:(j+2), 12] <- est_relative_efficiency(dat, pvec[i], ptvec[i],
                                                       'MLR','ULSMV')
              # MLR vs. WLSMV
              result[j:(j+2), 13] <- est_relative_efficiency(dat, pvec[i], ptvec[i],
                                                       'MLR','WLSMV')
              # ULSMV vs. WLSMV
              result[j:(j+2), 14] <- est_relative_efficiency(dat, pvec[i], ptvec[i],
                                                       'ULSMV','WLSMV')
              
          # update row
          j <- j+3
        }
      }
    }
  }
}

So, there are a lot of results that could be reported from this matrix of results. We have saved these results and these estimates are included in the accompanying Shiny app for more detailed exploration by those interested. Here, we describe a subset of the results that we feel are most important.

Summarizing Results

First, we will plot estimates (boxplots) to show how these estimates changed across conditions. To summarize the results we will average over the parameters that only differ y indices. Meaning we will describe the “average factor loading bias” by reporting the average bias for factor loadings. Additionally, different conditions resultedin different “sample sizes.” By this we mean the number of uses replications. The different number of cases per condition was accounted for by creating a “weight” variable for each row of the result object. This meant that conditions that had more usable replications counted more towards to averages reported (or count as much as if we averaged over the individual replications).

result$wi <- result$nRep/500
# 500 is the max number of replications per cell

# Save Results
write_csv(result, path=paste0(w.d, "/data/results_bias_se.csv"))

References

  1. Bandalos, D. L., & Gagné, P. (2012). Simulation methods in structural equation modeling. In R. H. Hoyle (Ed.), Handbook of structural equation modeling (pp. 92–108). New York, NY: Guilford Press.

  2. Hoogland, J. J., & Boomsma, A. (1998). Robustness studies in covariance structure modeling: An overview and a meta-analysis. Sociological Methods & Research, 26(3), 329-367.


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] workflowr_1.6.2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6    rprojroot_1.3-2 digest_0.6.25   later_1.0.0    
 [5] R6_2.4.1        backports_1.1.7 git2r_0.27.1    magrittr_1.5   
 [9] evaluate_0.14   stringi_1.4.6   rlang_0.4.6     fs_1.4.1       
[13] promises_1.1.0  rmarkdown_2.1   tools_3.6.3     stringr_1.4.0  
[17] glue_1.4.1      httpuv_1.5.2    xfun_0.14       yaml_2.2.1     
[21] compiler_3.6.3  htmltools_0.4.0 knitr_1.28