1717# ' if \code{type} is set to 'split', 'splits' or 's', the kurtosis is returned separately for each study.
1818# ' if \code{type} is set to 'both' or 'b', both sets of outputs are produced.
1919# ' The default value is set to 'both'.
20+ # ' @template classConsistencyCheckFalse
2021# ' @param datasources a list of \code{\link[DSI]{DSConnection-class}} objects obtained after login.
2122# ' If the \code{datasources} argument is not specified
2223# ' the default set of connections will be used: see \code{\link[DSI]{datashield.connections_default}}.
23- # ' @return a matrix showing the kurtosis of the input numeric variable, the number of valid observations and
24- # ' the validity message .
24+ # ' @return a matrix showing the kurtosis of the input numeric variable and
25+ # ' the number of valid observations .
2526# ' @author Demetris Avraam, for DataSHIELD Development Team
27+ # ' @author Tim Cadman, Genomics Coordination Centre, UMCG, Netherlands
2628# ' @export
2729# '
28- ds.kurtosis <- function (x = NULL , method = 1 , type = ' both' , datasources = NULL ){
29-
30- # if no opal login details are provided look for 'opal' objects in the environment
31- if (is.null(datasources )){
32- datasources <- datashield.connections_find()
33- }
30+ ds.kurtosis <- function (x = NULL , method = 1 , type = ' both' , datasources = NULL , classConsistencyCheck = FALSE ){
3431
35- # ensure datasources is a list of DSConnection-class
36- if (! (is.list(datasources ) && all(unlist(lapply(datasources , function (d ) {methods :: is(d ," DSConnection" )}))))){
37- stop(" The 'datasources' were expected to be a list of DSConnection-class objects" , call. = FALSE )
38- }
32+ datasources <- .set_datasources(datasources )
3933
4034 if (is.null(x )){
4135 stop(" Please provide the name of the input vector!" , call. = FALSE )
@@ -53,26 +47,17 @@ ds.kurtosis <- function(x=NULL, method=1, type='both', datasources=NULL){
5347 stop(' Function argument "type" has to be either "both", "combine" or "split"' , call. = FALSE )
5448 }
5549
56- # check if the input object is defined in all the studies
57- isDefined(datasources , x )
58-
59- # call the internal function that checks the input object is of the same class in all studies.
60- typ <- checkClass(datasources , x )
61-
62- # the input object must be a numeric or an integer vector
63- if (typ != ' integer' & typ != ' numeric' ){
64- message(paste0(x , " is of type " , typ , " !" ))
65- stop(" The input object must be an integer or numeric vector." , call. = FALSE )
66- }
67-
6850 if (type == ' split' | type == ' both' ){
6951 calltext.split <- call(" kurtosisDS1" , x , method )
7052 output.split <- DSI :: datashield.aggregate(datasources , calltext.split )
71- mat.split <- matrix (as.numeric(matrix (unlist(output.split ), nrow = length(datasources ), byrow = TRUE )[,1 : 2 ]),nrow = length(datasources ))
72- validity <- matrix (unlist(output.split ), nrow = length(datasources ), byrow = TRUE )[,3 ]
73- mat.split <- data.frame (cbind(mat.split , validity ))
53+ if (classConsistencyCheck ){
54+ .checkClassConsistency(output.split )
55+ }
56+ mat.split <- data.frame (
57+ Kurtosis = sapply(output.split , function (r ) r $ Kurtosis ),
58+ Nvalid = sapply(output.split , function (r ) r $ Nvalid )
59+ )
7460 rownames(mat.split ) <- names(output.split )
75- colnames(mat.split ) <- c(' Kurtosis' , ' Nvalid' , ' ValidityMessage' )
7661 }
7762
7863 if (type == ' combine' | type == ' both' ){
@@ -84,6 +69,9 @@ ds.kurtosis <- function(x=NULL, method=1, type='both', datasources=NULL){
8469 }else {
8570 calltext.combined <- call(" kurtosisDS2" , x , global.mean )
8671 output.combined <- DSI :: datashield.aggregate(datasources , calltext.combined )
72+ if (classConsistencyCheck ){
73+ .checkClassConsistency(output.combined )
74+ }
8775
8876 Global.sum.quartics <- 0
8977 Global.sum.squares <- 0
@@ -98,19 +86,15 @@ ds.kurtosis <- function(x=NULL, method=1, type='both', datasources=NULL){
9886
9987 if (method == 1 ){
10088 Global.kurtosis <- g2.global
101- combinedMessage <- " VALID ANALYSIS"
10289 }
10390 if (method == 2 ){
10491 Global.kurtosis <- ((Global.Nvalid + 1 ) * g2.global + 6 ) * (Global.Nvalid - 1 )/ ((Global.Nvalid - 2 ) * (Global.Nvalid - 3 ))
105- combinedMessage <- " VALID ANALYSIS"
10692 }
10793 if (method == 3 ){
10894 Global.kurtosis <- (g2.global + 3 ) * (1 - 1 / Global.Nvalid )^ 2 - 3
109- combinedMessage <- " VALID ANALYSIS"
11095 }
111- mat.combined <- data.frame (cbind( Global.kurtosis , Global.Nvalid , combinedMessage ) )
96+ mat.combined <- data.frame (Kurtosis = Global.kurtosis , Nvalid = Global.Nvalid )
11297 rownames(mat.combined ) <- ' studiesCombined'
113- colnames(mat.combined ) <- c(' Kurtosis' , ' Nvalid' , ' ValidityMessage' )
11498
11599 }
116100 }
0 commit comments