
<div style="display:block;clear:both;" class="scale-structure-start"></div>
<div class="scale-structure-container">

```{r,eval=TRUE, echo=FALSE}

digits <- x$input$digits;

if (!exists('headingLevel') || !is.numeric(headingLevel) || (length(headingLevel) != 1)) {
	headingLevel <- 0;
}

```

`r ufs::repStr("#", headingLevel);` Scale structure

```{r, echo=echoPartial, results='asis'}

  if (utils::packageVersion('psych') < '1.5.4') {
    ufs::cat0("Note: your version of package 'psych' is lower than 1.5.4 (",
              as.character(utils::packageVersion('psych')), " to be precise). This means that you ",
              "might see errors from the 'fa' function above this notice. ",
              "You can safely ignore these.\n\n");
  }

  ufs::cat0("\n\n",
            ufs::repStr("#", headingLevel + 1),
            " Information about this scale",
            "\n\n");
  
  overviewDf <-
    data.frame(values = c(x$input$dat.name,
                          ufs::vecTxt(x$input$items),
                          x$input$n.observations,
                          x$intermediate$cor.pos,
                          x$intermediate$cor.total,
                          round(100*x$intermediate$cor.proPos)),
               stringsAsFactors = FALSE);

  row.names(overviewDf) <- c("Dataframe:",
                             "Items:",
                             "Observations:",
                             "Positive correlations:",
                             "Number of correlations:",
                             "Percentage positive correlations:");

  knitr::kable(overviewDf,
               row.names=TRUE,
               col.names="");

  ufs::cat0("\n\n",
            ufs::repStr("#", headingLevel + 1),
            " Estimates assuming interval level",
            "\n\n");

  if (x$input$n.items > 2) {
    
    intervalDf <-
      data.frame(values = c(round(x$output$omega, digits=digits),
                            round(x$intermediate$omega.psych$omega_h, digits=digits),
                            ifelse(x$input$omega.psych,
                                   round(x$output$omega.psych, digits=digits),
                                   NULL),
                            round(x$output$glb, digits=digits),
                            round(x$output$coefficientH, digits=digits),
                            round(x$output$cronbach.alpha, digits=digits)),
                 stringsAsFactors = FALSE);
  
    row.names(intervalDf) <- c("Omega (total):",
                               "Omega (hierarchical):",
                               ifelse(x$input$omega.psych,
                                      "Revelle's Omega (total):",
                                      NULL),
                               "Greatest Lower Bound (GLB):",
                               "Coefficient H:",
                               "Coefficient Alpha:");
  
    print(knitr::kable(intervalDf,
                       row.names=TRUE,
                       col.names=""));
        
    if (x$input$ci & !is.null(x$output$alpha.ci)) {
      
      ### If confidence intervals were computed AND obtained, print them
      ufs::cat0("\n\n",
                ufs::repStr("#", headingLevel + 2),
                " Confidence intervals",
                "\n\n");
      
      intervalCIDf <-
        data.frame(values = c(ufs::formatCI(x$output$omega.ci,
                                            digits = digits),
                              ufs::formatCI(x$output$alpha.ci,
                                            digits = digits)),
                   stringsAsFactors = FALSE);

      row.names(intervalCIDf) <- c("Omega (total):",
                                   "Coefficient Alpha:");
      
      print(knitr::kable(intervalCIDf,
                         row.names=TRUE,
                         col.names=""));
      
    }
    if (x$input$poly && x$intermediate$maxLevels < 9 && x$intermediate$maxRange < 9) {
      if (!is.null(x$intermediate$omega.ordinal)) {
        
        cat0("\n\n",
             ufs::repStr("#", headingLevel + 1),
             " Estimates assuming ordinal level",
             "\n\n");
        
        ordinalDf <-
          data.frame(values = c(round(x$intermediate$omega.ordinal$est, digits=digits),
                                round(x$intermediate$omega.ordinal.hierarchical$est, digits=digits),
                                round(x$intermediate$alpha.ordinal$est, digits=digits)),
                     stringsAsFactors = FALSE);
        row.names(ordinalDf) <- c("Ordinal Omega (total):",
                                  "Ordinal Omega (hierarch.):",
                                  "Ordinal Coefficient Alpha:");
          
        print(knitr::kable(ordinalDf,
                           row.names=TRUE,
                           col.names=""));
        
        if (x$input$ci & !is.null(x$output$alpha.ordinal.ci)) {
              
          ### If confidence intervals were computed AND obtained, print them
          ufs::cat0("\n\n",
                    ufs::repStr("#", headingLevel + 2),
                    " Confidence intervals",
                    "\n\n");
          
          ordinalCIDf <-
            data.frame(values = c(ufs::formatCI(x$output$omega.ordinal.ci,
                                                digits = digits),
                                  ufs::formatCI(x$output$alpha.ordinal.ci,
                                                digits = digits)),
                       stringsAsFactors = FALSE);
          row.names(ordinalCIDf) <- c("Ordinal Omega (total):",
                                      "Ordinal Coefficient Alpha:");
          
          print(knitr::kable(ordinalCIDf,
                             row.names=TRUE,
                             col.names=""));
          
        }
      } else {
        ufs::cat0("\n\n(Estimates assuming ordinal level ",
                  "not computed, as the polychoric ",
                  "correlation matrix has missing values.)\n\n");
      }
    } else if (x$input$poly == TRUE){
      cat("\n\n(Estimates assuming ordinal level not computed, as ",
          "at least one item seems to have more than 8 levels; ",
          "the highest number of distinct levels is ",
          x$intermediate$maxLevels, " and the highest range is ",
          x$intermediate$maxRange, ". This last number needs to be ",
          "lower than 9 for the polychoric function to work. ",
          "If this is unexpected, you may want to ",
          "check for outliers.)\n\n", sep="");
    }
    if (x$input$omega.psych) {
      cat(paste0("\n\nNote: the normal point estimate and confidence ",
                 "interval for omega are based on the procedure suggested by ",
                 "Dunn, Baguley & Brunsden (2013) using the MBESS function ",
                 "ci.reliability, whereas the psych package point estimate was ",
                 "suggested in Revelle & Zinbarg (2008). See the help ",
                 "('?ufs::scaleStructure') for more information.\n\n"));
    } else {
      cat(paste0("\n\nNote: the normal point estimate and confidence ",
                 "interval for omega are based on the procedure suggested by ",
                 "Dunn, Baguley & Brunsden (2013). To obtain the (usually ",
                 "higher) omega point estimate using the procedure ",
                 "suggested by Revelle & Zinbarg (2008), use ",
                 "argument 'omega.psych=TRUE'. See the help ('?ufs::scaleStructure') ",
                 "for more information. Of course, you can also call ",
                 "the 'psych::omega' function from the psych package directly.\n\n"));
    }
  } else if (x$input$n.items == 2) {

    ufs::cat0("\n\n",
              ufs::repStr("#", headingLevel + 1),
              " Estimates for two-item measures",
              "\n\n");
    
    dualItemDf <-
      data.frame(values = c(round(x$output$spearman.brown, digits=digits),
                            round(x$output$cronbach.alpha, digits=digits),
                            round(x$intermediate$cor[1, 2], digits=digits)),
                 stringsAsFactors = FALSE);
    row.names(dualItemDf) <- c("Spearman Brown coefficient:",
                               "Coefficient Alpha:",
                               "Pearson Correlation:");
      
    print(knitr::kable(dualItemDf,
                       row.names=TRUE,
                       col.names=""));

  }

```

</div>
<div style="display:block;clear:both;" class="scale-structure-end"></div>
