@@ -66,18 +66,18 @@ blr_step_aic_backward.default <- function(model, details = FALSE, ...) {
6666
6767 response <-
6868 model %> %
69- magrittr :: use_series(model ) %> %
69+ use_series(model ) %> %
7070 names() %> %
71- magrittr :: extract(1 )
71+ extract(1 )
7272
7373 l <- mod_sel_data(model )
7474 nam <- coeff_names(model )
7575 preds <- nam
7676 aic_f <- model_aic(model )
7777
78- mi <- stats :: glm(
78+ mi <- glm(
7979 paste(response , " ~" , paste(preds , collapse = " + " )),
80- data = l , family = stats :: binomial(link = " logit" )
80+ data = l , family = binomial(link = " logit" )
8181 )
8282
8383 laic <- aic_f
@@ -106,17 +106,17 @@ blr_step_aic_backward.default <- function(model, details = FALSE, ...) {
106106
107107 for (i in seq_len(ilp )) {
108108 predictors <- preds [- i ]
109- m <- stats :: glm(
109+ m <- glm(
110110 paste(response , " ~" , paste(predictors , collapse = " + " )),
111- data = l , family = stats :: binomial(link = " logit" )
111+ data = l , family = binomial(link = " logit" )
112112 )
113113 aics [i ] <- model_aic(m )
114114 bics [i ] <- model_bic(m )
115115 devs [i ] <- model_deviance(m )
116116 }
117117
118118 da <- data.frame (predictors = preds , aics = aics , bics = bics , devs = devs )
119- da2 <- dplyr :: arrange(da , aics )
119+ da2 <- arrange(da , aics )
120120
121121 if (details == TRUE ) {
122122 w1 <- max(nchar(" Predictor" ), nchar(predictors ))
@@ -161,9 +161,9 @@ blr_step_aic_backward.default <- function(model, details = FALSE, ...) {
161161 step <- step + 1
162162 aic_f <- aics [minc ]
163163
164- mi <- stats :: glm(
164+ mi <- glm(
165165 paste(response , " ~" , paste(preds , collapse = " + " )),
166- data = l , family = stats :: binomial(link = " logit" )
166+ data = l , family = binomial(link = " logit" )
167167 )
168168
169169 laic <- c(laic , aic_f )
@@ -173,7 +173,7 @@ blr_step_aic_backward.default <- function(model, details = FALSE, ...) {
173173 bics <- c()
174174 devs <- c()
175175
176- if (shiny :: isRunning()) {
176+ if (isRunning()) {
177177 cat(paste(" -" , dplyr :: last(rpred )), " \n " )
178178 } else if (interactive()) {
179179 cat(crayon :: red(clisymbols :: symbol $ cross ), crayon :: bold(dplyr :: last(rpred )), " \n " )
@@ -184,9 +184,9 @@ blr_step_aic_backward.default <- function(model, details = FALSE, ...) {
184184
185185 for (i in seq_len(ilp )) {
186186 predictors <- preds [- i ]
187- m <- stats :: glm(
187+ m <- glm(
188188 paste(response , " ~" , paste(predictors , collapse = " + " )),
189- data = l , family = stats :: binomial(link = " logit" )
189+ data = l , family = binomial(link = " logit" )
190190 )
191191 aics [i ] <- model_aic(m )
192192 bics [i ] <- model_bic(m )
@@ -202,7 +202,7 @@ blr_step_aic_backward.default <- function(model, details = FALSE, ...) {
202202 predictors = preds , aics = aics , bics = bics ,
203203 devs = devs
204204 )
205- da2 <- dplyr :: arrange(da , aics )
205+ da2 <- arrange(da , aics )
206206 w1 <- max(nchar(" Predictor" ), nchar(predictors ))
207207 w2 <- 2
208208 w3 <- max(nchar(" AIC" ), nchar(format(round(aics , 3 ), nsmall = 3 )))
@@ -242,7 +242,7 @@ blr_step_aic_backward.default <- function(model, details = FALSE, ...) {
242242 cat(" \n\n " )
243243 cat(" Variables Removed:" , " \n\n " )
244244 for (i in seq_len(length(rpred ))) {
245- if (shiny :: isRunning()) {
245+ if (isRunning()) {
246246 cat(paste(" -" , rpred [i ]), " \n " )
247247 } else if (interactive()) {
248248 cat(crayon :: red(clisymbols :: symbol $ cross ), crayon :: bold(rpred [i ]), " \n " )
@@ -262,8 +262,8 @@ blr_step_aic_backward.default <- function(model, details = FALSE, ...) {
262262 print(fi )
263263 }
264264
265- final_model <- stats :: glm(paste(response , " ~" , paste(preds , collapse = " + " )),
266- data = l , family = stats :: binomial(link = ' logit' ))
265+ final_model <- glm(paste(response , " ~" , paste(preds , collapse = " + " )),
266+ data = l , family = binomial(link = ' logit' ))
267267
268268 out <- list (
269269 candidates = nam ,
@@ -304,54 +304,49 @@ plot.blr_step_aic_backward <- function(x, text_size = 3, ...) {
304304
305305 y <-
306306 x %> %
307- magrittr :: use_series(steps ) %> %
307+ use_series(steps ) %> %
308308 seq_len(. ) %> %
309- purrr :: prepend(0 )
309+ prepend(0 )
310310
311311 xloc <- y - 0.1
312312
313313 yloc <-
314314 x %> %
315- magrittr :: use_series(aics ) %> %
316- magrittr :: subtract(0.2 )
315+ use_series(aics ) %> %
316+ subtract(0.2 )
317317
318318 xmin <-
319319 y %> %
320320 min() %> %
321- magrittr :: subtract(0.4 )
321+ subtract(0.4 )
322322
323323 xmax <-
324324 y %> %
325325 max() %> %
326- magrittr :: add(1 )
326+ add(1 )
327327
328328 ymin <-
329329 x %> %
330- magrittr :: use_series(aics ) %> %
330+ use_series(aics ) %> %
331331 min() %> %
332- magrittr :: add(1 )
332+ add(1 )
333333
334334 ymax <-
335335 x %> %
336- magrittr :: use_series(aics ) %> %
336+ use_series(aics ) %> %
337337 max() %> %
338- magrittr :: add(1 )
338+ add(1 )
339339
340340 predictors <- c(" Full Model" , x $ predictors )
341341
342- d2 <- tibble :: tibble(x = xloc , y = yloc , tx = predictors )
343- d <- tibble :: tibble(a = y , b = x $ aics )
344-
345- p <-
346- ggplot2 :: ggplot(d , ggplot2 :: aes(x = a , y = b )) +
347- ggplot2 :: geom_line(color = " blue" ) +
348- ggplot2 :: geom_point(color = " blue" , shape = 1 , size = 2 ) +
349- ggplot2 :: xlim(c(xmin , xmax )) +
350- ggplot2 :: ylim(c(ymin , ymax )) +
351- ggplot2 :: xlab(" Step" ) +
352- ggplot2 :: ylab(" AIC" ) +
353- ggplot2 :: ggtitle(" Stepwise AIC Backward Elimination" ) +
354- ggplot2 :: geom_text(data = d2 , ggplot2 :: aes(x = x , y = y , label = tx ),
342+ d2 <- tibble(x = xloc , y = yloc , tx = predictors )
343+ d <- tibble(a = y , b = x $ aics )
344+
345+ p <- ggplot(d , aes(x = a , y = b )) + geom_line(color = " blue" ) +
346+ geom_point(color = " blue" , shape = 1 , size = 2 ) + xlim(c(xmin , xmax )) +
347+ ylim(c(ymin , ymax )) + xlab(" Step" ) + ylab(" AIC" ) +
348+ ggtitle(" Stepwise AIC Backward Elimination" ) +
349+ geom_text(data = d2 , aes(x = x , y = y , label = tx ),
355350 size = text_size , hjust = 0 , nudge_x = 0.1 )
356351
357352 print(p )
@@ -371,7 +366,7 @@ plot.blr_step_aic_backward <- function(x, text_size = 3, ...) {
371366coeff_names <- function (model ) {
372367
373368 model %> %
374- magrittr :: use_series(terms ) %> %
369+ use_series(terms ) %> %
375370 attr(which = " factors" ) %> %
376371 colnames()
377372
0 commit comments