Skip to content

Commit

Permalink
nonparametric extension
Browse files Browse the repository at this point in the history
  • Loading branch information
happma committed Apr 20, 2018
1 parent 5f69d93 commit 56f220c
Show file tree
Hide file tree
Showing 38 changed files with 7,407 additions and 245 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: HRM
Version: 0.8.0
Date: 2018-02-01
Version: 0.9.0
Date: 2018-02-14
Title: High-Dimensional Repeated Measures
Authors@R: c(person("Martin Happ", role = c("aut", "cre"),
email = "[email protected]"),
Expand All @@ -10,7 +10,7 @@ Author: Martin Happ [aut, cre], Harrar W. Solomon [aut], Arne C. Bathke [aut]
Maintainer: Martin Happ <[email protected]>
LazyData: true
Depends: R (>= 3.4.0), MASS, matrixcalc, plyr, ggplot2
Imports: xtable, reshape2, tcltk
Imports: xtable, reshape2, tcltk, data.table, pracma
Suggests: RGtk2 (>= 2.8.0), cairoDevice, RGtk2Extras
Description: Methods for testing main and interaction effects in possibly
high-dimensional repeated measures in factorial designs. The observations
Expand Down
6,401 changes: 6,401 additions & 0 deletions EEG.csv

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export(hrm.test, hrm.GUI)
export(hrm_test, hrm.GUI, hrm_GUI, hrm.test.matrix, hrm.test.dataframe)
import(matrixcalc)
import(MASS)
import(plyr)
Expand All @@ -10,8 +10,10 @@ importFrom("utils", "read.table", "write.table")
importFrom("xtable", "xtable")
importFrom("grDevices", "dev.new")
importFrom("tcltk", "tkchooseDirectory","tkgetOpenFile" , "tclvalue")
importFrom("data.table", "setDT", "rbindlist", "setnames", "as.data.table")
importFrom("pracma", "Lcm")
S3method(print,HRM)
S3method(summary,HRM)
S3method(plot,HRM)
S3method(hrm.test, list)
S3method(hrm.test, data.frame)
S3method(hrm_test, list)
S3method(hrm_test, data.frame)
8 changes: 3 additions & 5 deletions R/GUI.R
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ gui.results <- function(result, factors, dec, sep) {
#' @description Graphical User Interface (R Package RGtk2 needed) for the Function 'hrm_test': Test for main effects and interaction effects of one or two between-subject factors and one, two or three within-subject factors (at most four factors can be used).
#' @return The results can be saved as LaTeX Code or as plain text. Additionally a plot of the group profiles an be saved when using one whole- and one subplot factor.
#' @keywords export
hrm.GUI <- function(){
hrm_GUI <- function(){

# variable to temporarily store the loaded data from the user
tmp <- NULL
Expand Down Expand Up @@ -579,7 +579,8 @@ hrm.GUI <- function(){
if(alpha > 0 & alpha < 1) {
# if the input by the user is fine, then do the caluclation
tryCatch({
object.hrm <- hrm.test(formula = formula, data = tmp, alpha = alpha, subject = subject )

object.hrm <- hrm_test(formula = formula, data = tmp, alpha = alpha, subject = subject )
result <- object.hrm$result

# determin which columns are whole- and subplot factors
Expand Down Expand Up @@ -615,12 +616,9 @@ hrm.GUI <- function(){
tryCatch(responseVariable <- as.character(terms.formula(formula)[[2]]), warning = function(w) "", error = function(e) "" )
if(is.character(responseVariable)){
print("Profiles are being plotted ...")
#dev.new() # first graphics device is within RStudio
#dev.new() # show plot using new graphics device (i.e. separate window for plot); easer than drawing with cairoDevice
GUI_plot()
tryCatch({
print(plot.HRM(object.hrm))
#print(hrm.plot(data = tmp, group = groupFactor, factor1 = timeFactor, subject = subject, response = responseVariable, xlab = "dimension", ylab = "means"))
}, error = function(e) "", warning = function(w) "")
}
} else if(nfactors == 1 & !is.null(timeFactor) & errorOccured == 0) {
Expand Down
42 changes: 25 additions & 17 deletions R/S3methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
#' Test for Multi-Factor High-Dimensional Repeated Measures
#'
#' @description Performing main and interaction effects of up to three whole- or subplot-factors. In total, a maximum of four factors can be used. There are two different S3 methods available. The first method requires a list of matrices in the wide table format. The second methodl requres a data.frame in the long table format.
#' @return Returns a data frame consisting of the degrees of freedom, the test value, the critical value and the p-value
#' @rdname hrm.test
#' @rdname hrm_test
#' @param data Either a data.frame (one observation per row) or a list with matrices (one subject per row) for all groups containing the data
#' @param formula A model formula object. The left hand side contains the response variable and the right hand side contains the whole- and subplot factors.
#' @param subject column name within the data frame X identifying the subjects
#' @param alpha alpha level used for the test
#' @param ... Further arguments passed to 'hrm.test'
#' @param alpha alpha level used for calculating the critical value for the test
#' @param nonparametric Logical variable indicating wether the noparametric version of the test statistic should be used
#' @param ... Further arguments passed to 'hrm_test' will be ignored
#' @return Returns an object from class HRM containing
#' @return \item{result}{A dataframe with the results from the hypotheses tests.}
#' @return \item{formula}{The formula object which was used.}
Expand All @@ -26,34 +26,37 @@
#' @return \item{data}{The data.frame or list containing the data.}
#' @example R/example_1.txt
#' @keywords export
hrm.test <- function(data, ...) {
UseMethod("hrm.test")
hrm_test <- function(data, ...) {
UseMethod("hrm_test")
}

#' @method hrm.test default
#' @method hrm_test default
#' @keywords export
hrm.test.default <- function(data) {
stop("Your data needs either be a data.frame or a list containing matrices.")
hrm_test.default <- function(data) {
stop("Your data needs either to be a data.frame or a list containing matrices (a matrix for each group).")
}

#' @rdname hrm.test
#' @method hrm.test list
#' @rdname hrm_test
#' @method hrm_test list
#' @keywords export
hrm.test.list <- function(data, alpha = 0.05, ...) {
hrm_test.list <- function(data, alpha = 0.05, ...) {
return(hrm.test.matrices(data, alpha))
}

#' @rdname hrm.test
#' @method hrm.test data.frame
#' @rdname hrm_test
#' @method hrm_test data.frame
#' @keywords export
hrm.test.data.frame <- function(data, formula, alpha = 0.05, subject, ... ) {
return(hrm_test(formula=formula,alpha=alpha,subject=subject, data=data ))
hrm_test.data.frame <- function(data, formula, alpha = 0.05, subject, nonparametric = FALSE, ... ) {
return(hrm_test_internal(formula=formula, data=data, alpha=alpha,subject=subject, nonparametric ))
}



#' @keywords export
print.HRM <- function(x, ...) {
if(x$nonparametric){
cat("Nonparametric Repeated Measures Analysis\n")
cat("\n")
}
if(!is.null(x$formula)) {
cat("Call:", "\n")
print(x$formula)
Expand All @@ -62,11 +65,15 @@ print.HRM <- function(x, ...) {

print(x$result, row.names = FALSE)
cat("\nSignif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1")
cat("\n")
}


#' @keywords export
summary.HRM <- function(object, ...) {
if(object$nonparametric){
cat("Nonparametric Repeated Measures Analysis\n")
}
cat("Summary:\n")
cat("\n")
if(!is.null(object$formula)) {
Expand All @@ -84,4 +91,5 @@ summary.HRM <- function(object, ...) {

print(object$result, row.names = FALSE)
cat("\nSignif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1")
cat("\n")
}
9 changes: 6 additions & 3 deletions R/example_1.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## hrm.test with a list of matrices
## hrm_test with a list of matrices

# number patients per group
n = c(10,10)
Expand All @@ -16,9 +16,12 @@ sigma_2 = 1.5*sigma_1
X = list(mvrnorm(n[1],mu_1, sigma_1), mvrnorm(n[2],mu_2, sigma_2))
X=lapply(X, as.matrix)

hrm.test(data=X, alpha=0.05)
hrm_test(data=X, alpha=0.05)


## hrm.test with a data.frame using a 'formula' object

hrm.test(value ~ group*region*variable, subject = "subject", data = EEG)
# using the EEG dataset
?EEG

hrm_test(value ~ group*region*variable, subject = "subject", data = EEG)
12 changes: 11 additions & 1 deletion R/example_plot.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,14 @@ head(EEG)

# plots profiles according to groups with
# subplot-factor called dimension
plot(hrm.test(value ~ group*dimension, subject = "subject", data = EEG))

# first create an HRM object
object_hrm <- hrm_test(value ~ group*dimension, subject = "subject", data = EEG)

# plot the HRM object, here we use the additional argument 'theme_bw()' for ggplot2
plot(object_hrm, legend = TRUE, legend.title = "Group", ... = theme_bw() )

# same plot without a legend
# note that 'theme_bw' overwrites the standard legend properties of plot.HRM
plot(object_hrm, ... = theme_bw() +
theme(legend.title = element_blank(), legend.position="none") )
Loading

0 comments on commit 56f220c

Please sign in to comment.