From a8723e84ecc61def3de0dcc004cc24fcc1293f98 Mon Sep 17 00:00:00 2001 From: agaye Date: Thu, 1 Jan 2015 02:38:08 -0500 Subject: [PATCH] All changes completed. --- DESCRIPTION | 2 +- R/ds.cor.R | 65 +++++++++--------------- R/ds.corTest.R | 42 ++++++---------- R/ds.cov.R | 60 +++++++++------------- R/ds.tTest.R | 96 +++++++++++++++--------------------- R/ds.var.R | 40 +++++---------- data/login_remoteServer.rda | Bin 284 -> 290 bytes man/ds.cor.Rd | 36 +++++++------- man/ds.corTest.Rd | 20 ++++---- man/ds.cov.Rd | 36 +++++++------- man/ds.tTest.Rd | 79 ++++++++++++++--------------- man/ds.var.Rd | 22 ++++----- man/findLoginObjects.Rd | 26 ++++++++++ man/login_remoteServer.Rd | 10 ++-- 14 files changed, 243 insertions(+), 291 deletions(-) create mode 100644 man/findLoginObjects.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 894d4ad..586383a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: dsStatsClient Maintainer: Author: -Version: 3.0.1 +Version: 4.0.0 License: GPL-3 Title: DataSHIELD client site stattistical functions Description: DataSHIELD client site stattistical functions diff --git a/R/ds.cor.R b/R/ds.cor.R index 56c1c55..852de32 100644 --- a/R/ds.cor.R +++ b/R/ds.cor.R @@ -1,5 +1,5 @@ #' -#' @title Computes the correlation between two or more vectors +#' @title Computes correlation between two or more vectors #' @description This is similar to the R base function 'cor'. #' @details In addition to computing correlations this function, unlike #' the R base function 'cor', produces a table outlining the number of complete cases @@ -19,54 +19,39 @@ #' @export #' @examples { #' -#' # load that contains the login details -#' data(logindata) +#' # load that contains the login details +#' data(logindata) #' -#' # login and assign specific variable(s) -#' # (by default the assigned dataset is a dataframe named 'D') -#' myvar <- list('LAB_HDL', 'LAB_TSC', 'GENDER') -#' opals <- datashield.login(logins=logindata,assign=TRUE,variables=myvar) +#' # login and assign specific variable(s) +#' # (by default the assigned dataset is a dataframe named 'D') +#' myvar <- list('LAB_HDL', 'LAB_TSC', 'GENDER') +#' opals <- datashield.login(logins=logindata,assign=TRUE,variables=myvar) #' -#' # Example 1: generate the correlation matrix for the assigned dataset 'D' -#' # which contains 4 vectors (2 continuous and 1 categorical) -#' ds.cor(x='D') +#' # Example 1: generate the correlation matrix for the assigned dataset 'D' +#' # which contains 4 vectors (2 continuous and 1 categorical) +#' ds.cor(x='D') #' -#' # Example 2: calculate the correlation between two vectors (first assign some vectors from the dataframe 'D') -#' ds.assign(newobj='labhdl', toAssign='D$LAB_HDL') -#' ds.assign(newobj='labtsc', toAssign='D$LAB_TSC') -#' ds.assign(newobj='gender', toAssign='D$GENDER') -#' ds.cor(x='labhdl', y='labtsc') -#' ds.cor(x='labhdl', y='gender') +#' # Example 2: calculate the correlation between two vectors (first assign some vectors from the dataframe 'D') +#' ds.assign(newobj='labhdl', toAssign='D$LAB_HDL') +#' ds.assign(newobj='labtsc', toAssign='D$LAB_TSC') +#' ds.assign(newobj='gender', toAssign='D$GENDER') +#' ds.cor(x='labhdl', y='labtsc') +#' ds.cor(x='labhdl', y='gender') #' -#' # clear the Datashield R sessions and logout -#' datashield.logout(opals) +#' # clear the Datashield R sessions and logout +#' datashield.logout(opals) #' #' } #' -ds.cor = function(x=NULL, y=NULL, naAction='pairwise.complete.obs', datasources=NULL) -{ +ds.cor = function(x=NULL, y=NULL, naAction='pairwise.complete.obs', datasources=NULL){ - # if no opal login details were provided look for 'opal' objects in the environment + # if no opal login details are provided look for 'opal' objects in the environment if(is.null(datasources)){ - findLogin <- getOpals() - if(findLogin$flag == 1){ - datasources <- findLogin$opals - }else{ - if(findLogin$flag == 0){ - stop(" Are yout logged in to any server? Please provide a valid opal login object! ", call.=FALSE) - }else{ - message(paste0("More than one list of opal login object were found: '", paste(findLogin$opals,collapse="', '"), "'!")) - userInput <- readline("Please enter the name of the login object you want to use: ") - datasources <- eval(parse(text=userInput)) - if(class(datasources[[1]]) != 'opal'){ - stop("End of process: you failed to enter a valid login object", call.=FALSE) - } - } - } + datasources <- findLoginObjects() } if(is.null(x)){ - stop("x=NULL. Please provide the names of two numeric vectors!", call.=FALSE) + stop("x must be the name of a numeric vector or a table structure (matrix or data frame)", call.=FALSE) }else{ defined <- isDefined(datasources, x) } @@ -76,9 +61,7 @@ ds.cor = function(x=NULL, y=NULL, naAction='pairwise.complete.obs', datasources= if(typ=='numeric' | typ=='integer' | typ=='factor'){ if(is.null(y)){ - message(" ALERT!") - message(" y is set to NULL whilst x is a numeric vector, please provide a second vector") - stop(" End of process!", call.=FALSE) + stop("If x is a numeric vector, y must be a numeric vector!", call.=FALSE) }else{ defined2 <- isDefined(datasources, y) typ2 <- checkClass(datasources, y) @@ -87,7 +70,7 @@ ds.cor = function(x=NULL, y=NULL, naAction='pairwise.complete.obs', datasources= if(typ=='matrix' | typ=='data.frame' & !(is.null(y))){ y <- NULL - warning(" x is a matrix or a dataframe; y will be ignored and a correlation matrix computed for x!") + warning("x is a matrix or a data frame; y will be ignored and a correlation matrix computed for x!") } # name of the studies to be used in the output diff --git a/R/ds.corTest.R b/R/ds.corTest.R index 02977fc..7f982e9 100644 --- a/R/ds.corTest.R +++ b/R/ds.corTest.R @@ -11,48 +11,34 @@ #' @export #' @examples { #' -#' # load that contains the login details -#' data(logindata) +#' # load that contains the login details +#' data(logindata) #' -#' # login and assign specific variable(s) -#' # (by default the assigned dataset is a dataframe named 'D') -#' myvar <- list('LAB_TSC', 'LAB_HDL') -#' opals <- datashield.login(logins=logindata,assign=TRUE,variables=myvar) +#' # login and assign specific variable(s) +#' # (by default the assigned dataset is a dataframe named 'D') +#' myvar <- list('LAB_TSC', 'LAB_HDL') +#' opals <- datashield.login(logins=logindata,assign=TRUE,variables=myvar) #' -#' # test for correlation between the variables 'LAB_TSC' and 'LAB_HDL' -#' ds.corTest(x='D$LAB_TSC', y='D$LAB_HDL') +#' # test for correlation between the variables 'LAB_TSC' and 'LAB_HDL' +#' ds.corTest(x='D$LAB_TSC', y='D$LAB_HDL') #' -#' # clear the Datashield R sessions and logout -#' datashield.logout(opals) +#' # clear the Datashield R sessions and logout +#' datashield.logout(opals) #' #' } #' ds.corTest = function(x=NULL, y=NULL, datasources=NULL){ - # if no opal login details were provided look for 'opal' objects in the environment + # if no opal login details are provided look for 'opal' objects in the environment if(is.null(datasources)){ - findLogin <- getOpals() - if(findLogin$flag == 1){ - datasources <- findLogin$opals - }else{ - if(findLogin$flag == 0){ - stop(" Are yout logged in to any server? Please provide a valid opal login object! ", call.=FALSE) - }else{ - message(paste0("More than one list of opal login object were found: '", paste(findLogin$opals,collapse="', '"), "'!")) - userInput <- readline("Please enter the name of the login object you want to use: ") - datasources <- eval(parse(text=userInput)) - if(class(datasources[[1]]) != 'opal'){ - stop("End of process: you failed to enter a valid login object", call.=FALSE) - } - } - } + datasources <- findLoginObjects() } if(is.null(x)){ - stop("x=NULL. Please provide the names of two numeric vectors!", call.=FALSE) + stop("x=NULL. Please provide the names of the 1st vector!", call.=FALSE) } if(is.null(y)){ - stop("y=NULL. Please provide the names of two numeric vectors!", call.=FALSE) + stop("y=NULL. Please provide the names of the 2nd numeric vector!", call.=FALSE) } # the input variable might be given as column table (i.e. D$object) diff --git a/R/ds.cov.R b/R/ds.cov.R index 16cc8c3..15605b1 100644 --- a/R/ds.cov.R +++ b/R/ds.cov.R @@ -19,50 +19,36 @@ #' @export #' @examples { #' -#' # load that contains the login details -#' data(logindata) +#' # load that contains the login details +#' data(logindata) #' -#' # login and assign specific variable(s) -#' # (by default the assigned dataset is a dataframe named 'D') -#' myvar <- list('LAB_HDL', 'LAB_TSC', 'GENDER') -#' opals <- datashield.login(logins=logindata,assign=TRUE,variables=myvar) +#' # login and assign specific variable(s) +#' # (by default the assigned dataset is a dataframe named 'D') +#' myvar <- list('LAB_HDL', 'LAB_TSC', 'GENDER') +#' opals <- datashield.login(logins=logindata,assign=TRUE,variables=myvar) #' -#' # Example 1: generate the covariance matrix for the assigned dataset 'D' -#' # which contains 4 vectors (2 continuous and 1 categorical) -#' ds.cov(x='D') +#' # Example 1: generate the covariance matrix for the assigned dataset 'D' +#' # which contains 4 vectors (2 continuous and 1 categorical) +#' ds.cov(x='D') #' -#' # Example 2: calculate the covariance between two vectors -#' # (first assign the vectors from 'D') -#' ds.assign(newobj='labhdl', toAssign='D$LAB_HDL') -#' ds.assign(newobj='labtsc', toAssign='D$LAB_TSC') -#' ds.assign(newobj='gender', toAssign='D$GENDER') -#' ds.cov(x='labhdl', y='labtsc') -#' ds.cov(x='labhdl', y='gender') +#' # Example 2: calculate the covariance between two vectors +#' # (first assign the vectors from 'D') +#' ds.assign(newobj='labhdl', toAssign='D$LAB_HDL') +#' ds.assign(newobj='labtsc', toAssign='D$LAB_TSC') +#' ds.assign(newobj='gender', toAssign='D$GENDER') +#' ds.cov(x='labhdl', y='labtsc') +#' ds.cov(x='labhdl', y='gender') #' -#' # clear the Datashield R sessions and logout -#' datashield.logout(opals) +#' # clear the Datashield R sessions and logout +#' datashield.logout(opals) #' #' } #' ds.cov = function(x=NULL, y=NULL, naAction='pairwise.complete.obs', datasources=NULL){ - # if no opal login details were provided look for 'opal' objects in the environment + # if no opal login details are provided look for 'opal' objects in the environment if(is.null(datasources)){ - findLogin <- getOpals() - if(findLogin$flag == 1){ - datasources <- findLogin$opals - }else{ - if(findLogin$flag == 0){ - stop(" Are yout logged in to any server? Please provide a valid opal login object! ", call.=FALSE) - }else{ - message(paste0("More than one list of opal login object were found: '", paste(findLogin$opals,collapse="', '"), "'!")) - userInput <- readline("Please enter the name of the login object you want to use: ") - datasources <- eval(parse(text=userInput)) - if(class(datasources[[1]]) != 'opal'){ - stop("End of process: you failed to enter a valid login object", call.=FALSE) - } - } - } + datasources <- findLoginObjects() } if(is.null(x)){ @@ -76,9 +62,7 @@ ds.cov = function(x=NULL, y=NULL, naAction='pairwise.complete.obs', datasources= if(typ=='numeric' | typ=='integer' | typ=='factor'){ if(is.null(y)){ - message(" ALERT!") - message(" y is set to NULL whilst x is a numeric vector, please provide a second vector") - stop(" End of process!", call.=FALSE) + stop("If x is a numeric vector, y must be a numeric vector!", call.=FALSE) }else{ defined2 <- isDefined(datasources, y) typ2 <- checkClass(datasources, y) @@ -87,7 +71,7 @@ ds.cov = function(x=NULL, y=NULL, naAction='pairwise.complete.obs', datasources= if(typ=='matrix' | typ=='data.frame' & !(is.null(y))){ y <- NULL - warning(" x is a matrix or a dataframe; y will be ignored and a covariance matrix computed for x!") + warning("x is a matrix or a dataframe; y will be ignored and a covariance matrix computed for x!") } # name of the studies to be used in the output diff --git a/R/ds.tTest.R b/R/ds.tTest.R index 51aa989..aebc174 100644 --- a/R/ds.tTest.R +++ b/R/ds.tTest.R @@ -21,80 +21,67 @@ #' @param datasources a list of opal object(s) obtained after login in to opal servers; #' these objects hold also the data assign to R, as \code{dataframe}, from opal datasources. #' @return a list containing the following elements: -#' \code{statistic} the value of the t-statistic -#' \code{parameter} the degrees of freedom for the t-statistic -#' \code{p.value} p.value the p-value for the test -#' \code{conf.int} a confidence interval for the mean appropriate to the specified alternative hypothesis -#' \code{estimate} the estimated mean or difference in means depending on whether it was a one-sample test or a two-sample test -#' \code{null.value} the specified hypothesized value of the mean or mean difference depending on whether it was a one-sample test or a two-sample test +#' \code{statistic} the value of the t-statistic. +#' \code{parameter} the degrees of freedom for the t-statistic. +#' \code{p.value} p.value the p-value for the test. +#' \code{conf.int} a confidence interval for the mean appropriate to the specified alternative hypothesis. +#' \code{estimate} the estimated mean or difference in means depending on whether it was a one-sample test +#' or a two-sample test. +#' \code{null.value} the specified hypothesized value of the mean or mean difference depending on whether it +#' was a one-sample test or a two-sample test. #' \code{alternative} a character string describing the alternative hypothesis #' \code{method} a character string indicating what type of t-test was performed #' @author Isaeva, J.; Gaye, A. #' @export -#' @examples -#' { +#' @examples { #' -#' # load that contains the login details -#' data(logindata) +#' # load that contains the login details +#' data(logindata) #' -#' # login and assign specific variable(s) -#' myvar <- list("LAB_HDL", "LAB_TSC") -#' opals <- datashield.login(logins=logindata,assign=TRUE,variables=myvar) +#' # login and assign specific variable(s) +#' myvar <- list("LAB_HDL", "LAB_TSC") +#' opals <- datashield.login(logins=logindata,assign=TRUE,variables=myvar) #' -#' # Example 1: Run a t.test of the pooled data for the variables 'LAB_HDL' and 'LAB_TSC' - default -#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC') +#' # Example 1: Run a t.test of the pooled data for the variables 'LAB_HDL' and 'LAB_TSC' - default +#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC') #' -#' # Example 2: Run a t.test for each study separately for the same variables as above -#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC', type='split') +#' # Example 2: Run a t.test for each study separately for the same variables as above +#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC', type='split') #' -#' # Example 3: Run a paired t.test of the pooled data -#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC', paired=TRUE) +#' # Example 3: Run a paired t.test of the pooled data +#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC', paired=TRUE) #' -#' # Example 4: Run a paired t.test for each study separately -#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC', paired=TRUE, type='split') +#' # Example 4: Run a paired t.test for each study separately +#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC', paired=TRUE, type='split') #' -#' # Example 5: Run a t.test of the pooled data with different alternatives -#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC', alternative='greater') -#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC', alternative='less') +#' # Example 5: Run a t.test of the pooled data with different alternatives +#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC', alternative='greater') +#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC', alternative='less') #' -#' # Example 6: Run a t.test of the pooled data with mu different from zero -#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC', mu=-4) +#' # Example 6: Run a t.test of the pooled data with mu different from zero +#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC', mu=-4) #' -#' # Example 7: Run a t.test of the pooled data assuming that variances of variables are equal -#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC', var.equal=TRUE) +#' # Example 7: Run a t.test of the pooled data assuming that variances of variables are equal +#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC', var.equal=TRUE) #' -#' # Example 8: Run a t.test of the pooled data with 90% confidence interval -#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC', conf.level=0.90) +#' # Example 8: Run a t.test of the pooled data with 90% confidence interval +#' ds.tTest(x='D$LAB_HDL', y='D$LAB_TSC', conf.level=0.90) #' -#' # Example 9: Run a one-sample t.test of the pooled data -#' ds.tTest(x='D$LAB_HDL') -#' # the below example should not work, paired t.test is not possible if the 'y' variable is missing -#' # ds.tTest(x='D$LAB_HDL', paired=TRUE) +#' # Example 9: Run a one-sample t.test of the pooled data +#' ds.tTest(x='D$LAB_HDL') +#' # the below example should not work, paired t.test is not possible if the 'y' variable is missing +#' # ds.tTest(x='D$LAB_HDL', paired=TRUE) #' -#' # clear the Datashield R sessions and logout -#' datashield.logout(opals) +#' # clear the Datashield R sessions and logout +#' datashield.logout(opals) #' #'} #' ds.tTest <- function (x=NULL, y=NULL, type="combine", alternative="two.sided", mu=0, paired=FALSE, var.equal=FALSE, conf.level=0.95, datasources=NULL) { - # if no opal login details were provided look for 'opal' objects in the environment + # if no opal login details are provided look for 'opal' objects in the environment if(is.null(datasources)){ - findLogin <- getOpals() - if(findLogin$flag == 1){ - datasources <- findLogin$opals - }else{ - if(findLogin$flag == 0){ - stop(" Are yout logged in to any server? Please provide a valid opal login object! ", call.=FALSE) - }else{ - message(paste0("More than one list of opal login object were found: '", paste(findLogin$opals,collapse="', '"), "'!")) - userInput <- readline("Please enter the name of the login object you want to use: ") - datasources <- eval(parse(text=userInput)) - if(class(datasources[[1]]) != 'opal'){ - stop("End of process: you failed to enter a valid login object", call.=FALSE) - } - } - } + datasources <- findLoginObjects() } if(is.null(x)){ @@ -187,9 +174,8 @@ ds.tTest <- function (x=NULL, y=NULL, type="combine", alternative="two.sided", m cally = paste0("subsetDS('", x, "', not.na.x)") datashield.assign(datasources, 'xok', as.symbol(cally)) cally = paste0("as.null(", x, ")") - datashield.assign(datasources, 'yok', as.symbol(cally)) # does not matter that as.null(x) since we just want to make y to be NULL - } - + datashield.assign(datasources, 'yok', as.symbol(cally)) # does not matter that as.null(x) since we just want to set y to NULL + } if (paired) { cally = paste0("(yok)","*(",-1,")") diff --git a/R/ds.var.R b/R/ds.var.R index 4d8fd83..90c093a 100644 --- a/R/ds.var.R +++ b/R/ds.var.R @@ -13,43 +13,29 @@ #' @export #' @examples { #' -#' # load that contains the login details -#' data(logindata) +#' # load that contains the login details +#' data(logindata) #' -#' # login and assign specific variable(s) -#' myvar <- list('LAB_TSC') -#' opals <- datashield.login(logins=logindata,assign=TRUE,variables=myvar) +#' # login and assign specific variable(s) +#' myvar <- list('LAB_TSC') +#' opals <- datashield.login(logins=logindata,assign=TRUE,variables=myvar) #' -#' # Example 1: compute the pooled variance of the variable 'LAB_TSC' - default behaviour -#' ds.var(x='D$LAB_TSC') +#' # Example 1: compute the pooled variance of the variable 'LAB_TSC' - default behaviour +#' ds.var(x='D$LAB_TSC') #' -#' # Example 2: compute the variance of each study separately -#' ds.var(x='D$LAB_TSC', type='split') +#' # Example 2: compute the variance of each study separately +#' ds.var(x='D$LAB_TSC', type='split') #' -#' # clear the Datashield R sessions and logout -#' datashield.logout(opals) +#' # clear the Datashield R sessions and logout +#' datashield.logout(opals) #' #' } #' ds.var = function(x=NULL, type='combine', datasources=NULL){ - # if no opal login details were provided look for 'opal' objects in the environment + # if no opal login details are provided look for 'opal' objects in the environment if(is.null(datasources)){ - findLogin <- getOpals() - if(findLogin$flag == 1){ - datasources <- findLogin$opals - }else{ - if(findLogin$flag == 0){ - stop(" Are yout logged in to any server? Please provide a valid opal login object! ", call.=FALSE) - }else{ - message(paste0("More than one list of opal login object were found: '", paste(findLogin$opals,collapse="', '"), "'!")) - userInput <- readline("Please enter the name of the login object you want to use: ") - datasources <- eval(parse(text=userInput)) - if(class(datasources[[1]]) != 'opal'){ - stop("End of process: you failed to enter a valid login object", call.=FALSE) - } - } - } + datasources <- findLoginObjects() } if(is.null(x)){ diff --git a/data/login_remoteServer.rda b/data/login_remoteServer.rda index 7720b6a152ddce046e3e71edf338a80a622b9570..721c514cb9661e789165a3b587343b5316007426 100644 GIT binary patch literal 290 zcmV+-0p0!|iwFP!000001C3F!PQx$|y~Ih?MhZf(@eg%Nrm8C}3^3588*&=AL~`Ql z?6xako?z^RDuxOM+vj)h-aVgRAJYT5`+*E6Goxg0*GK@&Kn_jW&MV{lA5nL z9ytP#Ta$^+y0(>$c_s5QXH(6UrpVO=bXaruuJwL7n-xZ$S|*jaTQ25{`9ByyQmggl z)~h($ literal 284 zcmV+%0ptE3iwFP!000001C3I#PQx$|y~IgHBLyL`@ejBqQ`Hp~1{h%J>NIYNyq7Tt~5oiE}(wQ-G|n@