Skip to content

Commit

Permalink
Reverting to the state of the project at 84ae843
Browse files Browse the repository at this point in the history
  • Loading branch information
aravindhebbali committed Dec 14, 2018
1 parent c7fbafc commit 63c6514
Show file tree
Hide file tree
Showing 88 changed files with 1,218 additions and 1,076 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ BugReports: https://github.com/rsquaredacademy/blorr/issues
VignetteBuilder: knitr
Encoding: UTF-8
LazyData: true
RoxygenNote: 6.1.1
RoxygenNote: 6.0.1
LinkingTo: Rcpp
107 changes: 107 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,115 @@ export(blr_vif_tol)
export(blr_woe_iv)
export(blr_woe_iv_stats)
importFrom(Rcpp,sourceCpp)
importFrom(car,Anova)
importFrom(caret,confusionMatrix)
importFrom(checkmate,check_choice)
importFrom(checkmate,check_class)
importFrom(checkmate,check_data_frame)
importFrom(checkmate,check_logical)
importFrom(checkmate,check_number)
importFrom(checkmate,check_tibble)
importFrom(checkmate,check_true)
importFrom(cli,cat_line)
importFrom(dplyr,arrange)
importFrom(dplyr,bind_cols)
importFrom(dplyr,case_when)
importFrom(dplyr,desc)
importFrom(dplyr,filter)
importFrom(dplyr,full_join)
importFrom(dplyr,group_by)
importFrom(dplyr,if_else)
importFrom(dplyr,mutate)
importFrom(dplyr,n)
importFrom(dplyr,pull)
importFrom(dplyr,rename)
importFrom(dplyr,select)
importFrom(dplyr,slice)
importFrom(dplyr,summarise)
importFrom(dplyr,summarise_all)
importFrom(e1071,classAgreement)
importFrom(ggplot2,aes)
importFrom(ggplot2,annotate)
importFrom(ggplot2,element_blank)
importFrom(ggplot2,element_text)
importFrom(ggplot2,geom_col)
importFrom(ggplot2,geom_hline)
importFrom(ggplot2,geom_line)
importFrom(ggplot2,geom_linerange)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,geom_segment)
importFrom(ggplot2,geom_text)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,ggtitle)
importFrom(ggplot2,scale_x_continuous)
importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,sec_axis)
importFrom(ggplot2,theme)
importFrom(ggplot2,xlab)
importFrom(ggplot2,xlim)
importFrom(ggplot2,ylab)
importFrom(ggplot2,ylim)
importFrom(glue,glue)
importFrom(gridExtra,grid.arrange)
importFrom(gridExtra,marrangeGrob)
importFrom(magrittr,"%<>%")
importFrom(magrittr,"%>%")
importFrom(magrittr,add)
importFrom(magrittr,divide_by)
importFrom(magrittr,extract)
importFrom(magrittr,extract2)
importFrom(magrittr,is_greater_than)
importFrom(magrittr,multiply_by)
importFrom(magrittr,multiply_by_matrix)
importFrom(magrittr,raise_to_power)
importFrom(magrittr,set_colnames)
importFrom(magrittr,subtract)
importFrom(magrittr,use_series)
importFrom(purrr,map)
importFrom(purrr,map2_int)
importFrom(purrr,map_dbl)
importFrom(purrr,map_df)
importFrom(purrr,map_int)
importFrom(rlang,"!!!")
importFrom(rlang,"!!")
importFrom(rlang,enquo)
importFrom(rlang,eval_tidy)
importFrom(rlang,prepend)
importFrom(rlang,quo_name)
importFrom(rlang,quos)
importFrom(rlang,sym)
importFrom(shiny,isRunning)
importFrom(shiny,runApp)
importFrom(stats,AIC)
importFrom(stats,BIC)
importFrom(stats,as.formula)
importFrom(stats,binomial)
importFrom(stats,coef)
importFrom(stats,coefficients)
importFrom(stats,confint)
importFrom(stats,deviance)
importFrom(stats,df.residual)
importFrom(stats,dfbetas)
importFrom(stats,family)
importFrom(stats,formula)
importFrom(stats,glm)
importFrom(stats,hatvalues)
importFrom(stats,lm)
importFrom(stats,logLik)
importFrom(stats,model.frame)
importFrom(stats,model.matrix)
importFrom(stats,model.response)
importFrom(stats,pchisq)
importFrom(stats,predict.glm)
importFrom(stats,qt)
importFrom(stats,quantile)
importFrom(stats,residuals)
importFrom(stats,rstandard)
importFrom(stats,terms)
importFrom(tibble,add_column)
importFrom(tibble,add_row)
importFrom(tibble,as_data_frame)
importFrom(tibble,as_tibble)
importFrom(tibble,tibble)
importFrom(utils,data)
useDynLib(blorr, .registration = TRUE)
75 changes: 35 additions & 40 deletions R/blr-backward-elimination.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ blr_step_aic_backward.default <- function(model, details = FALSE, ...) {

response <-
model %>%
magrittr::use_series(model) %>%
use_series(model) %>%
names() %>%
magrittr::extract(1)
extract(1)

l <- mod_sel_data(model)
nam <- coeff_names(model)
preds <- nam
aic_f <- model_aic(model)

mi <- stats::glm(
mi <- glm(
paste(response, "~", paste(preds, collapse = " + ")),
data = l, family = stats::binomial(link = "logit")
data = l, family = binomial(link = "logit")
)

laic <- aic_f
Expand Down Expand Up @@ -106,17 +106,17 @@ blr_step_aic_backward.default <- function(model, details = FALSE, ...) {

for (i in seq_len(ilp)) {
predictors <- preds[-i]
m <- stats::glm(
m <- glm(
paste(response, "~", paste(predictors, collapse = " + ")),
data = l, family = stats::binomial(link = "logit")
data = l, family = binomial(link = "logit")
)
aics[i] <- model_aic(m)
bics[i] <- model_bic(m)
devs[i] <- model_deviance(m)
}

da <- data.frame(predictors = preds, aics = aics, bics = bics, devs = devs)
da2 <- dplyr::arrange(da, aics)
da2 <- arrange(da, aics)

if (details == TRUE) {
w1 <- max(nchar("Predictor"), nchar(predictors))
Expand Down Expand Up @@ -161,9 +161,9 @@ blr_step_aic_backward.default <- function(model, details = FALSE, ...) {
step <- step + 1
aic_f <- aics[minc]

mi <- stats::glm(
mi <- glm(
paste(response, "~", paste(preds, collapse = " + ")),
data = l, family = stats::binomial(link = "logit")
data = l, family = binomial(link = "logit")
)

laic <- c(laic, aic_f)
Expand All @@ -173,7 +173,7 @@ blr_step_aic_backward.default <- function(model, details = FALSE, ...) {
bics <- c()
devs <- c()

if (shiny::isRunning()) {
if (isRunning()) {
cat(paste("-", dplyr::last(rpred)), "\n")
} else if (interactive()) {
cat(crayon::red(clisymbols::symbol$cross), crayon::bold(dplyr::last(rpred)), "\n")
Expand All @@ -184,9 +184,9 @@ blr_step_aic_backward.default <- function(model, details = FALSE, ...) {

for (i in seq_len(ilp)) {
predictors <- preds[-i]
m <- stats::glm(
m <- glm(
paste(response, "~", paste(predictors, collapse = " + ")),
data = l, family = stats::binomial(link = "logit")
data = l, family = binomial(link = "logit")
)
aics[i] <- model_aic(m)
bics[i] <- model_bic(m)
Expand All @@ -202,7 +202,7 @@ blr_step_aic_backward.default <- function(model, details = FALSE, ...) {
predictors = preds, aics = aics, bics = bics,
devs = devs
)
da2 <- dplyr::arrange(da, aics)
da2 <- arrange(da, aics)
w1 <- max(nchar("Predictor"), nchar(predictors))
w2 <- 2
w3 <- max(nchar("AIC"), nchar(format(round(aics, 3), nsmall = 3)))
Expand Down Expand Up @@ -242,7 +242,7 @@ blr_step_aic_backward.default <- function(model, details = FALSE, ...) {
cat("\n\n")
cat("Variables Removed:", "\n\n")
for (i in seq_len(length(rpred))) {
if (shiny::isRunning()) {
if (isRunning()) {
cat(paste("-", rpred[i]), "\n")
} else if (interactive()) {
cat(crayon::red(clisymbols::symbol$cross), crayon::bold(rpred[i]), "\n")
Expand All @@ -262,8 +262,8 @@ blr_step_aic_backward.default <- function(model, details = FALSE, ...) {
print(fi)
}

final_model <- stats::glm(paste(response, "~", paste(preds, collapse = " + ")),
data = l, family = stats::binomial(link = 'logit'))
final_model <- glm(paste(response, "~", paste(preds, collapse = " + ")),
data = l, family = binomial(link = 'logit'))

out <- list(
candidates = nam,
Expand Down Expand Up @@ -304,54 +304,49 @@ plot.blr_step_aic_backward <- function(x, text_size = 3, ...) {

y <-
x %>%
magrittr::use_series(steps) %>%
use_series(steps) %>%
seq_len(.) %>%
purrr::prepend(0)
prepend(0)

xloc <- y - 0.1

yloc <-
x %>%
magrittr::use_series(aics) %>%
magrittr::subtract(0.2)
use_series(aics) %>%
subtract(0.2)

xmin <-
y %>%
min() %>%
magrittr::subtract(0.4)
subtract(0.4)

xmax <-
y %>%
max() %>%
magrittr::add(1)
add(1)

ymin <-
x %>%
magrittr::use_series(aics) %>%
use_series(aics) %>%
min() %>%
magrittr::add(1)
add(1)

ymax <-
x %>%
magrittr::use_series(aics) %>%
use_series(aics) %>%
max() %>%
magrittr::add(1)
add(1)

predictors <- c("Full Model", x$predictors)

d2 <- tibble::tibble(x = xloc, y = yloc, tx = predictors)
d <- tibble::tibble(a = y, b = x$aics)

p <-
ggplot2::ggplot(d, ggplot2::aes(x = a, y = b)) +
ggplot2::geom_line(color = "blue") +
ggplot2::geom_point(color = "blue", shape = 1, size = 2) +
ggplot2::xlim(c(xmin, xmax)) +
ggplot2::ylim(c(ymin, ymax)) +
ggplot2::xlab("Step") +
ggplot2::ylab("AIC") +
ggplot2::ggtitle("Stepwise AIC Backward Elimination") +
ggplot2::geom_text(data = d2, ggplot2::aes(x = x, y = y, label = tx),
d2 <- tibble(x = xloc, y = yloc, tx = predictors)
d <- tibble(a = y, b = x$aics)

p <- ggplot(d, aes(x = a, y = b)) + geom_line(color = "blue") +
geom_point(color = "blue", shape = 1, size = 2) + xlim(c(xmin, xmax)) +
ylim(c(ymin, ymax)) + xlab("Step") + ylab("AIC") +
ggtitle("Stepwise AIC Backward Elimination") +
geom_text(data = d2, aes(x = x, y = y, label = tx),
size = text_size, hjust = 0, nudge_x = 0.1)

print(p)
Expand All @@ -371,7 +366,7 @@ plot.blr_step_aic_backward <- function(x, text_size = 3, ...) {
coeff_names <- function(model) {

model %>%
magrittr::use_series(terms) %>%
use_series(terms) %>%
attr(which = "factors") %>%
colnames()

Expand Down
Loading

0 comments on commit 63c6514

Please sign in to comment.