Skip to content

Commit

Permalink
Fixes and Validation #133
Browse files Browse the repository at this point in the history
  • Loading branch information
dbosak01 committed Dec 18, 2023
1 parent ce2e716 commit 7f89c29
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 11 deletions.
Binary file modified Procs_Validation.docx
Binary file not shown.
29 changes: 25 additions & 4 deletions R/proc_ttest.R
Original file line number Diff line number Diff line change
Expand Up @@ -855,16 +855,37 @@ get_class_ttest <- function(data, var, class, report = TRUE, opts = NULL,
v1 <- lst[[1]][[var]]
v2 <- lst[[2]][[var]]

# # SAS appears to be putting the shorter vector as the experiment
# if (length(v2) < length(v1)) {
# v1 <- lst[[2]][[var]]
# v2 <- lst[[1]][[var]]
#
# }

alph <- 1 - get_alpha(opts)

ttret <- TTEST(v1, v2, alph)
ttret1 <- TTEST(v1, v2, alph)
ttret2 <- TTEST(v2, v1, alph)

st <- as.data.frame(ttret$`Statistics by group`,
ft1 <- as.data.frame(unclass(ttret1$`F-test for the ratio of variances`),
stringsAsFactors = FALSE)
tt <- as.data.frame(unclass(ttret$`Two groups t-test for the difference of means`),
ft2 <- as.data.frame(unclass(ttret2$`F-test for the ratio of variances`),
stringsAsFactors = FALSE)

# SAS appears to be taking the one with the greatest F Value
if (ft1$`F value` > ft2$`F value`) {
ft <- ft1
} else {

ft <- ft2
}

st <- as.data.frame(ttret1$`Statistics by group`,
stringsAsFactors = FALSE)
ft <- as.data.frame(unclass(ttret$`F-test for the ratio of variances`),
tt <- as.data.frame(unclass(ttret1$`Two groups t-test for the difference of means`),
stringsAsFactors = FALSE)
# ft <- as.data.frame(unclass(ttret$`F-test for the ratio of variances`),
# stringsAsFactors = FALSE)

vcls <- c("Diff (1-2)")
empt <- c(NA, NA)
Expand Down
2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ articles:
procs-means: procs-means.html
procs-ttest: procs-ttest.html
procs: procs.html
last_built: 2023-12-17T02:32Z
last_built: 2023-12-18T15:54Z
urls:
reference: https://procs.r-sassy.org/reference
article: https://procs.r-sassy.org/articles
Expand Down
63 changes: 57 additions & 6 deletions tests/testthat/test-ttest.R
Original file line number Diff line number Diff line change
Expand Up @@ -463,14 +463,12 @@ test_that("ttest14: Simple proc_ttest with class and by works.", {
# var height;
# run;

tmpdat <- cls
tmpdat$cat <- c("A", "A", "A", "A", "A", "A", "A", "A", "A",
"B", "B", "B", "B", "B", "B", "B", "B", "B", "B")

res <- proc_ttest(tmpdat,
by = "cat",
res <- proc_ttest(cls,
by = "region",
var = "Height",
class = "Sex")
class = "Sex",
options = c(alpha = 0.1))

res

Expand Down Expand Up @@ -1111,3 +1109,56 @@ test_that("ttest26: Internal consistency checks with paired", {
expect_equal(res1$out$TTests$PROBT[3], res3$TTests$VALUES[9])

})

test_that("ttest27: Check F Values for different var and class combinations.", {

# SAS appears to pick the different variables for test or control
# depending on what is going on in the data. Best guess is that it is
# picking the combination with highest F Value. This is to run a few
# comparisons against SAS and just make sure everything is coming out OK.

# proc ttest data=sashelp.class alpha=0.05;
# class sex /* Grouping Variable */;
# var height;
# run;


res1 <- proc_ttest(cls,
by = "region",
var = "Height",
class = "Sex",
options = c(alpha = 0.1))

res1

expect_equal(as.numeric(res1$Equality$NDF), c(3, 3))
expect_equal(as.numeric(res1$Equality$DDF), c(4, 5))
expect_equal(as.numeric(res1$Equality$FVAL), c(2.04584557, 1.70834286))



res2 <- proc_ttest(cls,
by = "region",
var = "Weight",
class = "Sex",
options = c(alpha = 0.1))

res2

expect_equal(as.numeric(res2$Equality$NDF), c(3, 3))
expect_equal(as.numeric(res2$Equality$DDF), c(4, 5))
expect_equal(as.numeric(res2$Equality$FVAL), c(1.4055752, 1.1721952))

res3 <- proc_ttest(cls,
by = "region",
var = "Age",
class = "Sex",
options = c(alpha = 0.1))

res3

expect_equal(as.numeric(res3$Equality$NDF), c(4, 5))
expect_equal(as.numeric(res3$Equality$DDF), c(3, 3))
expect_equal(as.numeric(res3$Equality$FVAL), c(1.41818182, 1.290000))

})

0 comments on commit 7f89c29

Please sign in to comment.