Skip to content

Commit e54c4ae

Browse files
committed
update
1 parent 746e2d5 commit e54c4ae

19 files changed

+34
-136
lines changed

DESCRIPTION

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,11 @@ Imports:
2525
insight,
2626
lme4,
2727
magrittr,
28-
MASS,
29-
modelr,
3028
parameters,
3129
performance,
3230
purrr,
3331
sjlabelled,
3432
sjmisc,
35-
stats,
3633
tidyr
3734
Suggests:
3835
brms,
@@ -41,6 +38,7 @@ Suggests:
4138
coin,
4239
ggplot2,
4340
graphics,
41+
MASS,
4442
pscl,
4543
pwr,
4644
sjPlot,

NAMESPACE

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -125,75 +125,33 @@ export(weighted_se)
125125
export(weighted_ttest)
126126
export(wtd_sd)
127127
export(xtab_statistics)
128-
importFrom(MASS,glm.nb)
129128
importFrom(bayestestR,ci)
130129
importFrom(bayestestR,equivalence_test)
131130
importFrom(dplyr,case_when)
132131
importFrom(dplyr,filter)
133132
importFrom(dplyr,group_vars)
134-
importFrom(dplyr,mutate)
135133
importFrom(dplyr,quos)
136134
importFrom(dplyr,select)
137135
importFrom(dplyr,select_if)
138-
importFrom(dplyr,summarise)
139136
importFrom(insight,export_table)
140-
importFrom(insight,find_formula)
141-
importFrom(insight,find_response)
142137
importFrom(insight,format_p)
143138
importFrom(insight,format_value)
144-
importFrom(insight,get_data)
145139
importFrom(insight,get_response)
146140
importFrom(insight,link_inverse)
147141
importFrom(insight,print_color)
148142
importFrom(lme4,ngrps)
149143
importFrom(magrittr,"%>%")
150-
importFrom(modelr,crossv_kfold)
151144
importFrom(performance,mse)
152145
importFrom(performance,rmse)
153146
importFrom(purrr,flatten_df)
154147
importFrom(purrr,map)
155-
importFrom(purrr,map2)
156148
importFrom(purrr,map_dbl)
157149
importFrom(purrr,map_df)
158150
importFrom(purrr,map_lgl)
159151
importFrom(purrr,walk)
160152
importFrom(sjlabelled,as_numeric)
161153
importFrom(sjmisc,is_empty)
162154
importFrom(sjmisc,is_float)
163-
importFrom(sjmisc,is_num_fac)
164155
importFrom(sjmisc,str_contains)
165-
importFrom(sjmisc,trim)
166156
importFrom(sjmisc,typical_value)
167-
importFrom(stats,as.formula)
168-
importFrom(stats,chisq.test)
169-
importFrom(stats,coef)
170-
importFrom(stats,complete.cases)
171-
importFrom(stats,dpois)
172-
importFrom(stats,family)
173-
importFrom(stats,fitted)
174-
importFrom(stats,formula)
175-
importFrom(stats,kruskal.test)
176-
importFrom(stats,lm)
177-
importFrom(stats,model.frame)
178-
importFrom(stats,model.matrix)
179-
importFrom(stats,na.omit)
180-
importFrom(stats,na.pass)
181-
importFrom(stats,nobs)
182-
importFrom(stats,pf)
183-
importFrom(stats,pnorm)
184-
importFrom(stats,predict.glm)
185-
importFrom(stats,pt)
186-
importFrom(stats,qf)
187-
importFrom(stats,qnorm)
188-
importFrom(stats,resid)
189-
importFrom(stats,sd)
190-
importFrom(stats,setNames)
191-
importFrom(stats,terms)
192-
importFrom(stats,update)
193-
importFrom(stats,var)
194-
importFrom(stats,vcov)
195-
importFrom(stats,weighted.mean)
196-
importFrom(stats,weights)
197-
importFrom(stats,xtabs)
198157
importFrom(tidyr,nest)
199-
importFrom(tidyr,unnest)

R/S3-methods.R

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
#' @importFrom stats model.matrix
2-
#' @importFrom insight get_data
31
#' @export
42
model.matrix.gls <- function(object, ...) {
53
stats::model.matrix(object, data = insight::get_data(object))
64
}
75

86

