Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

Commit

Permalink
All changes completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
agaye committed Jan 1, 2015
1 parent 94d6f43 commit a8723e8
Show file tree
Hide file tree
Showing 14 changed files with 243 additions and 291 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: dsStatsClient
Maintainer: <[email protected]>
Author: <[email protected]>
Version: 3.0.1
Version: 4.0.0
License: GPL-3
Title: DataSHIELD client site stattistical functions
Description: DataSHIELD client site stattistical functions
Expand Down
65 changes: 24 additions & 41 deletions R/ds.cor.R
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
Expand All @@ -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)
Expand All @@ -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
Expand Down
42 changes: 14 additions & 28 deletions R/ds.corTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
60 changes: 22 additions & 38 deletions R/ds.cov.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand All @@ -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)
Expand All @@ -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
Expand Down
96 changes: 41 additions & 55 deletions R/ds.tTest.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)){
Expand Down Expand Up @@ -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,")")
Expand Down
Loading

0 comments on commit a8723e8

Please sign in to comment.