Skip to content

Commit d8995e8

Browse files
Merge pull request #23 from rsquaredacademy/develop
use styler
2 parents 626d878 + baa732e commit d8995e8

37 files changed

+2742
-2741
lines changed

R/RcppExports.R

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
33

44
nsignC <- function(x) {
5-
.Call(`_inferr_nsignC`, x)
5+
.Call(`_inferr_nsignC`, x)
66
}
77

88
gvar <- function(ln, ly) {
9-
.Call(`_inferr_gvar`, ln, ly)
9+
.Call(`_inferr_gvar`, ln, ly)
1010
}
11-

R/infer-anova.R

+16-18
Original file line numberDiff line numberDiff line change
@@ -36,45 +36,43 @@
3636
#' infer_oneway_anova(hsb, write, prog)
3737
#' @export
3838
#'
39-
infer_oneway_anova <- function(data, x, y, ...) UseMethod('infer_oneway_anova')
39+
infer_oneway_anova <- function(data, x, y, ...) UseMethod("infer_oneway_anova")
4040

4141
#' @export
4242
infer_oneway_anova.default <- function(data, x, y, ...) {
43-
4443
x1 <- enquo(x)
4544
y1 <- enquo(y)
4645

4746
fdata <-
48-
data %>%
49-
select(!! x1, !! y1)
47+
data %>%
48+
select(!! x1, !! y1)
5049

5150
sample_mean <- anova_avg(fdata, !! x1)
5251
sample_stats <- anova_split(fdata, !! x1, !! y1, sample_mean)
5352
k <- anova_calc(fdata, sample_stats, !! x1, !! y1)
5453

5554

56-
result <- list(between = k$sstr, within = k$ssee, total = k$total,
57-
df_btw = k$df_sstr, df_within = k$df_sse,
58-
df_total = k$df_sst, ms_btw = k$mstr, ms_within = k$mse,
59-
f = k$f, p = k$sig, r2 = round(k$reg$r.squared, 4),
60-
ar2 = round(k$reg$adj.r.squared, 4),
61-
sigma = round(k$reg$sigma, 4), obs = k$obs,
62-
tab = sample_stats[, c(1, 2, 3, 5)])
63-
64-
class(result) <- 'infer_oneway_anova'
65-
return(result)
55+
result <- list(
56+
between = k$sstr, within = k$ssee, total = k$total,
57+
df_btw = k$df_sstr, df_within = k$df_sse,
58+
df_total = k$df_sst, ms_btw = k$mstr, ms_within = k$mse,
59+
f = k$f, p = k$sig, r2 = round(k$reg$r.squared, 4),
60+
ar2 = round(k$reg$adj.r.squared, 4),
61+
sigma = round(k$reg$sigma, 4), obs = k$obs,
62+
tab = sample_stats[, c(1, 2, 3, 5)]
63+
)
6664

65+
class(result) <- "infer_oneway_anova"
66+
return(result)
6767
}
6868

6969
#' @export
7070
#' @rdname infer_oneway_anova
7171
#' @usage NULL
7272
#'
7373
owanova <- function(data, x, y, ...) {
74-
75-
.Deprecated("infer_oneway_anova()")
76-
infer_oneway_anova(data, x, y, ...)
77-
74+
.Deprecated("infer_oneway_anova()")
75+
infer_oneway_anova(data, x, y, ...)
7876
}
7977

8078
#' @export

R/infer-binom-test.R

+42-47
Original file line numberDiff line numberDiff line change
@@ -34,45 +34,44 @@
3434
#' infer_binom_test(hsb, female, prob = 0.5)
3535
#' @export
3636
#'
37-
infer_binom_calc <- function(n, success, prob = 0.5, ...) UseMethod('infer_binom_calc')
37+
infer_binom_calc <- function(n, success, prob = 0.5, ...) UseMethod("infer_binom_calc")
3838

