Skip to content

Commit 63c6514

Browse files
Reverting to the state of the project at 84ae843
1 parent c7fbafc commit 63c6514

File tree

88 files changed

+1218
-1076
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1218
-1076
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ BugReports: https://github.com/rsquaredacademy/blorr/issues
5555
VignetteBuilder: knitr
5656
Encoding: UTF-8
5757
LazyData: true
58-
RoxygenNote: 6.1.1
58+
RoxygenNote: 6.0.1
5959
LinkingTo: Rcpp

NAMESPACE

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,115 @@ export(blr_vif_tol)
118118
export(blr_woe_iv)
119119
export(blr_woe_iv_stats)
120120
importFrom(Rcpp,sourceCpp)
121+
importFrom(car,Anova)
122+
importFrom(caret,confusionMatrix)
123+
importFrom(checkmate,check_choice)
124+
importFrom(checkmate,check_class)
125+
importFrom(checkmate,check_data_frame)
126+
importFrom(checkmate,check_logical)
127+
importFrom(checkmate,check_number)
128+
importFrom(checkmate,check_tibble)
129+
importFrom(checkmate,check_true)
130+
importFrom(cli,cat_line)
131+
importFrom(dplyr,arrange)
132+
importFrom(dplyr,bind_cols)
133+
importFrom(dplyr,case_when)
134+
importFrom(dplyr,desc)
135+
importFrom(dplyr,filter)
136+
importFrom(dplyr,full_join)
137+
importFrom(dplyr,group_by)
138+
importFrom(dplyr,if_else)
139+
importFrom(dplyr,mutate)
140+
importFrom(dplyr,n)
141+
importFrom(dplyr,pull)
142+
importFrom(dplyr,rename)
143+
importFrom(dplyr,select)
144+
importFrom(dplyr,slice)
145+
importFrom(dplyr,summarise)
146+
importFrom(dplyr,summarise_all)
147+
importFrom(e1071,classAgreement)
148+
importFrom(ggplot2,aes)
149+
importFrom(ggplot2,annotate)
150+
importFrom(ggplot2,element_blank)
151+
importFrom(ggplot2,element_text)
152+
importFrom(ggplot2,geom_col)
153+
importFrom(ggplot2,geom_hline)
154+
importFrom(ggplot2,geom_line)
155+
importFrom(ggplot2,geom_linerange)
156+
importFrom(ggplot2,geom_point)
157+
importFrom(ggplot2,geom_segment)
158+
importFrom(ggplot2,geom_text)
159+
importFrom(ggplot2,ggplot)
160+
importFrom(ggplot2,ggtitle)
161+
importFrom(ggplot2,scale_x_continuous)
162+
importFrom(ggplot2,scale_y_continuous)
163+
importFrom(ggplot2,sec_axis)
164+
importFrom(ggplot2,theme)
165+
importFrom(ggplot2,xlab)
166+
importFrom(ggplot2,xlim)
167+
importFrom(ggplot2,ylab)
168+
importFrom(ggplot2,ylim)
169+
importFrom(glue,glue)
170+
importFrom(gridExtra,grid.arrange)
171+
importFrom(gridExtra,marrangeGrob)
121172
importFrom(magrittr,"%<>%")
122173
importFrom(magrittr,"%>%")
174+
importFrom(magrittr,add)
175+
importFrom(magrittr,divide_by)
176+
importFrom(magrittr,extract)
177+
importFrom(magrittr,extract2)
178+
importFrom(magrittr,is_greater_than)
179+
importFrom(magrittr,multiply_by)
180+
importFrom(magrittr,multiply_by_matrix)
181+
importFrom(magrittr,raise_to_power)
182+
importFrom(magrittr,set_colnames)
183+
importFrom(magrittr,subtract)
184+
importFrom(magrittr,use_series)
185+
importFrom(purrr,map)
186+
importFrom(purrr,map2_int)
187+
importFrom(purrr,map_dbl)
188+
importFrom(purrr,map_df)
189+
importFrom(purrr,map_int)
123190
importFrom(rlang,"!!!")
124191
importFrom(rlang,"!!")
192+
importFrom(rlang,enquo)
193+
importFrom(rlang,eval_tidy)
194+
importFrom(rlang,prepend)
195+
importFrom(rlang,quo_name)
196+
importFrom(rlang,quos)
197+
importFrom(rlang,sym)
198+
importFrom(shiny,isRunning)
199+
importFrom(shiny,runApp)
200+
importFrom(stats,AIC)
201+
importFrom(stats,BIC)
202+
importFrom(stats,as.formula)
203+
importFrom(stats,binomial)
204+
importFrom(stats,coef)
205+
importFrom(stats,coefficients)
206+
importFrom(stats,confint)
207+
importFrom(stats,deviance)
208+
importFrom(stats,df.residual)
209+
importFrom(stats,dfbetas)
210+
importFrom(stats,family)
211+
importFrom(stats,formula)
212+
importFrom(stats,glm)
213+
importFrom(stats,hatvalues)
214+
importFrom(stats,lm)
215+
importFrom(stats,logLik)
216+
importFrom(stats,model.frame)
217+
importFrom(stats,model.matrix)
218+
importFrom(stats,model.response)
219+
importFrom(stats,pchisq)
220+
importFrom(stats,predict.glm)
221+
importFrom(stats,qt)
222+
importFrom(stats,quantile)
223+
importFrom(stats,residuals)
224+
importFrom(stats,rstandard)
225+
importFrom(stats,terms)
226+
importFrom(tibble,add_column)
227+
importFrom(tibble,add_row)
228+
importFrom(tibble,as_data_frame)
229+
importFrom(tibble,as_tibble)
230+
importFrom(tibble,tibble)
231+
importFrom(utils,data)
125232
useDynLib(blorr, .registration = TRUE)

R/blr-backward-elimination.R

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -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, ...) {
371366
coeff_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

Comments
 (0)