1 ```#' Binomial logistic regression multivariable models with bootstrapped ``` 2 ```#' confidence intervals: \code{finalfit} model wrapper ``` 3 ```#' ``` 4 ```#' Using \code{finalfit} conventions, produces a multivariable binomial logistic ``` 5 ```#' regression models for a set of explanatory variables against a binary ``` 6 ```#' dependent. ``` 7 ```#' ``` 8 ```#' Uses \code{\link[stats]{glm}} with \code{finalfit} modelling conventions. ``` 9 ```#' \code{boot::\link[boot]{boot}} is used to draw bootstrapped confidence ``` 10 ```#' intervals on fixed effect model coefficients. Output can be passed to ``` 11 ```#' \code{\link{fit2df}}. ``` 12 ```#' ``` 13 ```#' @param .data Dataframe. ``` 14 ```#' @param dependent Character vector length 1: name of depdendent variable ``` 15 ```#' (must have 2 levels). ``` 16 ```#' @param explanatory Character vector of any length: name(s) of explanatory ``` 17 ```#' variables. ``` 18 ```#' @param R Number of draws. ``` 19 ```#' @return A multivariable \code{\link[stats]{glm}} fitted model with ``` 20 ```#' bootstrapped confidence intervals. Output is of class \code{glmboot}. ``` 21 ```#' ``` 22 ```#' @seealso \code{\link{fit2df}, \link{finalfit_merge}} ``` 23 ```#' @family finalfit model wrappers ``` 24 ```#' @export ``` 25 ```#' ``` 26 ```#' @examples ``` 27 ```#' library(finalfit) ``` 28 ```#' library(dplyr) ``` 29 ```#' ## Note number of draws set to 100 just for speed in this example ``` 30 ```#' explanatory = c("age.factor", "sex.factor", "obstruct.factor", "perfor.factor") ``` 31 ```#' dependent = "mort_5yr" ``` 32 ```#' ``` 33 ```#' colon_s %>% ``` 34 ```#' glmmulti_boot(dependent, explanatory, R=100) %>% ``` 35 ```#' fit2df(estimate_suffix="(multivariable (BS CIs))") ``` 36 ```#' ``` 37 38 ```glmmulti_boot <- function(.data, dependent, explanatory, R=1000){ ``` 39 1 ``` formula <- paste(dependent, "~", paste(explanatory, collapse="+")) ``` 40 ``` # function to get coefficients ``` 41 1 ``` ci <- function(formula, data, indices) { ``` 42 1 ``` d <- data[indices,] ``` 43 1 ``` fit <- glm(formula, family="binomial", data=d) ``` 44 1 ``` return(fit\$coefficients) ``` 45 ``` } ``` 46 1 ``` bs.out <- boot::boot(data=.data, statistic=ci, ``` 47 1 ``` R=R, formula=formula) ``` 48 1 ``` class(bs.out) = "glmboot" ``` 49 1 ``` return(bs.out) ``` 50 ```} ```

Read our documentation on viewing source code .