3939
#' @export
4040
infer_binom_calc.default <- function(n, success, prob = 0.5, ...) {
41+
if (!is.numeric(n)) {
42+
stop("n must be an integer")
43+
}
4144

42-
if (!is.numeric(n)) {
43-
stop('n must be an integer')
44-
}
45+
if (!is.numeric(success)) {
46+
stop("success must be an integer")
47+
}
4548

46-
if (!is.numeric(success)) {
47-
stop('success must be an integer')
48-
}
49+
if (!is.numeric(prob)) {
50+
stop("prob must be numeric")
51+
}
4952

50-
if(!is.numeric(prob)) {
51-
stop('prob must be numeric')
52-
}
53+
if ((prob < 0) | (prob > 1)) {
54+
stop("prob must be between 0 and 1")
55+
}
5356

54-
if((prob < 0) | (prob > 1)) {
55-
stop('prob must be between 0 and 1')
56-
}
57+
k <- binom_comp(n, success, prob)
5758

58-
k <- binom_comp(n, success, prob)
59+
out <- list(
60+
n = n, k = k$k, exp_k = k$exp_k, obs_p = k$obs_p,
61+
exp_p = k$exp_p, lower = k$lower, upper = k$upper
62+
)
5963

60-
out <- list(n = n, k = k$k, exp_k = k$exp_k, obs_p = k$obs_p,
61-
exp_p = k$exp_p, lower = k$lower, upper = k$upper)
62-
63-
class(out) <- 'infer_binom_calc'
64-
return(out)
64+
class(out) <- "infer_binom_calc"
65+
return(out)
6566
}
6667

6768
#' @export
6869
#' @rdname infer_binom_calc
6970
#' @usage NULL
7071
#'
7172
binom_calc <- function(n, success, prob = 0.5, ...) {
72-
73-
.Deprecated("infer_binom_calc()")
74-
infer_binom_calc(n, success, prob = 0.5, ...)
75-
73+
.Deprecated("infer_binom_calc()")
74+
infer_binom_calc(n, success, prob = 0.5, ...)
7675
}
7776

