test_normality: Normality tests by groups

Description Usage Arguments Value See Also Examples

View source: R/test_normality.R

Description

Perform a test of normality for each group separately. The available tests: Shapiro-Wilk (default), Lilliefors (Kolmogorov-Smirnov), Anderson-Darling and other.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
test_normality(
  y,
  data = NULL,
  test = "Shapiro-Wilk",
  p_adjust_method = NULL,
  ...,
  groups = NULL,
  ss = signif_syms,
  hide_error_msg = FALSE
)

## S3 method for class 'test_normality'
print(
  x,
  ...,
  digits_p = 3,
  signif_stars = !is.null(ss),
  digits_stat = 3,
  format_stat = c("auto", "f", "g"),
  rm_zero = FALSE,
  legend = TRUE,
  show_col_method = FALSE,
  hide_error_msg = attr(x, "hide_error_msg"),
  ss = attr(x, "ss")
)

## S3 method for class 'test_normality'
pander(
  x,
  caption = NA,
  ...,
  digits_p = 3,
  signif_stars = !is.null(ss),
  digits_stat = 3,
  format_stat = c("auto", "f", "g"),
  rm_zero = FALSE,
  legend = TRUE,
  show_col_method = FALSE,
  hide_error_msg = attr(x, "hide_error_msg"),
  ss = attr(x, "ss")
)

Arguments

y

(formula|numeric|character)
Either a formula, a numeric vector or a name of a column in data.

  • If y is a formula (e.g. variable ~ factor), left-hand side provides the name of a variable to be tested. In the right-hand side there are names of factor variables to be used to create subsets. If the left-hand side is empty (e.g. ~ factor), right-hand side is treated as variable name to test.

data

(data frame|NULL)
Either a data frame that contains the variables mentioned in y or NULL (if the variables are in the function's environment).

test

(string | function)
Either a function that carries out a normality test or a string (case insensitive, maybe unambiguously abbreviated) with a name of a normality test. Possible names of tests:

  • "SW", "Shapiro-Wilk" — for Shapiro-Wilk test;

  • "Lilliefors" — for Kolmogorov-Smirnov test with Lilliefor's correction;

  • "AD", "Anderson-Darling" — for Anderson-Darling test;

  • "CVM", "CM", "Cramer-von Mises" — for Cramer-von Mises test;

  • "SF", "Shapiro-Francia" — for Shapiro-Francia test;

  • "Chi-squared","Pearsons" — for Pearson's chi-squared test of normality.

p_adjust_method

(NULL|string)
A name of p value adjustment method for multiple comparisons. For available methods check stats::p.adjust.methods(). If NULL, no adjusted p value is calculated (default). If string (e.g., "holm"), an additional column p.adjust is calculated.

...

Further parameters to the function of normatity test.

groups

(NULL|factor|character)
An alternative way to provide groups. If y is a numeric vector, groups must be a factor (or NULL). If y is a sting, groups must also be a string (or NULL).

ss

# FIXME: not documented

hide_error_msg

(logical)
If FALSE column "error_msg" is not printed. If TRUE the column is printed if error occurs in calcultations. Default is FALSE.

x

normality_test object.

digits_p

(numeric) Number of significant digits to round a p value to. No less than 2.

  • if digits_p = 2:

    1. values below 0.001 are printed as "<0.001";

    2. values between 0.001 and 0.01 as "<0.01";

    3. all other values are rounded to two decimal places.

  • if digits_p = 3, only formatting "<0.01" is skipped.

signif_stars

(logical)
If TRUE, significance stars are printed.

digits_stat

(integer)
Either a number of decimal places or number of significant digits to round test statistic to.

format_stat

(character)
Number format "f", "g" or "auto" (default) for test statistic. More about number formats "f" and "g" you can find in documentation of function base::formatC() section format.

rm_zero

(logical) Flag if leading zero before the point should be removed.

legend

(logical)
If TRUE, legend for significance stars is printed.

show_col_method

(logical)
If FALSE column "method" is not printed. Default is FALSE.

caption

(string|NULL|NA)
A caption for the table with results of a normality test. If NA — a default caption is printed (default). If NULL – no caption is printed.

Value

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
library(biostat)
library(pander)
data(CO2)

# For whole dataset
test_normality(~uptake, data = CO2)

# For each subgroup
test_normality(uptake ~ Treatment, data = CO2)

# For each subgroup by several factor variables
rez <- test_normality(uptake ~ Type + Treatment,
                      data = CO2)
rez

# Modify printed output
print(rez, rm_zero = TRUE)

print(rez, digits_p = 2)


# Choose another test of normality
rez2 <- test_normality(uptake ~ Type + Treatment,
                      data = CO2,
                      test = "chi-sq")
rez2


# Print as a 'pandoc' table (for R Markdown reports)
pander(rez)

pander(rez, digits_stat = 2)

pander(rez, digits_p = 2)

pander(rez, digits_p = 4, signif_stars = FALSE)


## Not run: 
# View unformatted results in a separate window
View(rez)

## End(Not run)

# Show object's class
class(rez)

GegznaV/BioStat documentation built on Aug. 14, 2020, 9:30 p.m.