@@ -57,7 +57,7 @@ t_test <- function(x, formula,
57
57
conf_int = TRUE ,
58
58
conf_level = 0.95 ,
59
59
... ) {
60
-
60
+
61
61
check_conf_level(conf_level )
62
62
63
63
# convert all character and logical variables to be factor variables
@@ -170,7 +170,7 @@ t_stat <- function(x, formula,
170
170
msg = c(" The t_stat() wrapper has been deprecated in favor of the more " ,
171
171
" general observe(). Please use that function instead." )
172
172
)
173
-
173
+
174
174
check_conf_level(conf_level )
175
175
176
176
# convert all character and logical variables to be factor variables
@@ -256,9 +256,9 @@ chisq_test <- function(x, formula, response = NULL,
256
256
# Parse response and explanatory variables
257
257
response <- enquo(response )
258
258
explanatory <- enquo(explanatory )
259
-
259
+
260
260
x <- standardize_variable_types(x )
261
-
261
+
262
262
x <- parse_variables(x = x , formula = formula ,
263
263
response = response , explanatory = explanatory )
264
264
@@ -290,7 +290,7 @@ chisq_test <- function(x, formula, response = NULL,
290
290
# '
291
291
# ' A shortcut wrapper function to get the observed test statistic for a chisq
292
292
# ' test. Uses [chisq.test()][stats::chisq.test()], which applies a continuity
293
- # ' correction. This function has been deprecated in favor of the more
293
+ # ' correction. This function has been deprecated in favor of the more
294
294
# ' general [observe()].
295
295
# '
296
296
# ' @param x A data frame that can be coerced into a [tibble][tibble::tibble].
@@ -327,15 +327,15 @@ chisq_stat <- function(x, formula, response = NULL,
327
327
explanatory = NULL , ... ) {
328
328
.Deprecated(
329
329
new = " observe" ,
330
- msg = c(" The chisq_stat() wrapper has been deprecated in favor of the " ,
330
+ msg = c(" The chisq_stat() wrapper has been deprecated in favor of the " ,
331
331
" more general observe(). Please use that function instead." )
332
332
)
333
-
333
+
334
334
# Parse response and explanatory variables
335
335
response <- enquo(response )
336
336
explanatory <- enquo(explanatory )
337
337
x <- standardize_variable_types(x )
338
-
338
+
339
339
x <- parse_variables(x = x , formula = formula ,
340
340
response = response , explanatory = explanatory )
341
341
@@ -364,7 +364,7 @@ chisq_stat <- function(x, formula, response = NULL,
364
364
365
365
check_conf_level <- function (conf_level ) {
366
366
if (
367
- (class (conf_level ) != " numeric" ) | (conf_level < 0 ) | (conf_level > 1 )
367
+ (! inherits (conf_level , " numeric" ) ) | (conf_level < 0 ) | (conf_level > 1 )
368
368
) {
369
369
stop_glue(" The `conf_level` argument must be a number between 0 and 1." )
370
370
}
@@ -409,8 +409,8 @@ check_conf_level <- function(conf_level) {
409
409
# ' a string. Only used when testing the null that a single
410
410
# ' proportion equals a given value, or that two proportions are equal;
411
411
# ' ignored otherwise.
412
- # ' @param correct A logical indicating whether Yates' continuity correction
413
- # ' should be applied where possible. If `z = TRUE`, the `correct` argument will
412
+ # ' @param correct A logical indicating whether Yates' continuity correction
413
+ # ' should be applied where possible. If `z = TRUE`, the `correct` argument will
414
414
# ' be overwritten as `FALSE`. Otherwise defaults to `correct = TRUE`.
415
415
# ' @param z A logical value for whether to report the statistic as a standard
416
416
# ' normal deviate or a Pearson's chi-square statistic. \eqn{z^2} is distributed
@@ -431,7 +431,7 @@ check_conf_level <- function(conf_level) {
431
431
# ' prop_test(gss,
432
432
# ' college ~ NULL,
433
433
# ' p = .2)
434
- # '
434
+ # '
435
435
# ' # report as a z-statistic rather than chi-square
436
436
# ' # and specify the success level of the response
437
437
# ' prop_test(gss,
@@ -458,10 +458,10 @@ prop_test <- function(x, formula,
458
458
response <- enquo(response )
459
459
explanatory <- enquo(explanatory )
460
460
x <- standardize_variable_types(x )
461
-
461
+
462
462
x <- parse_variables(x = x , formula = formula ,
463
463
response = response , explanatory = explanatory )
464
-
464
+
465
465
correct <- if (z ) {FALSE } else if (is.null(correct )) {TRUE } else {correct }
466
466
467
467
if (! (class(response_variable(x )) %in% c(" logical" , " character" , " factor" ))) {
@@ -535,7 +535,7 @@ prop_test <- function(x, formula,
535
535
p = p ,
536
536
correct = correct ,
537
537
... )
538
-
538
+
539
539
}
540
540
541
541
if (length(prelim $ estimate ) < = 2 ) {
@@ -563,7 +563,7 @@ prop_test <- function(x, formula,
563
563
chisq_df = parameter ,
564
564
p_value = p.value )
565
565
}
566
-
566
+
567
567
if (z ) {
568
568
results <- calculate_z(x , results , success , p , order )
569
569
}
@@ -573,9 +573,9 @@ prop_test <- function(x, formula,
573
573
574
574
calculate_z <- function (x , results , success , p , order ) {
575
575
exp <- if (has_explanatory(x )) {explanatory_name(x )} else {" NULL" }
576
-
576
+
577
577
form <- as.formula(paste0(response_name(x ), " ~ " , exp ))
578
-
578
+
579
579
stat <- x %> %
580
580
specify(formula = form , success = success ) %> %
581
581
hypothesize(
@@ -587,9 +587,9 @@ calculate_z <- function(x, results, success, p, order) {
587
587
order = if (has_explanatory(x )) {order } else {NULL }
588
588
) %> %
589
589
dplyr :: pull()
590
-
590
+
591
591
results $ statistic <- stat
592
592
results $ chisq_df <- NULL
593
-
593
+
594
594
results
595
595
}
0 commit comments