Advertisement
silveira7

Batch Shapiro Test

Jun 29th, 2021
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.57 KB | None | 0 0
  1. library(huxtable)
  2.  
  3. shapiro.batch <- function(tbl) {
  4.     variables <- vector()
  5.     p_values <- vector()
  6.     n = 0
  7.     for (i in 1:ncol(tbl)) {
  8.         if (is.numeric(tbl[[i]])){
  9.             n = n + 1
  10.             x <- shapiro.test(tbl[[i]])
  11.             variables[n] <- colnames(tbl)[i]
  12.             if (x$p.value < 0.05) {
  13.                 p_values[n] <- "Not normal"
  14.             }
  15.             else {
  16.                 p_values[n] <- "Normal"
  17.             }
  18.         }
  19.     }
  20.     hux(Variable = variables,
  21.         Normality = p_values) %>%
  22.         set_position("left") %>%
  23.         set_bold(row = 1, col = everywhere) %>%
  24.         set_bottom_border(1, everywhere) %>%
  25.         set_bottom_border(final(1), everywhere)
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement