Chapter02 {DanielBiostatistics10th} R Documentation

## Chapter 2

### Description

Functions and examples for Chapter 2, Descriptive Statistics.

### Usage

print_stats(x, na.rm = TRUE)

print_freqs(x, breaks, include.lowest = TRUE, right = TRUE)


### Arguments

 x numeric vector, the observations. In function print_freqs(), this argument can also be a factor na.rm logical scalar, whether to remove the missing observations (default TRUE) breaks numeric vector, see cut.default include.lowest logical scalar, default TRUE. See cut.default right logical scalar, see cut.default

### Details

Function print_freqs() prints the (relative) frequencies and cumulative (relative) frequencies, from a numeric input vector, specified interval breaks as well as open/close status of the ends of the intervals.

Function print_stats() prints the simple statistics of the input observations, such as sample size, mean, median, (smallest) mode, variance, standard deviation, coefficient of variation (if all observations are non-negative), quartiles, inter-quartile range (IQR), range, skewness and kurtosis. A histogram is also printed.

### Value

Function print_freqs() returns a freqs object, for which a show method, an autolayer and an autoplot method are defined.

Function print_stats() does not have a returned value.

### References

Wayne W. Daniel, Biostatistics: A Foundation for Analysis in the Health Sciences, Tenth Edition. Wiley, ISBN: 978-1-119-62550-6.

### Examples

library(DanielBiostatistics10th)

# Page 20, Example 2.2.1
class(EXA_C01_S04_01$AGE) # 'integer' class(age <- as.numeric(EXA_C01_S04_01$AGE)) # 'numeric'
sort(age) # Page 21, Table 2.2.1 # 'ordered vector'

# Page 23, Example 2.3.1
(ageB = seq.int(from = 30, to = 90, by = 10))
(r231 = print_freqs(age, breaks = ageB, right = FALSE)) # Page 25, Table 2.3.2
# The open/close of interval ends is determined by textbook using 30-39, 40-49, etc.
autoplot(r231) + labs(title = 'Page 27, Figure 2.3.2')

# Page 38-42, Example 2.4.1 - Example 2.4.6
# Page 44-46, Example 2.5.1 - Example 2.5.3
print_stats(age) # or some other data input

# Page 49, Example 2.5.4 (omitted)

# Page 50, Example 2.5.5
boxplot(EXA_C02_S05_05$GRF, main = c('GRF from Page 50, Example 2.5.5')) print_stats(EXA_C02_S05_05$GRF)