# load packages
library(dmtools)
library(dplyr, warn.conflicts = FALSE)
# set options
options(digits = 3)

Descriptive statistics

iris %>% desc_stats()
Descriptive statistics
Variables N Mean SE SD Median Min Max Range
Sepal.Length 150 5.84 0.068 0.828 5.80 4.3 7.9 3.6
Sepal.Width 150 3.06 0.036 0.436 3.00 2.0 4.4 2.4
Petal.Length 150 3.76 0.144 1.765 4.35 1.0 6.9 5.9
Petal.Width 150 1.20 0.062 0.762 1.30 0.1 2.5 2.4
iris %>% desc_stats(norm = TRUE)
Descriptive statistics
Variables N Mean SE SD Median Min Max Range W p-value
Sepal.Length 150 5.84 0.068 0.828 5.80 4.3 7.9 3.6 0.976 0.01
Sepal.Width 150 3.06 0.036 0.436 3.00 2.0 4.4 2.4 0.985 0.101
Petal.Length 150 3.76 0.144 1.765 4.35 1.0 6.9 5.9 0.876 < 0.001
Petal.Width 150 1.20 0.062 0.762 1.30 0.1 2.5 2.4 0.902 < 0.001

\(W\) — Shapiro-Wilk Normality Test.

iris %>% group_by(Species) %>% desc_stats()
Descriptive statistics
Species Variables N Mean SE SD Median Min Max Range
setosa Sepal.Length 50 5.006 0.050 0.352 5.00 4.3 5.8 1.5
setosa Sepal.Width 50 3.428 0.054 0.379 3.40 2.3 4.4 2.1
setosa Petal.Length 50 1.462 0.025 0.174 1.50 1.0 1.9 0.9
setosa Petal.Width 50 0.246 0.015 0.105 0.20 0.1 0.6 0.5
versicolor Sepal.Length 50 5.936 0.073 0.516 5.90 4.9 7.0 2.1
versicolor Sepal.Width 50 2.770 0.044 0.314 2.80 2.0 3.4 1.4
versicolor Petal.Length 50 4.260 0.066 0.470 4.35 3.0 5.1 2.1
versicolor Petal.Width 50 1.326 0.028 0.198 1.30 1.0 1.8 0.8
virginica Sepal.Length 50 6.588 0.090 0.636 6.50 4.9 7.9 3.0
virginica Sepal.Width 50 2.974 0.046 0.322 3.00 2.2 3.8 1.6
virginica Petal.Length 50 5.552 0.078 0.552 5.55 4.5 6.9 2.4
virginica Petal.Width 50 2.026 0.039 0.275 2.00 1.4 2.5 1.1
iris %>% desc_stats_by(by = 5)
Descriptive statistics
Species Variables N Mean SE SD Median Min Max Range
setosa Sepal.Length 50 5.006 0.050 0.352 5.00 4.3 5.8 1.5
setosa Sepal.Width 50 3.428 0.054 0.379 3.40 2.3 4.4 2.1
setosa Petal.Length 50 1.462 0.025 0.174 1.50 1.0 1.9 0.9
setosa Petal.Width 50 0.246 0.015 0.105 0.20 0.1 0.6 0.5
versicolor Sepal.Length 50 5.936 0.073 0.516 5.90 4.9 7.0 2.1
versicolor Sepal.Width 50 2.770 0.044 0.314 2.80 2.0 3.4 1.4
versicolor Petal.Length 50 4.260 0.066 0.470 4.35 3.0 5.1 2.1
versicolor Petal.Width 50 1.326 0.028 0.198 1.30 1.0 1.8 0.8
virginica Sepal.Length 50 6.588 0.090 0.636 6.50 4.9 7.9 3.0
virginica Sepal.Width 50 2.974 0.046 0.322 3.00 2.2 3.8 1.6
virginica Petal.Length 50 5.552 0.078 0.552 5.55 4.5 6.9 2.4
virginica Petal.Width 50 2.026 0.039 0.275 2.00 1.4 2.5 1.1

Normality tests

iris %>% norm_test()
Variables W p-value
Sepal.Length 0.976 0.01
Sepal.Width 0.985 0.101
Petal.Length 0.876 < 0.001
Petal.Width 0.902 < 0.001
iris %>% group_by(Species) %>% norm_test()
Shapiro-Wilk normality test
Species Variables W p-value
setosa Sepal.Length 0.978 0.46
setosa Sepal.Width 0.972 0.272
setosa Petal.Length 0.955 0.055
setosa Petal.Width 0.800 < 0.001
versicolor Sepal.Length 0.978 0.465
versicolor Sepal.Width 0.974 0.338
versicolor Petal.Length 0.966 0.158
versicolor Petal.Width 0.948 0.027
virginica Sepal.Length 0.971 0.258
virginica Sepal.Width 0.967 0.181
virginica Petal.Length 0.962 0.11
virginica Petal.Width 0.960 0.087
iris %>% norm_test_by(by = 5)
Shapiro-Wilk normality test
Species Variables W p-value
setosa Sepal.Length 0.978 0.46
setosa Sepal.Width 0.972 0.272
setosa Petal.Length 0.955 0.055
setosa Petal.Width 0.800 < 0.001
versicolor Sepal.Length 0.978 0.465
versicolor Sepal.Width 0.974 0.338
versicolor Petal.Length 0.966 0.158
versicolor Petal.Width 0.948 0.027
virginica Sepal.Length 0.971 0.258
virginica Sepal.Width 0.967 0.181
virginica Petal.Length 0.962 0.11
virginica Petal.Width 0.960 0.087

Normality plots

norm_plot(iris[, 1])

iris %>% norm_plot()

Statistical tests

In the chunk

t.test(extra ~ group, sleep, paired = TRUE)
Paired t-test: ‘extra’ by ‘group’
t df p-value hypothesis
-4.06 9 0.003 two.sided
oneway.test(Sepal.Length ~ Species, data = iris)
One-way analysis of means (not assuming equal variances): ‘Sepal.Length’ and ‘Species’
F num df denom df p-value
139 2 92.2 < 0.001

Inline

T-test : t = -4.062; df = 9; p-value = 0.003.

1-way ANOVA: F = 138.908; num df = 2; denom df = 92.211; p-value = < 0.001 .