9-
#' @importFrom stats coef vcov pnorm
107
#' @importFrom dplyr case_when
118
#' @export
129
print.svyglm.nb <- function(x, se = c("robust", "model"), digits = 4, ...) {
@@ -33,7 +30,6 @@ print.svyglm.nb <- function(x, se = c("robust", "model"), digits = 4, ...) {
3330

3431

3532

36-
#' @importFrom stats coef vcov pnorm
3733
#' @importFrom dplyr case_when
3834
#' @export
3935
print.svyglm.zip <- function(x, se = c("robust", "model"), digits = 4, ...) {
@@ -56,7 +52,6 @@ print.svyglm.zip <- function(x, se = c("robust", "model"), digits = 4, ...) {
5652

5753

5854

59-
#' @importFrom stats qnorm coef pnorm vcov
6055
tidy_svyglm.nb <- function(x, digits = 4, v_se = c("robust", "model")) {
6156
v_se <- match.arg(v_se)
6257

@@ -80,7 +75,6 @@ tidy_svyglm.nb <- function(x, digits = 4, v_se = c("robust", "model")) {
8075

8176

8277

83-
#' @importFrom stats qnorm coef pnorm vcov
8478
tidy_svyglm.zip <- function(x, digits = 4, v_se = c("robust", "model")) {
8579
v_se <- match.arg(v_se)
8680

@@ -142,16 +136,12 @@ formula.svyglm.zip <- function(x, ...) {
142136

143137

144138

145-
#' @importFrom MASS glm.nb
146-
#' @importFrom stats coef setNames predict.glm
147139
#' @export
148140
predict.svyglm.nb <- function(object, newdata = NULL,
149141
type = c("link", "response", "terms"),
150142
se.fit = FALSE, dispersion = NULL, terms = NULL,
151143
na.action = na.pass, ...) {
152-
153-
if (!isNamespaceLoaded("survey"))
154-
requireNamespace("survey", quietly = TRUE)
144+
insight::check_if_installed(c("survey", "MASS"))
155145

156146
fnb <- MASS::glm.nb(
157147
attr(object, "nb.formula", exact = TRUE),
@@ -178,9 +168,6 @@ predict.svyglm.nb <- function(object, newdata = NULL,
178168
}
179169

180170

181-
#' @importFrom MASS glm.nb
182-
#' @importFrom stats coef setNames predict.glm
183-
#' @importFrom insight get_response
184171
#' @export
185172
residuals.svyglm.nb <- function(object, ...) {
186173

@@ -201,7 +188,6 @@ residuals.svyglm.nb <- function(object, ...) {
201188
}
202189

203190

204-
#' @importFrom stats terms formula
205191
#' @export
206192
terms.svyglm.nb <- function(x, ...) {
207193

@@ -235,7 +221,6 @@ deviance.svyglm.nb <- function(object, ...) {
235221
}
236222

237223

238-
#' @importFrom insight print_color
239224
#' @export
240225
print.tidy_stan <- function(x, ...) {
241226
insight::print_color("\nSummary Statistics of Stan-Model\n\n", "blue")
@@ -261,8 +246,8 @@ print.tidy_stan <- function(x, ...) {
261246
}
262247

263248

264-
#' @importFrom sjmisc trim
265249
clean_term_name <- function(x) {
250+
insight::check_if_installed("sjmisc")
266251
x <- sjmisc::trim(x)
267252
format(x, width = max(nchar(x)))
268253
}
@@ -340,7 +325,6 @@ plot.sj_inequ_trend <- function(x, ...) {
340325
}
341326

342327

343-
#' @importFrom stats kruskal.test na.omit
344328
#' @export
345329
print.sj_mwu <- function(x, ...) {
346330
insight::print_color("\n# Mann-Whitney-U-Test\n\n", "blue")

R/boot_ci.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ boot_ci <- function(data, ..., method = c("dist", "quantile"), ci.lvl = 0.95) {
158158

159159

160160
#' @rdname boot_ci
161-
#' @importFrom stats sd
162161
#' @export
163162
boot_se <- function(data, ...) {
164163
# evaluate arguments, generate data
@@ -175,7 +174,6 @@ boot_se <- function(data, ...) {
175174

176175

177176
#' @rdname boot_ci
178-
#' @importFrom stats sd pt
179177
#' @export
180178
boot_p <- function(data, ...) {
181179
# evaluate arguments, generate data

R/confint_ncg.R

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Author: Ken Kelley
44
# License: GPL-3
55

6-
#' @importFrom stats pf qf
76
confint_ncg <- function(F.value = NULL, conf.level = 0.95, df.1 = NULL, df.2 = NULL) {
87
alpha.lower <- alpha.upper <- (1 - conf.level) / 2
98
tol <- 1e-09
@@ -40,12 +39,12 @@ confint_ncg <- function(F.value = NULL, conf.level = 0.95, df.1 = NULL, df.2 = N
4039
Diff.2 <- stats::pf(q = F.value, df1 = df.1, df2 = df.2, ncp = LL.Bounds[2]) - (1 - alpha.lower) > tol
4140
Diff.3 <- stats::pf(q = F.value, df1 = df.1, df2 = df.2, ncp = LL.Bounds[3]) - (1 - alpha.lower) > tol
4241

43-
if (isTRUE(Diff.1) & isTRUE(Diff.2) & !isTRUE(Diff.3)) {
42+
if (isTRUE(Diff.1) && isTRUE(Diff.2) && !isTRUE(Diff.3)) {
4443
LL.Bounds <-
4544
c(LL.Bounds[2], (LL.Bounds[2] + LL.Bounds[3]) / 2, LL.Bounds[3])
4645
}
4746

48-
if (isTRUE(Diff.1) & !isTRUE(Diff.2) & !isTRUE(Diff.3)) {
47+
if (isTRUE(Diff.1) && !isTRUE(Diff.2) && !isTRUE(Diff.3)) {
4948
LL.Bounds <-
5049
c(LL.Bounds[1], (LL.Bounds[1] + LL.Bounds[2]) / 2, LL.Bounds[2])
5150
}
@@ -89,14 +88,13 @@ confint_ncg <- function(F.value = NULL, conf.level = 0.95, df.1 = NULL, df.2 = N
8988
Diff.2 <- stats::pf(q = F.value, df1 = df.1, df2 = df.2, ncp = UL.Bounds[2]) - alpha.upper > tol
9089
Diff.3 <- stats::pf(q = F.value, df1 = df.1, df2 = df.2, ncp = UL.Bounds[3]) - alpha.upper > tol
9190

92-
if (isTRUE(Diff.1) & isTRUE(Diff.2) & !isTRUE(Diff.3)) {
91+
if (isTRUE(Diff.1) && isTRUE(Diff.2) && !isTRUE(Diff.3)) {
9392
UL.Bounds <-
9493
c(UL.Bounds[2], (UL.Bounds[2] + UL.Bounds[3]) / 2, UL.Bounds[3])
9594
}
9695

97-
if (isTRUE(Diff.1) & !isTRUE(Diff.2) & !isTRUE(Diff.3)) {
98-
UL.Bounds <- c(UL.Bounds[1], (UL.Bounds[1] +
99-
UL.Bounds[2])/2, UL.Bounds[2])
96+
if (isTRUE(Diff.1) && !isTRUE(Diff.2) && !isTRUE(Diff.3)) {
97+
UL.Bounds <- c(UL.Bounds[1], (UL.Bounds[1] + UL.Bounds[2]) / 2, UL.Bounds[2])
10098
}
10199

102100
Diff <- stats::pf(q = F.value, df1 = df.1, df2 = df.2, ncp = UL.Bounds[2]) - alpha.upper

R/cv.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#' fit <- lm(barthtot ~ c160age + c12hour, data = efc)
2121
#' cv(fit)
2222
#'
23-
#' @importFrom stats sd
2423
#' @export
2524
cv <- function(x, ...) {
2625
# return value

R/cv_error.R

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,40 +31,33 @@
3131
#' neg_c_7 ~ barthtot + c12hour
3232
#' ))
3333
#'
34-
#' @importFrom modelr crossv_kfold
35-
#' @importFrom dplyr mutate summarise
36-
#' @importFrom purrr map map2 map_dbl map_df
37-
#' @importFrom tidyr unnest
38-
#' @importFrom insight find_response
39-
#' @importFrom performance rmse
4034
#' @export
4135
cv_error <- function(data, formula, k = 5) {
42-
insight::check_if_installed("broom")
43-
44-
# compute cross validation data
45-
cv_data <- data %>%
46-
modelr::crossv_kfold(k = k) %>%
47-
dplyr::mutate(
48-
trained.models = purrr::map(.data$train, ~ stats::lm(formula, data = .x)),
49-
predicted = purrr::map2(.data$trained.models, .data$test, ~ broom::augment(.x, newdata = .y)),
50-
residuals = purrr::map(.data$predicted, ~.x[[insight::find_response(formula)]] - .x$.fitted),
51-
rmse.train = purrr::map_dbl(.data$trained.models, ~ performance::rmse(.x))
52-
)
36+
insight::check_if_installed("datawizard")
5337

38+
# response
39+
resp <- insight::find_response(formula)
5440

55-
# Training error
56-
train.error <- dplyr::summarise(cv_data, train.error = mean(.data$rmse.train, na.rm = TRUE))
41+
# compute cross validation data
42+
cv_data <- lapply(k, function(i) {
43+
datawizard::data_partition(data, proportion = 0.8)
44+
})
45+
# get train and test datasets
46+
train_data <- lapply(cv_data, function(cvdat) cvdat[[1]])
47+
test_data <- lapply(cv_data, function(cvdat) cvdat[[2]])
5748

49+
# fit models on datasets
50+
trained_models <- lapply(train_data, function(x) stats::lm(formula, data = x))
51+
test_models <- lapply(test_data, function(x) stats::lm(formula, data = x))
5852

59-
# Test error
60-
test.error <- cv_data %>%
61-
tidyr::unnest(.data$predicted, .data$residuals) %>%
62-
dplyr::summarise(test.error = sqrt(mean(.data$residuals^2, na.rm = TRUE)))
53+
# RMSE
54+
train_error <- mean(vapply(trained_models, performance::rmse, numeric(1)), na.rm = TRUE)
55+
test_error <- mean(vapply(test_models, performance::rmse, numeric(1)), na.rm = TRUE)
6356

6457
data_frame(
6558
model = deparse(formula),
66-
train.error = round(train.error[[1]], 4),
67-
test.error = round(test.error[[1]], 4)
59+
train.error = round(train_error, 4),
60+
test.error = round(test_error, 4)
6861
)
6962
}
7063

@@ -73,5 +66,5 @@ cv_error <- function(data, formula, k = 5) {
7366
#' @rdname cv_error
7467
#' @export
7568
cv_compare <- function(data, formulas, k = 5) {
76-
purrr::map_df(formulas, ~ cv_error(data, formula = .x, k = k))
69+
do.call(rbind, lapply(formulas, function(f) cv_error(data, formula = f, k = k)))
7770
}

R/gmd.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ gmd <- function(x, ...) {
3939
}
4040

4141

42-
#' @importFrom stats na.omit
4342
gmd_helper <- function(x) {
4443
if (!is.numeric(x)) return(NA)
4544

R/gof.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
#' # equal to population
4949
#' chisq_gof(efc$e42dep, prop.table(table(efc$e42dep)))
5050
#'
51-
#' @importFrom stats na.omit fitted resid formula as.formula lm pnorm chisq.test
5251
#' @export
5352
chisq_gof <- function(x, prob = NULL, weights = NULL) {
5453
if (inherits(x, "glm")) {

R/helpfunctions.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ dot_names <- function(dots) unname(unlist(lapply(dots, as.character)))
4545

4646
#' @importFrom tidyr nest
4747
#' @importFrom dplyr select filter group_vars
48-
#' @importFrom stats complete.cases
4948
get_grouped_data <- function(x) {
5049
# retain observations that are complete wrt grouping vars, then nest
5150
grps <- x %>%
@@ -64,7 +63,7 @@ get_grouped_data <- function(x) {
6463

6564

6665
.compact_character <- function(x) {
67-
x[!sapply(x, function(i) is.null(i) || nchar(i) == 0 || is.na(i) || any(i == "NULL", na.rm = TRUE))]
66+
x[!sapply(x, function(i) is.null(i) || !nzchar(i, keepNA = TRUE) || is.na(i) || any(i == "NULL", na.rm = TRUE))]
6867
}
6968

7069

R/phi.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ phi.formula <- function(formula, data, ci.lvl = NULL, n = 1000, method = c("dist
4444

4545

4646
.phi <- function(tab) {
47+
insight::check_if_installed("MASS")
4748
# convert to flat table
4849
if (!inherits(tab, "ftable")) tab <- stats::ftable(tab)
4950

R/se_ybar.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#' se_ybar(fit)
1919
#' }
2020
#' @importFrom lme4 ngrps
21-
#' @importFrom stats nobs
2221
#' @importFrom purrr map_dbl
2322
#' @export
2423
se_ybar <- function(fit) {

R/svy_median.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
#' @rdname weighted_sd
2-
#' @importFrom stats as.formula
32
#' @export
43
survey_median <- function(x, design) {
54
# check if pkg survey is available
6-
if (!requireNamespace("survey", quietly = TRUE)) {
7-
stop("Package `survey` needed to for this function to work. Please install it.", call. = FALSE)
8-
}
5+
insight::check_if_installed("suvey")
96

107
# deparse
118
v <- stats::as.formula(paste("~", as.character(substitute(x))))

0 commit comments

Comments
 (0)