Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Happ committed Apr 20, 2018
0 parents commit dea196d
Show file tree
Hide file tree
Showing 15 changed files with 762 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
^.*\.Rproj$
^\.Rproj\.user$
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
SampleWMW.Rproj
23 changes: 23 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Package: WMWssp
Type: Package
Title: Wilcoxon-Mann-Whitney Sample Size Planning
Version: 0.3.2
Date: 2018-02-16
Authors@R: c(
person("Arne C. Bathke", role = "aut"),
person("Edgar Brunner", role = "aut"),
person("Martin Happ", role = c("aut", "cre"), email = "[email protected]"),
person("Frank Konietschke", role = "aut")
)
Author: Arne C. Bathke [aut], Edgar Brunner [aut], Martin Happ [aut, cre], Frank Konietschke [aut]
Maintainer: Martin Happ <[email protected]>
Description: Calculates the minimal sample size for the Wilcoxon-Mann-Whitney test
that is needed for a given power and two sided type I error rate. The method works for metric data with and without
ties, count data, ordered categorical data, and even dichotomous data.
But data is needed for the reference group to generate synthetic data for the treatment group based on a relevant effect.
For details, see Brunner, E., Bathke A. C. and Konietschke, F: Rank- and Pseudo-Rank Procedures in Factorial Designs - Using R and SAS, Springer Verlag, to appear.
Imports: rankFD
Depends: R (>= 3.4.0)
License: GPL-3
LazyData: TRUE
RoxygenNote: 6.0.1
5 changes: 5 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export(WMWssp, WMWssp_minimize, WMWssp_noether, WMWssp_maximize)
importFrom("stats", "qnorm", "optimize", "pnorm")
importFrom("rankFD", "rank.two.samples")
S3method(print, WMWssp)
S3method(summary, WMWssp)
66 changes: 66 additions & 0 deletions R/S3methods.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
####################################################################################################################################
### Filename: S3methods.R
### Description: S3 methods for class 'WMWssp' returned from functions from file samplesize.R
###
###
###
###
####################################################################################################################################

print.WMWssp <- function(x, ...){

cat("Wilcoxon-Mann-Whitney Sample Size Calculation\n \n")
cat("Total sample size needed: ")
cat(x$N, paste("(n_1 = ", ceiling(x$N*x$t), ", n_2 = ", ceiling(x$N*(1-x$t)), ")", sep = ""))
cat("\n")

if(as.character(x$call) %in% c("WMWssp_minimize", "WMWssp_maximize") ) {
cat("Optimal allocation rate to the first group: ")
cat(x$t)
cat("\n")
} else {
cat("Allocation rate to the first group: ")
cat(x$t)
cat("\n")
}

if(x$simulation >= 0){
cat("Simulated Power: ")
cat(x$simulation)
cat("\n")
}

if(as.character(x$call) %in% c("WMWssp_maximize")){
cat("Maximal Power: ")
cat(x$power)
cat("\n")
}

cat("\nUse 'summary' for more details.")

}


summary.WMWssp <- function(object, ...){
cat("Wilcoxon-Mann-Whitney Sample Size Calculation\n \n")
cat("Summary\n")
cat("Call: ")
cat(as.character(object$call))
cat("\n")
cat("Type-I error (two-sided): ")
cat(object$alpha)
cat("\n")
if(as.character(object$call) != "WMWssp_maximize"){
cat("Power: ")
cat(object$power)
cat("\n")
}
if(as.character(object$call) == "WMWssp_maximize"){
cat("Sample size: ")
cat(object$N)
cat("\n")
}
cat("\n")

print(object$result)
}
11 changes: 11 additions & 0 deletions R/example_maximize.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Prior information for the reference group
x <- c(315,375,356,374,412,418,445,403,431,410,391,475,379)
# generate data for treatment group based on a shift effect
y <- x - 20

#
N <- 112

# calculate optimal t
ssp <- WMWssp_maximize(x, y, alpha = 0.05, N)
summary(ssp)
8 changes: 8 additions & 0 deletions R/example_minimize.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Prior information for the reference group
x <- c(315,375,356,374,412,418,445,403,431,410,391,475,379)
# generate data for treatment group based on a shift effect
y <- x - 20

# calculate optimal t
ssp <- WMWssp_minimize(x, y, alpha = 0.05, power = 0.8)
summary(ssp)
9 changes: 9 additions & 0 deletions R/example_noether.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Prior information for the reference group
x <- c(315,375,356,374,412,418,445,403,431,410,391,475,379)
# generate data for treatment group based on a shift effect
y <- x - 20
# this data leads to a relative effect of p = 0.349

# calculate sampe size for a balanced design
ssp <- WMWssp_noether(alpha = 0.05, power = 0.8, t =1/2, p = 0.349)
summary(ssp)
8 changes: 8 additions & 0 deletions R/example_ssp.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Prior information for the reference group
x <- c(315,375,356,374,412,418,445,403,431,410,391,475,379)
# generate data for treatment group based on a shift effect
y <- x - 20

# calculate sample size
ssp <- WMWssp(x, y, alpha = 0.05, power = 0.8, t = 1/2)
summary(ssp)
Loading

0 comments on commit dea196d

Please sign in to comment.