Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use styler #23

Merged
merged 1 commit into from
Feb 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

nsignC <- function(x) {
.Call(`_inferr_nsignC`, x)
.Call(`_inferr_nsignC`, x)
}

gvar <- function(ln, ly) {
.Call(`_inferr_gvar`, ln, ly)
.Call(`_inferr_gvar`, ln, ly)
}

34 changes: 16 additions & 18 deletions R/infer-anova.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,45 +36,43 @@
#' infer_oneway_anova(hsb, write, prog)
#' @export
#'
infer_oneway_anova <- function(data, x, y, ...) UseMethod('infer_oneway_anova')
infer_oneway_anova <- function(data, x, y, ...) UseMethod("infer_oneway_anova")

#' @export
infer_oneway_anova.default <- function(data, x, y, ...) {

x1 <- enquo(x)
y1 <- enquo(y)

fdata <-
data %>%
select(!! x1, !! y1)
data %>%
select(!! x1, !! y1)

sample_mean <- anova_avg(fdata, !! x1)
sample_stats <- anova_split(fdata, !! x1, !! y1, sample_mean)
k <- anova_calc(fdata, sample_stats, !! x1, !! y1)


result <- list(between = k$sstr, within = k$ssee, total = k$total,
df_btw = k$df_sstr, df_within = k$df_sse,
df_total = k$df_sst, ms_btw = k$mstr, ms_within = k$mse,
f = k$f, p = k$sig, r2 = round(k$reg$r.squared, 4),
ar2 = round(k$reg$adj.r.squared, 4),
sigma = round(k$reg$sigma, 4), obs = k$obs,
tab = sample_stats[, c(1, 2, 3, 5)])

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

class(result) <- "infer_oneway_anova"
return(result)
}

#' @export
#' @rdname infer_oneway_anova
#' @usage NULL
#'
owanova <- function(data, x, y, ...) {

.Deprecated("infer_oneway_anova()")
infer_oneway_anova(data, x, y, ...)

.Deprecated("infer_oneway_anova()")
infer_oneway_anova(data, x, y, ...)
}

#' @export
Expand Down
89 changes: 42 additions & 47 deletions R/infer-binom-test.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,45 +34,44 @@
#' infer_binom_test(hsb, female, prob = 0.5)
#' @export
#'
infer_binom_calc <- function(n, success, prob = 0.5, ...) UseMethod('infer_binom_calc')
infer_binom_calc <- function(n, success, prob = 0.5, ...) UseMethod("infer_binom_calc")

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

if (!is.numeric(n)) {
stop('n must be an integer')
}
if (!is.numeric(success)) {
stop("success must be an integer")
}

if (!is.numeric(success)) {
stop('success must be an integer')
}
if (!is.numeric(prob)) {
stop("prob must be numeric")
}

if(!is.numeric(prob)) {
stop('prob must be numeric')
}
if ((prob < 0) | (prob > 1)) {
stop("prob must be between 0 and 1")
}

if((prob < 0) | (prob > 1)) {
stop('prob must be between 0 and 1')
}
k <- binom_comp(n, success, prob)

k <- binom_comp(n, success, prob)
out <- list(
n = n, k = k$k, exp_k = k$exp_k, obs_p = k$obs_p,
exp_p = k$exp_p, lower = k$lower, upper = k$upper
)

out <- list(n = n, k = k$k, exp_k = k$exp_k, obs_p = k$obs_p,
exp_p = k$exp_p, lower = k$lower, upper = k$upper)

class(out) <- 'infer_binom_calc'
return(out)
class(out) <- "infer_binom_calc"
return(out)
}

#' @export
#' @rdname infer_binom_calc
#' @usage NULL
#'
binom_calc <- function(n, success, prob = 0.5, ...) {

.Deprecated("infer_binom_calc()")
infer_binom_calc(n, success, prob = 0.5, ...)

.Deprecated("infer_binom_calc()")
infer_binom_calc(n, success, prob = 0.5, ...)
}

