33# ' @description This function calculates the correlation of two variables or the correlation
44# ' matrix for the variables of an input data frame.
55# ' @details In addition to computing correlations; this function produces a table outlining the
6- # ' number of complete cases and a table outlining the number of missing values to allow for the
6+ # ' number of complete cases and a table outlining the number of missing values to allow the
77# ' user to decide the 'relevance' of the correlation based on the number of complete
88# ' cases included in the correlation calculations.
99# '
1010# ' If the argument \code{y} is not NULL, the dimensions of the object have to be
1111# ' compatible with the argument \code{x}.
1212# '
13- # ' If \code{naAction} is set to \code{'casewise.complete'}, then the function omits all the rows
14- # ' in the whole data frame that include at least one cell with a missing value before the calculation of correlations.
15- # ' If \code{naAction} is set to \code{'pairwise.complete'} (default),
16- # ' then the function divides the input data frame to
17- # ' subset data frames formed by each pair between two variables
18- # ' (all combinations are considered) and omits the rows
19- # ' with missing values at each pair separately and then calculates the correlations of those pairs.
13+ # ' The function calculates the pairwise correlations based on casewise complete cases which means that
14+ # ' it omits all the rows in the input data frame that include at least one cell with a missing value,
15+ # ' before the calculation of correlations.
2016# '
21- # ' If \code{type} is set to \code{'split'} (default), the correlation of two variables or the
22- # ' variance-correlation matrix of an input data frame and the number of
23- # ' complete cases and missing values are returned for every single study.
24- # ' If type is set to \code{'combine'}, the pooled correlation, the total number of complete cases
25- # ' and the total number of missing values aggregated from all the involved studies, are returned.
17+ # ' If \code{type} is set to \code{'split'} (default), the correlation of two variables or the
18+ # ' variance-correlation matrix of an input data frame and the number of complete cases and missing
19+ # ' values are returned for every single study. If type is set to \code{'combine'}, the pooled
20+ # ' correlation, the total number of complete cases and the total number of missing values aggregated
21+ # ' from all the involved studies, are returned.
2622# '
27- # ' Server function called: \code{corDS}
23+ # ' Server function called: \code{corDS}
2824# '
2925# ' @param x a character string providing the name of the input vector, data frame or matrix.
3026# ' @param y a character string providing the name of the input vector, data frame or matrix.
3127# ' Default NULL.
32- # ' @param naAction a character string giving a method for computing correlations in the
33- # ' presence of missing values. This must be set to \code{'casewise.complete'} or
34- # ' \code{'pairwise.complete'}. Default \code{'casewise.complete'}. For more information see details.
3528# ' @param type a character string that represents the type of analysis to carry out.
3629# ' This must be set to \code{'split'} or \code{'combine'}. Default \code{'split'}. For more information see details.
3730# ' @param datasources a list of \code{\link{DSConnection-class}} objects obtained after login.
3831# ' If the \code{datasources} argument is not specified
3932# ' the default set of connections will be used: see \code{\link{datashield.connections_default}}.
4033# ' @return \code{ds.cor} returns a list containing the number of missing values in each variable,
41- # ' the number of missing variables casewise or pairwise depending on the argument \code{naAction} , the correlation matrix,
34+ # ' the number of missing variables casewise, the correlation matrix,
4235# ' the number of used complete cases. The function applies two disclosure controls. The first disclosure
4336# ' control checks that the number of variables is not bigger than a percentage of the individual-level records (the allowed
4437# ' percentage is pre-specified by the 'nfilter.glm'). The second disclosure control checks that none of them is dichotomous
7366# ' connections <- DSI::datashield.login(logins = logindata, assign = TRUE, symbol = "D")
7467# '
7568# ' # Example 1: Get the correlation matrix of two continuous variables
76- # ' ds.cor(x="D$LAB_TSC", y="D$LAB_TRIG", type="combine", naAction='casewise.complete',
77- # ' datasources = connections)
69+ # ' ds.cor(x="D$LAB_TSC", y="D$LAB_TRIG", type="combine", datasources = connections)
7870# '
7971# ' # Example 2: Get the correlation matrix of the variables in a dataframe
8072# ' ds.dataFrame(x=c("D$LAB_TSC", "D$LAB_TRIG", "D$LAB_HDL", "D$PM_BMI_CONTINUOUS"),
8173# ' newobj="D.new", check.names=FALSE, datasources=connections)
82- # ' ds.cor("D.new", type="combine", naAction = "casewise.complete", datasources = connections)
83- # ' ds.cor("D.new", type="combine", naAction = "pairwise.complete", datasources = connections)
74+ # ' ds.cor("D.new", type="combine", datasources = connections)
8475# '
8576# ' # clear the Datashield R sessions and logout
8677# ' datashield.logout(connections)
8778# '
8879# ' }
8980# ' @export
9081# '
91- ds.cor <- function (x = NULL , y = NULL , naAction = ' casewise.complete ' , type = " split" , datasources = NULL ){
82+ ds.cor <- function (x = NULL , y = NULL , type = " split" , datasources = NULL ){
9283
9384 # look for DS connections
9485 if (is.null(datasources )){
@@ -128,12 +119,12 @@ ds.cor <- function(x=NULL, y=NULL, naAction='casewise.complete', type="split", d
128119
129120 # call the server side function
130121 if ((' matrix' %in% typ ) | (' data.frame' %in% typ )){
131- calltext <- call(" corDS" , x , NULL , naAction )
122+ calltext <- call(" corDS" , x , NULL )
132123 }else {
133124 if (! (is.null(y ))){
134- calltext <- call(" corDS" , x , y , naAction )
125+ calltext <- call(" corDS" , x , y )
135126 }else {
136- calltext <- call(" corDS" , x , NULL , naAction )
127+ calltext <- call(" corDS" , x , NULL )
137128 }
138129 }
139130 output <- DSI :: datashield.aggregate(datasources , calltext )
@@ -156,12 +147,7 @@ ds.cor <- function(x=NULL, y=NULL, naAction='casewise.complete', type="split", d
156147 correlation [[i ]] <- stats :: cov2cor(covariance [[i ]])
157148 results [[i ]] <- list (output [[i ]][[4 ]][[1 ]], output [[i ]][[4 ]][[2 ]], correlation [[i ]], output [[i ]][[3 ]])
158149 n1 <- " Number of missing values in each variable"
159- if (naAction == ' casewise.complete' ){
160- n2 <- " Number of missing values casewise"
161- }
162- if (naAction == ' pairwise.complete' ){
163- n2 <- " Number of missing values pairwise"
164- }
150+ n2 <- " Number of missing values casewise"
165151 n3 <- " Correlation Matrix"
166152 n4 <- " Number of complete cases used"
167153 names(results [[i ]]) <- c(n1 , n2 , n3 , n4 )
@@ -198,12 +184,7 @@ ds.cor <- function(x=NULL, y=NULL, naAction='casewise.complete', type="split", d
198184
199185 results <- list (combined.missing.cases.vector , combined.missing.cases.matrix , combined.complete.cases , combined.correlation )
200186 n1 <- " Number of missing values in each variable"
201- if (naAction == ' casewise.complete' ){
202- n2 <- " Number of missing values casewise"
203- }
204- if (naAction == ' pairwise.complete' ){
205- n2 <- " Number of missing values pairwise"
206- }
187+ n2 <- " Number of missing values casewise"
207188 n3 <- " Number of complete cases used"
208189 n4 <- " Correlation Matrix"
209190 names(results ) <- c(n1 , n2 , n3 , n4 )
0 commit comments