-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
197 lines (122 loc) · 3.79 KB
/
README.Rmd
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
---
title: "README for package `sbwtools`"
author: "Author: S. Bryan West<br>"
output:
github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# sbwtools
<!-- badges: start -->
<!-- badges: end -->
**sbwtools** is a package containing my most frequently used custom functions I have either written myself or borrowed from other, more skilled programmers.
### News
Updated `ci_df` and `ci_boot_df` functions to use `dplyr::reframe()` instead of `dplyr::summarize()`,
as of `dplyr` [version 1.1.0](https://www.tidyverse.org/blog/2023/02/dplyr-1-1-0-pick-reframe-arrange/#reframe)
## System Information
Updated on `r Sys.time()`
```{r}
sessioninfo::platform_info()
```
## Installation
sbwtools is only available from [GitHub](https://github.com/). Install with:
```{r install info, eval = FALSE}
# install.packages("devtools")
devtools::install_github("sbw78/sbwtools")
```
## Credits
Credit to [Kevin Ushey](github.com/kevinushey/etc) for the functions [hh](#hh and ht),
[ht](#hh and ht), [last](#last), [se](#se). He created these functions for his
.Rprofile dotfile, which you can find at his github repo.
Credit to [Jacob Long](https://jacob-long.com) for the `theme_apa` used in
[`make_forest_plot`](#make_forest_plot).
## Function examples
### `ci_df`
Build a dataframe with the mean and confidence intervals of a continuous
variable, with optional grouping.
```{r ci_df}
library(sbwtools)
library(dplyr)
ci_data <- iris %>%
as_tibble() %>%
ci_df(., Petal.Length, Species)
```
****
### `ci_boot_df`
Same as `ci_df`, but with bootstrapped sampling
```{r ci_boot_df}
ci_boot_data <- iris %>%
as_tibble() %>%
ci_boot_df(., Petal.Length, Species)
```
****
### `custom_kable`
Customized `knitr::kable` output.
```{r custom_kable, eval = FALSE}
custom_kable(ci_data, caption = "Summarized data from iris",
col.names = c("Species", "n", "Petal Length", "Lower CI", "Upper CI", "sd"))
custom_kable(ci_data, caption = "Summarized data from iris",
col.names = c("Species", "n", "Petal Length", "Lower CI", "Upper CI", "sd")) %>%
kableExtra::footnote(general = "1000 bootstrapped samples")
```
****
### `format_pval`
Format p-values (i.e. "< .001" for values less than .001).
```{r format_pval}
fit <- lm(Sepal.Length ~ Species, data = iris)
summary_df <- broom::tidy(fit)
# Without formatting p-value
summary_df
# Formatted p-value
mutate(summary_df, p.value = format_pval(p.value))
```
****
### `hh` and `ht`
`hh`: Get first 5 rows and first 5 columns of a data frame or matrix
`ht`: Get the first 10 rows and last 10 rows of a data frame or matrix.
Credit: [Kevin Ushey](github.com/kevinushey/etc)
```{r hh ht}
hh(iris)
ht(iris)
```
****
****
### `last`
Get the last element of a vector or list.
Credit: [Kevin Ushey](github.com/kevinushey/etc)
```{r}
last(letters)
```
****
### `make_forest_plot`
Build a forest plot.
Credit: [Jacob Long](https://jacob-long.com), author of the
[jtools package](https://jtools.jacob-long.com "jtools")
([github](https://github.com/jacob-long/jtools "GitHub")) from which this function
borrows the `ggplot2` theme `theme_apa()`.
```{r make_forest_plot}
p <- make_forest_plot(ci_data, mean_Petal.Length, Species, xlab = "Mean petal length",
ylab = "Species", ci_low, ci_high)
p
```
****
### `regex_build`
Combine a character vector into a single regex list.
```{r regex_build}
regex_build(c("apples", "oranges", "bananas"))
regex_build(c("apples", "passion fruit", "oranges"), modifier = "multi")
```
****
### `se`
Calculate standard error.
Credit: [Kevin Ushey](github.com/kevinushey/etc)
```{r se}
se(iris$Sepal.Length)
```