#' @export
Expand All @@ -83,41 +82,37 @@ print.infer_binom_calc <- function(x, ...) {
#' @export
#' @rdname infer_binom_calc
infer_binom_test <- function(data, variable, prob = 0.5) {
varyable <- enquo(variable)

varyable <- enquo(variable)

fdata <-
data %>%
pull(!! varyable)
fdata <-
data %>%
pull(!! varyable)

if (!is.factor(fdata)) {
stop('variable must be of type factor', call. = FALSE)
}
if (!is.factor(fdata)) {
stop("variable must be of type factor", call. = FALSE)
}

if (nlevels(fdata) > 2) {
stop('Binomial test is applicable only to binary data i.e. categorical data with 2 levels.', call. = FALSE)
}
if (nlevels(fdata) > 2) {
stop("Binomial test is applicable only to binary data i.e. categorical data with 2 levels.", call. = FALSE)
}

if(!is.numeric(prob)) {
stop('prob must be numeric', call. = FALSE)
}
if (!is.numeric(prob)) {
stop("prob must be numeric", call. = FALSE)
}

if((prob < 0) | (prob > 1)) {
stop('prob must be between 0 and 1', call. = FALSE)
}
if ((prob < 0) | (prob > 1)) {
stop("prob must be between 0 and 1", call. = FALSE)
}

n <- length(fdata)
k <- table(fdata)[[2]]
infer_binom_calc.default(n, k, prob)
n <- length(fdata)
k <- table(fdata)[[2]]
infer_binom_calc.default(n, k, prob)
}

#' @export
#' @rdname infer_binom_calc
#' @usage NULL
#'
binom_test <- function(data, prob = 0.5) {

.Deprecated("infer_binom_test()")


.Deprecated("infer_binom_test()")
}
129 changes: 62 additions & 67 deletions R/infer-chisq-assoc-test.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,83 +37,78 @@
#' infer_chisq_assoc_test(hsb, female, ses)
#' @export
#'
infer_chisq_assoc_test <- function(data, x, y) UseMethod('infer_chisq_assoc_test')
infer_chisq_assoc_test <- function(data, x, y) UseMethod("infer_chisq_assoc_test")

#' @export
infer_chisq_assoc_test.default <- function(data, x, y) {

x1 <- enquo(x)
y1 <- enquo(y)

xone <-
data %>%
pull(!! x1)

yone <-
data %>%
pull(!! y1)

if (!is.factor(xone)) {
stop('x must be a categorical variable')
}

if (!is.factor(yone)) {
stop('y must be a categorical variable')
}

# dimensions
k <- table(xone, yone)
dk <- dim(k)
ds <- prod(dk)
nr <- dk[1]
nc <- dk[2]


if (ds == 4) {

twoway <- matrix(table(xone, yone), nrow = 2)
df <- df_chi(twoway)
ef <- efmat(twoway)
k <- pear_chsq(twoway, df, ef)
m <- lr_chsq(twoway, df, ef)
n <- yates_chsq(twoway)
p <- mh_chsq(twoway, n$total, n$prod_totals)

} else {

twoway <- matrix(table(xone, yone), nrow = dk[1])
ef <- efm(twoway, dk)
df <- df_chi(twoway)
k <- pear_chi(twoway, df, ef)
m <- lr_chsq2(twoway, df, ef, ds)

}

j <- chigf(xone, yone, k$chi)

result <- if (ds == 4) {
list(chi = k$chi, chilr = m$chilr, chimh = p$chimh, chiy = n$chi_y,
sig = k$sig, siglr = m$sig_lr, sigy = n$sig_y, sigmh = p$sig_mh,
phi = j$phi, cc = j$cc, cv = j$cv, ds = ds, df = df)
} else {
list(df = df, chi = k$chi, chilr = m$chilr, sig = k$sig, siglr = m$sig_lr,
phi = j$phi, cc = j$cc, cv = j$cv, ds = ds)
}

class(result) <- 'infer_chisq_assoc_test'
return(result)

x1 <- enquo(x)
y1 <- enquo(y)

xone <-
data %>%
pull(!! x1)

yone <-
data %>%
pull(!! y1)

if (!is.factor(xone)) {
stop("x must be a categorical variable")
}

if (!is.factor(yone)) {
stop("y must be a categorical variable")
}

# dimensions
k <- table(xone, yone)
dk <- dim(k)
ds <- prod(dk)
nr <- dk[1]
nc <- dk[2]


if (ds == 4) {
twoway <- matrix(table(xone, yone), nrow = 2)
df <- df_chi(twoway)
ef <- efmat(twoway)
k <- pear_chsq(twoway, df, ef)
m <- lr_chsq(twoway, df, ef)
n <- yates_chsq(twoway)
p <- mh_chsq(twoway, n$total, n$prod_totals)
} else {
twoway <- matrix(table(xone, yone), nrow = dk[1])
ef <- efm(twoway, dk)
df <- df_chi(twoway)
k <- pear_chi(twoway, df, ef)
m <- lr_chsq2(twoway, df, ef, ds)
}

j <- chigf(xone, yone, k$chi)

result <- if (ds == 4) {
list(
chi = k$chi, chilr = m$chilr, chimh = p$chimh, chiy = n$chi_y,
sig = k$sig, siglr = m$sig_lr, sigy = n$sig_y, sigmh = p$sig_mh,
phi = j$phi, cc = j$cc, cv = j$cv, ds = ds, df = df
)
} else {
list(
df = df, chi = k$chi, chilr = m$chilr, sig = k$sig, siglr = m$sig_lr,
phi = j$phi, cc = j$cc, cv = j$cv, ds = ds
)
}

class(result) <- "infer_chisq_assoc_test"
return(result)
}

#' @export
#' @rdname infer_chisq_assoc_test
#' @usage NULL
#'
chisq_test <- function(x, y) {

.Deprecated("infer_chisq_assoc_test()")


.Deprecated("infer_chisq_assoc_test()")
}

#' @export
Expand Down
Loading