11# Get started with \` bayesian\`
22
33``` r
4+
45library(bayesian )
56```
67
78``` r
9+
810library(recipes )
911library(workflows )
1012```
@@ -21,6 +23,7 @@ prepare (a recipe for) the `epilepsy` data. This data set is shipped
2123with the ` brms ` package, which is automatically loaded by ` bayesian ` .
2224
2325``` r
26+
2427epi_recipe <- epilepsy | >
2528 recipe() | >
2629 update_role(count , new_role = " outcome" ) | >
@@ -30,6 +33,7 @@ epi_recipe <- epilepsy |>
3033```
3134
3235``` r
36+
3337print(epi_recipe )
3438```
3539
@@ -60,6 +64,7 @@ later on. In the next step, we use `bayesian` to set up a basic model
6064structure.
6165
6266``` r
67+
6368epi_model <- bayesian(
6469 family = poisson()
6570 ) | >
@@ -68,6 +73,7 @@ epi_model <- bayesian(
6873```
6974
7075``` r
76+
7177print(epi_model )
7278```
7379
@@ -86,6 +92,7 @@ or set it to something else that we now wanted to change, we could use
8692the ` update ` method as follows
8793
8894``` r
95+
8996epi_model <- epi_model | >
9097 update(family = poisson())
9198```
@@ -95,6 +102,7 @@ above defined data processing recipe and the model plus the actual model
95102formula to be passed to the ` brms ` engine.
96103
97104``` r
105+
98106epi_workflow <- workflow() | >
99107 add_recipe(epi_recipe ) | >
100108 add_model(
@@ -104,6 +112,7 @@ epi_workflow <- workflow() |>
104112```
105113
106114``` r
115+
107116print(epi_workflow )
108117```
109118
@@ -128,6 +137,7 @@ We are now ready to fit the model by calling the `fit` method with the
128137data set we want to train the model on.
129138
130139``` r
140+
131141epi_workflow_fit <- epi_workflow | >
132142 fit(data = epilepsy )
133143```
@@ -137,6 +147,7 @@ epi_workflow_fit <- epi_workflow |>
137147 ## Start sampling
138148
139149``` r
150+
140151print(epi_workflow_fit )
141152```
142153
@@ -176,18 +187,21 @@ print(epi_workflow_fit)
176187To extract the parsnip model fit from the workflow
177188
178189``` r
190+
179191epi_fit <- epi_workflow_fit | >
180192 extract_fit_parsnip()
181193```
182194
183195The ` brmsfit ` object can be extracted as follows
184196
185197``` r
198+
186199epi_brmsfit <- epi_workflow_fit | >
187200 extract_fit_engine()
188201```
189202
190203``` r
204+
191205class(epi_brmsfit )
192206```
193207
@@ -199,10 +213,12 @@ the data reprocessing, which is automatically applied using the workflow
199213preprocessor (recipe).
200214
201215``` r
216+
202217newdata <- epilepsy [1 : 5 , ]
203218```
204219
205220``` r
221+
206222epi_workflow_fit | >
207223 predict(
208224 new_data = newdata ,
@@ -223,6 +239,7 @@ epi_workflow_fit |>
223239To add the standard errors on the scale of the linear predictors
224240
225241``` r
242+
226243epi_workflow_fit | >
227244 predict(
228245 new_data = newdata ,
0 commit comments