The following fictitious example of a prospective cohort study will be used to validate the correct estimation of the BSW package in R.

Exposed | Non-Exposed | |
---|---|---|

Cases | 200 | 50 |

Non-Cases | 50 | 200 |

```
library(testthat)
library(BSW)
: Matrix
Lade nötiges Paket: matrixStats
Lade nötiges Paket: quadprog
Lade nötiges Paket<- data.frame(y = rep(c(0, 1), each = 250),
df x = rep(c(0, 1, 0, 1), times = c(200, 50, 50, 200))
)<- (200 * 250) / (50 * 250)
RR <- sqrt((1/200 + 1/50) - (1/250 + 1/250))
SE <- bsw(y ~ x, df)
fit <- summary(fit)
out :
Callbsw(formula = y ~ x, data = df)
: TRUE
Convergence:
CoefficientsPr(>|z|) RR 2.5% 97.5%
Estimate Std. Error z value -1.609438 0.1264911 -12.72372 4.365487e-37 0.2 0.1560848 0.256271
(Intercept) 1.386294 0.1303840 10.63239 2.106386e-26 4.0 3.0979677 5.164676
x
: 37 Iterations
```

The relative risk for exposed individuals compared to non-exposed individuals can be calculated from

```
test_that(desc = "Estimated relative risk is equal to 4",
code = {
expect_equal(object = unname(exp(coef(fit)[2])),
expected = RR)
}
) Test passed 🥇
```

The standard error of the natural logarithm of the relative risk can be calculated from

```
test_that(desc = "Estimated standard error is equal to 0.1303840",
code = {
expect_equal(object = unname(out$std.err[2]),
expected = SE)
}
) Test passed 🌈
```

The z-value can be calculated from

```
test_that(desc = "Estimated z-value is equal to 10.63239",
code = {
expect_equal(object = unname(out$z.value[2]),
expected = log(RR) / SE)
}
) Test passed 😀
```

The 95% confidence interval limits can be calculated from

```
test_that(desc = "Estimated 95% confidence interval limits are equal to 3.097968 and 5.164676",
code = {
expect_equal(object = unname(exp(confint(fit)[2,])),
expected = exp(log(RR) + SE * qnorm(c(0.025, 0.975))))
}
) Test passed 😀
```