Skip to content

Commit

Permalink
styler
Browse files Browse the repository at this point in the history
  • Loading branch information
DominiqueMakowski committed Nov 19, 2019
1 parent 0f7558d commit e5e4ab5
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 43 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Expand Up @@ -22,7 +22,7 @@ Imports:
stats,
insight (>= 0.7.0),
bayestestR (>= 0.4.0),
parameters (>= 0.2.1),
parameters (>= 0.2.0),
effectsize (>= 0.0.1)
Suggests:
BayesFactor,
Expand Down
64 changes: 31 additions & 33 deletions R/cor_test_distance.R
@@ -1,26 +1,29 @@
#' @keywords internal
.cor_test_distance <- function(data, x, y, ci = 0.95, corrected = TRUE, ...) {

var_x <- .complete_variable_x(data, x, y)
var_y <- .complete_variable_y(data, x, y)

if(corrected == FALSE){
if (corrected == FALSE) {
rez <- .cor_test_distance_raw(var_x, var_y, index = 1)
rez <- data.frame(Parameter1 = x,
Parameter2 = y,
r = rez$dCor,
Method = "Distance Correlation")
} else{
rez <- data.frame(
Parameter1 = x,
Parameter2 = y,
r = rez$dCor,
Method = "Distance Correlation"
)
} else {
rez <- .cor_test_distance_corrected(var_x, var_y, ci = ci)
rez <- data.frame(Parameter1 = x,
Parameter2 = y,
r = rez$r,
t = rez$t,
df = rez$df,
p = rez$p,
CI_low = rez$CI_low,
CI_high = rez$CI_high,
Method = "Distance Correlation (Bias Corrected)")
rez <- data.frame(
Parameter1 = x,
Parameter2 = y,
r = rez$r,
t = rez$t,
df = rez$df,
p = rez$p,
CI_low = rez$CI_low,
CI_high = rez$CI_high,
Method = "Distance Correlation (Bias Corrected)"
)
}
}

Expand Down Expand Up @@ -54,20 +57,21 @@

ci_vals <- cor_to_ci(r, n = n, ci = ci)

list(r = r,
t = t,
df = dof,
p = p,
CI_low = ci_vals$CI_low,
CI_high = ci_vals$CI_high)
list(
r = r,
t = t,
df = dof,
p = p,
CI_low = ci_vals$CI_low,
CI_high = ci_vals$CI_high
)
}




#' @keywords internal
.cor_test_distance_raw <- function(x, y, index = 1) {

if (index < 0 || index > 2) {
stop("`index` must be between 0 and 2.")
index <- 1.0
Expand Down Expand Up @@ -125,15 +129,9 @@
M <- mean(d)
a <- sweep(d, 1, m)
b <- sweep(a, 2, m)
A <- b + M #same as plain A
#correction to get A^*
A <- A - d/n
A <- b + M # same as plain A
# correction to get A^*
A <- A - d / n
diag(A) <- m - M
(n / (n-1)) * A
(n / (n - 1)) * A
}






2 changes: 1 addition & 1 deletion R/cor_test_freq.R
Expand Up @@ -17,4 +17,4 @@
}

params
}
}
2 changes: 1 addition & 1 deletion R/cor_test_polychoric.R
Expand Up @@ -48,4 +48,4 @@
Method = method,
stringsAsFactors = FALSE
)
}
}
1 change: 0 additions & 1 deletion R/cor_to_ci.R
Expand Up @@ -2,7 +2,6 @@
#' @importFrom stats qnorm
#' @export
cor_to_ci <- function(cor, n, ci = 0.95, method = "pearson") {

z <- atanh(cor)
se <- 1 / sqrt(n - 3) # Sample standard error

Expand Down
1 change: 0 additions & 1 deletion R/cor_to_p.R
Expand Up @@ -19,7 +19,6 @@
#'
#' cor.test(iris$Sepal.Length, iris$Sepal.Width, method = "kendall")
#' cor_to_p(-0.07699679, n = 150, method = "kendall")
#'
#' @importFrom stats mad median qnorm cov2cor pnorm pt
#' @export
cor_to_p <- function(cor, n, method = "pearson") {
Expand Down
2 changes: 1 addition & 1 deletion R/print.easycormatrix.R
Expand Up @@ -21,7 +21,7 @@ print.easycormatrix <- function(x, digits = 2, stars = TRUE, ...) {
if (stars) {
x[, nums] <- paste0(as.matrix(as.data.frame(x)[, nums]), as.matrix(p[, nums]))
}
} else{
} else {
x[, nums] <- sapply(as.data.frame(x)[, nums], insight::format_value, digits = digits)
}

Expand Down
5 changes: 2 additions & 3 deletions R/z_fisher.R
Expand Up @@ -12,10 +12,9 @@
#' @export
z_fisher <- function(r = NULL, z = NULL) {
# TODO: add variants for Spearman and Kendall (Zar, 2014)
if(is.null(z)){
if (is.null(z)) {
return(atanh(r))
} else{
} else {
return(tanh(z))
}
}

2 changes: 1 addition & 1 deletion tests/testthat/test-cor_test.R
Expand Up @@ -36,4 +36,4 @@ test_that("cor_test distance", {
out <- cor_test(iris, "Petal.Length", "Petal.Width", method = "distance")
comparison <- energy::dcor.ttest(iris$Petal.Length, iris$Petal.Width)
testthat::expect_equal(out$r, as.numeric(comparison$estimate), tol = 0.01)
})
})

0 comments on commit e5e4ab5

Please sign in to comment.