7877
#' @export
@@ -83,41 +82,37 @@ print.infer_binom_calc <- function(x, ...) {
8382
#' @export
8483
#' @rdname infer_binom_calc
8584
infer_binom_test <- function(data, variable, prob = 0.5) {
85+
varyable <- enquo(variable)
8686

87-
varyable <- enquo(variable)
88-
89-
fdata <-
90-
data %>%
91-
pull(!! varyable)
87+
fdata <-
88+
data %>%
89+
pull(!! varyable)
9290

93-
if (!is.factor(fdata)) {
94-
stop('variable must be of type factor', call. = FALSE)
95-
}
91+
if (!is.factor(fdata)) {
92+
stop("variable must be of type factor", call. = FALSE)
93+
}
9694

97-
if (nlevels(fdata) > 2) {
98-
stop('Binomial test is applicable only to binary data i.e. categorical data with 2 levels.', call. = FALSE)
99-
}
95+
if (nlevels(fdata) > 2) {
96+
stop("Binomial test is applicable only to binary data i.e. categorical data with 2 levels.", call. = FALSE)
97+
}
10098

101-
if(!is.numeric(prob)) {
102-
stop('prob must be numeric', call. = FALSE)
103-
}
99+
if (!is.numeric(prob)) {
100+
stop("prob must be numeric", call. = FALSE)
101+
}
104102

105-
if((prob < 0) | (prob > 1)) {
106-
stop('prob must be between 0 and 1', call. = FALSE)
107-
}
103+
if ((prob < 0) | (prob > 1)) {
104+
stop("prob must be between 0 and 1", call. = FALSE)
105+
}
108106

109-
n <- length(fdata)
110-
k <- table(fdata)[[2]]
111-
infer_binom_calc.default(n, k, prob)
107+
n <- length(fdata)
108+
k <- table(fdata)[[2]]
109+
infer_binom_calc.default(n, k, prob)
112110
}
113111

114112
#' @export
115113
#' @rdname infer_binom_calc
116114
#' @usage NULL
117115
#'
118116
binom_test <- function(data, prob = 0.5) {
119-
120-
.Deprecated("infer_binom_test()")
121-
122-
117+
.Deprecated("infer_binom_test()")
123118
}

R/infer-chisq-assoc-test.R

+62-67
Original file line numberDiff line numberDiff line change
@@ -37,83 +37,78 @@
3737
#' infer_chisq_assoc_test(hsb, female, ses)
3838
#' @export
3939
#'
40-
infer_chisq_assoc_test <- function(data, x, y) UseMethod('infer_chisq_assoc_test')
40+
infer_chisq_assoc_test <- function(data, x, y) UseMethod("infer_chisq_assoc_test")
4141

4242
#' @export
4343
infer_chisq_assoc_test.default <- function(data, x, y) {
44-
45-
x1 <- enquo(x)
46-
y1 <- enquo(y)
47-
48-
xone <-
49-
data %>%
50-
pull(!! x1)
51-
52-
yone <-
53-
data %>%
54-
pull(!! y1)
55-
56-
if (!is.factor(xone)) {
57-
stop('x must be a categorical variable')
58-
}
59-
60-
if (!is.factor(yone)) {
61-
stop('y must be a categorical variable')
62-
}
63-
64-
# dimensions
65-
k <- table(xone, yone)
66-
dk <- dim(k)
67-
ds <- prod(dk)
68-
nr <- dk[1]
69-
nc <- dk[2]
70-
71-
72-
if (ds == 4) {
73-
74-
twoway <- matrix(table(xone, yone), nrow = 2)
75-
df <- df_chi(twoway)
76-
ef <- efmat(twoway)
77-
k <- pear_chsq(twoway, df, ef)
78-
m <- lr_chsq(twoway, df, ef)
79-
n <- yates_chsq(twoway)
80-
p <- mh_chsq(twoway, n$total, n$prod_totals)
81-
82-
} else {
83-
84-
twoway <- matrix(table(xone, yone), nrow = dk[1])
85-
ef <- efm(twoway, dk)
86-
df <- df_chi(twoway)
87-
k <- pear_chi(twoway, df, ef)
88-
m <- lr_chsq2(twoway, df, ef, ds)
89-
90-
}
91-
92-
j <- chigf(xone, yone, k$chi)
93-
94-
result <- if (ds == 4) {
95-
list(chi = k$chi, chilr = m$chilr, chimh = p$chimh, chiy = n$chi_y,
96-
sig = k$sig, siglr = m$sig_lr, sigy = n$sig_y, sigmh = p$sig_mh,
97-
phi = j$phi, cc = j$cc, cv = j$cv, ds = ds, df = df)
98-
} else {
99-
list(df = df, chi = k$chi, chilr = m$chilr, sig = k$sig, siglr = m$sig_lr,
100-
phi = j$phi, cc = j$cc, cv = j$cv, ds = ds)
101-
}
102-
103-
class(result) <- 'infer_chisq_assoc_test'
104-
return(result)
105-
44+
x1 <- enquo(x)
45+
y1 <- enquo(y)
46+
47+
xone <-
48+
data %>%
49+
pull(!! x1)
50+
51+
yone <-
52+
data %>%
53+
pull(!! y1)
54+
55+
if (!is.factor(xone)) {
56+
stop("x must be a categorical variable")
57+
}
58+
59+
if (!is.factor(yone)) {
60+
stop("y must be a categorical variable")
61+
}
62+
63+
# dimensions
64+
k <- table(xone, yone)
65+
dk <- dim(k)
66+
ds <- prod(dk)
67+
nr <- dk[1]
68+
nc <- dk[2]
69+
70+
71+
if (ds == 4) {
72+
twoway <- matrix(table(xone, yone), nrow = 2)
73+
df <- df_chi(twoway)
74+
ef <- efmat(twoway)
75+
k <- pear_chsq(twoway, df, ef)
76+
m <- lr_chsq(twoway, df, ef)
77+
n <- yates_chsq(twoway)
78+
p <- mh_chsq(twoway, n$total, n$prod_totals)
79+
} else {
80+
twoway <- matrix(table(xone, yone), nrow = dk[1])
81+
ef <- efm(twoway, dk)
82+
df <- df_chi(twoway)
83+
k <- pear_chi(twoway, df, ef)
84+
m <- lr_chsq2(twoway, df, ef, ds)
85+
}
86+
87+
j <- chigf(xone, yone, k$chi)
88+
89+
result <- if (ds == 4) {
90+
list(
91+
chi = k$chi, chilr = m$chilr, chimh = p$chimh, chiy = n$chi_y,
92+
sig = k$sig, siglr = m$sig_lr, sigy = n$sig_y, sigmh = p$sig_mh,
93+
phi = j$phi, cc = j$cc, cv = j$cv, ds = ds, df = df
94+
)
95+
} else {
96+
list(
97+
df = df, chi = k$chi, chilr = m$chilr, sig = k$sig, siglr = m$sig_lr,
98+
phi = j$phi, cc = j$cc, cv = j$cv, ds = ds
99+
)
100+
}
101+
102+
class(result) <- "infer_chisq_assoc_test"
103+
return(result)
106104
}
107105

108106
#' @export
109107
#' @rdname infer_chisq_assoc_test
110108
#' @usage NULL
111109
#'
112110
chisq_test <- function(x, y) {
113-
114-
.Deprecated("infer_chisq_assoc_test()")
115-
116-
111+
.Deprecated("infer_chisq_assoc_test()")
117112
}
118113

119114
#' @export

0 commit comments

Comments
 (0)