You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The **bregr** package is designed to simplify and streamline the process of **b**atch processing **reg**ression models in **R**. Whether you're working with univariate or multivariate models, bregr makes it easy to handle multiple analyses at once. The package returns results in a tidy format, ensuring that the output is organized and accessible for further analysis or reporting. Additionally, bregr generates clear visualization plots that aid in the straightforward interpretation of model results. This makes it an invaluable tool for anyone working with regression models in R, allowing you to focus more on deriving insights and less on the mechanics of setting up and processing models.
25
+
26
+
27
+
## A overview of regression modeling in batch
28
+
29
+
Regression modeling in batch involves constructing a series of regression models
30
+
with same or different dependent variables $y_i$ in each model, different independent variables $x_i$
31
+
of interest (focal) in each model, and constant variables (constant) in all models.
You can install the stable version of bregr from CRAN with:
45
+
46
+
```r
47
+
install.packages("bregr")
48
+
```
49
+
28
50
You can install the development version of bregr from [GitHub](https://github.com/) with:
29
51
30
52
```r
31
53
# install.packages("pak")
32
54
pak::pak("WangLabCSU/bregr")
33
55
```
34
56
35
-
## Example
57
+
## Usage
36
58
37
-
This is a basic example which shows you how to solve a common problem:
59
+
Load package(s):
38
60
39
-
```{rexample}
61
+
```{rload-package}
40
62
library(bregr)
41
-
## basic example code
42
63
```
43
64
44
-
What is special about using `README.Rmd` instead of just `README.md`? You can include R chunks like so:
65
+
Load data:
66
+
67
+
```{r load-data}
68
+
lung = survival::lung
69
+
lung$ph.ecog = factor(lung$ph.ecog)
70
+
```
71
+
72
+
The design and implementation of bregr follow [Tidy design principles](https://design.tidyverse.org/) and [Tidyverse style guide](https://style.tidyverse.org/), which is easy to understand and use.
73
+
74
+
### Basics and workflow
75
+
76
+
1. Construct a `breg` object:
77
+
78
+
```{r}
79
+
breg(lung)
80
+
```
81
+
82
+
2. Set model response (i.e., dependent) variable(s):
83
+
84
+
```{r}
85
+
breg(lung) |>
86
+
br_set_y(c("time", "status"))
87
+
```
88
+
89
+
2. Set model predictor (i.e., independent) variables. In batch analysis, this is
90
+
divided into two parts: 1) focal variables and 2) control variables.
91
+
92
+
Focal variables are injected into constructed models one by one, while
93
+
control variables remain constant across all constructed models.
94
+
95
+
```{r}
96
+
breg(lung) |>
97
+
br_set_y(c("time", "status")) |>
98
+
br_set_x(colnames(lung)[6:10]) |> # set focal terms
99
+
br_set_x2(c("age", "sex")) # set control terms, this is optional
100
+
```
101
+
> `terms` is desribed in the result object as bregr supports a more broader scope of
102
+
> predictors. e.g., `x + poly(x, 2)` has one variable x, but two terms `x` and `poly(x, 2)`.
103
+
45
104
46
-
```{r cars}
47
-
summary(cars)
105
+
3. Set model configuration.
106
+
107
+
Here, "coxph" (Cox-PH) for survival analysis is given.
108
+
109
+
```{r}
110
+
mds = breg(lung) |>
111
+
br_set_y(c("time", "status")) |>
112
+
br_set_x(colnames(lung)[6:10]) |>
113
+
br_set_x2(c("age", "sex")) |>
114
+
br_set_model("coxph")
115
+
mds
116
+
```
117
+
We can check constructed model formulas in text format.
118
+
119
+
```{r}
120
+
br_get_models(mds)
121
+
# or mds@models
122
+
```
123
+
4. The final step is constructing modeling with data and options defined above.
124
+
125
+
```{r}
126
+
mds = breg(lung) |>
127
+
br_set_y(c("time", "status")) |>
128
+
br_set_x(colnames(lung)[6:10]) |>
129
+
br_set_x2(c("age", "sex")) |>
130
+
br_set_model("coxph") |>
131
+
br_run()
132
+
mds
133
+
```
134
+
135
+
Now the `models` slot has been updated to real model objects:
136
+
137
+
```{r}
138
+
br_get_models(mds)
139
+
```
140
+
141
+
Tidy and comprehensive modeling results can be obtained from slots `results_tidy` and `results`,
142
+
respectively.
143
+
144
+
```{r}
145
+
br_get_results(mds, tidy = TRUE)
146
+
br_get_results(mds)
147
+
```
148
+
149
+
We can see that the whole workflow is easy to read and they are combined by R native operators.
150
+
151
+
```
152
+
breg(lung) |>
153
+
br_set_y(c("time", "status")) |>
154
+
br_set_x(colnames(lung)[6:10]) |>
155
+
br_set_x2(c("age", "sex")) |>
156
+
br_set_model("coxph") |>
157
+
br_run()
158
+
```
159
+
160
+
### Pipeline function
161
+
162
+
Given the develop experience in [ezcox](https://github.com/ShixiangWang/ezcox/),
163
+
we create a pipeline function for common one-step use.
164
+
165
+
```r
166
+
br_pipeline(
167
+
lung,
168
+
y= c("time", "status"),
169
+
x= colnames(lung)[6:10],
170
+
x2= c("age", "sex"),
171
+
method="coxph"
172
+
)
48
173
```
49
174
50
-
You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date. `devtools::build_readme()` is handy for this.
175
+
### Visualization
51
176
52
-
You can also embed plots, for example:
177
+
bregr mainly provides `br_show_forest()`for result data.
53
178
54
-
```{rpressure, echo = FALSE}
55
-
plot(pressure)
179
+
```{rfig.width=8, fig.height=6}
180
+
br_show_forest(mds)
56
181
```
57
182
58
-
In that case, don't forget to commit and push the resulting figure files, so they display on GitHub and CRAN.
0 commit comments