|
1 | 1 | #' |
2 | | -#' @title Calculates the skewness of a numeric variable |
3 | | -#' @description This function calculates the skewness of a numeric variable. |
4 | | -#' @details The function calculates the skewness of an input variable x with three different methods. |
5 | | -#' The method is specified by the argument \code{method}. If x contains any missings, the function removes those before |
6 | | -#' the calculation of the skewness. If \code{method} is set to 1 the following formula is used |
7 | | -#' \eqn{ skewness= \frac{\sum_{i=1}^{N} (x_i - \bar(x))^3 /N}{(\sum_{i=1}^{N} ((x_i - \bar(x))^2) /N)^(3/2) }}, |
8 | | -#' where \eqn{ \bar{x} } is the mean of x and \eqn{N} is the number of observations. If \code{method} is set to 2 |
9 | | -#' the following formula is used \eqn{ skewness= \frac{\sum_{i=1}^{N} (x_i - \bar(x))^3 /N}{(\sum_{i=1}^{N} ((x_i - \bar(x))^2) /N)^(3/2) } * \frac{\sqrt(N(N-1)}{n-2}}. |
10 | | -#' If \code{method} is set to 3 the following formula is used \eqn{ skewness= \frac{\sum_{i=1}^{N} (x_i - \bar(x))^3 /N}{(\sum_{i=1}^{N} ((x_i - \bar(x))^2) /N)^(3/2) } * (\frac{N-1}{N})^(3/2)}. |
11 | | -#' This function is similar to the function \code{skewness} in R package \code{e1071}. |
12 | | -#' @param x a string character, the name of a numeric variable. |
13 | | -#' @param method an integer between 1 and 3 selecting one of the algorithms for computing skewness |
14 | | -#' detailed below. The default value is set to 1. |
15 | | -#' @param type a character which represents the type of analysis to carry out. |
16 | | -#' If \code{type} is set to 'combine', 'combined', 'combines' or 'c', the global skewness is returned |
17 | | -#' if \code{type} is set to 'split', 'splits' or 's', the skewness is returned separately for each study. |
18 | | -#' if \code{type} is set to 'both' or 'b', both sets of outputs are produced. |
19 | | -#' The default value is set to 'both'. |
20 | | -#' @param datasources a list of \code{\link{DSConnection-class}} objects obtained after login. |
21 | | -#' If the \code{datasources} argument is not specified |
| 2 | +#' @title Calculates the skewness of a server-side numeric variable |
| 3 | +#' @description This function calculates the skewness of a numeric variable |
| 4 | +#' that is stored on the server-side (Opal server). |
| 5 | +#' @details This function is similar to the function \code{skewness} in R package \code{e1071}. |
| 6 | +#' |
| 7 | +#' The function calculates the skewness of an input variable \code{x} |
| 8 | +#' with three different methods: \cr |
| 9 | +#' (1) If \code{method} is set to 1 the following formula is used \eqn{ skewness= \frac{\sum_{i=1}^{N} (x_i - \bar(x))^3 /N}{(\sum_{i=1}^{N} ((x_i - \bar(x))^2) /N)^(3/2) }}, |
| 10 | +#' where \eqn{ \bar{x} } is the mean of x and \eqn{N} is the number of observations.\cr |
| 11 | +#' (2) If \code{method} is set to 2 |
| 12 | +#' the following formula is used \eqn{ skewness= \frac{\sum_{i=1}^{N} (x_i - \bar(x))^3 /N}{(\sum_{i=1}^{N} ((x_i - \bar(x))^2) /N)^(3/2) } * \frac{\sqrt(N(N-1)}{n-2}}.\cr |
| 13 | +#' (3) If \code{method} is set to 3 the following formula is used \eqn{ skewness= \frac{\sum_{i=1}^{N} (x_i - \bar(x))^3 /N}{(\sum_{i=1}^{N} ((x_i - \bar(x))^2) /N)^(3/2) } * (\frac{N-1}{N})^(3/2)}. |
| 14 | +#' |
| 15 | +#' The \code{type} argument can be set as follows:\cr |
| 16 | +#' (1) If \code{type} is set to \code{'combine'}, \code{'combined'}, \code{'combines'} or \code{'c'}, |
| 17 | +#' the global skewness is returned.\cr |
| 18 | +#' (2) If \code{type} is set to \code{'split'}, \code{'splits'} or \code{'s'}, |
| 19 | +#' the skewness is returned separately for each study.\cr |
| 20 | +#' (3) If \code{type} is set to \code{'both'} or \code{'b'}, both sets of outputs are produced.\cr |
| 21 | +#' |
| 22 | +#' If \code{x} contains any missing value, the function removes those before |
| 23 | +#' the calculation of the skewness. |
| 24 | +#' |
| 25 | +#' Server functions called: \code{skewnessDS1} and \code{skewnessDS2} |
| 26 | +#' |
| 27 | +#' @param x a character string specifying the name of a numeric variable. |
| 28 | +#' @param method an integer value between 1 and 3 selecting one of the algorithms for computing skewness. |
| 29 | +#' For more information see \strong{Details}. The default value is set to 1. |
| 30 | +#' @param type a character string which represents the type of analysis to carry out. |
| 31 | +#' \code{type} can be set as: \code{'combine'}, \code{'split'} or \code{'both'}. For more information |
| 32 | +#' see \strong{Details}. |
| 33 | +#' The default value is set to \code{'both'}. |
| 34 | +#' @param datasources a list of \code{\link{DSConnection-class}} |
| 35 | +#' objects obtained after login. If the \code{datasources} argument is not specified |
22 | 36 | #' the default set of connections will be used: see \code{\link{datashield.connections_default}}. |
23 | | -#' @return a matrix showing the skewness of the input numeric variable, the number of valid observations and |
24 | | -#' the validity message. |
| 37 | +#' @return \code{ds.skewness} returns a matrix showing the skewness of the input numeric variable, |
| 38 | +#' the number of valid observations and the validity message. |
25 | 39 | #' @author Demetris Avraam, for DataSHIELD Development Team |
| 40 | +#' @examples |
| 41 | +#' \dontrun{ |
| 42 | +#' ## Version 6, for version 5 see the Wiki |
| 43 | +#' |
| 44 | +#' # connecting to the Opal servers |
| 45 | +#' |
| 46 | +#' require('DSI') |
| 47 | +#' require('DSOpal') |
| 48 | +#' require('dsBaseClient') |
| 49 | +#' |
| 50 | +#' builder <- DSI::newDSLoginBuilder() |
| 51 | +#' builder$append(server = "study1", |
| 52 | +#' url = "http://192.168.56.100:8080/", |
| 53 | +#' user = "administrator", password = "datashield_test&", |
| 54 | +#' table = "CNSIM.CNSIM1", driver = "OpalDriver") |
| 55 | +#' builder$append(server = "study2", |
| 56 | +#' url = "http://192.168.56.100:8080/", |
| 57 | +#' user = "administrator", password = "datashield_test&", |
| 58 | +#' table = "CNSIM.CNSIM2", driver = "OpalDriver") |
| 59 | +#' builder$append(server = "study3", |
| 60 | +#' url = "http://192.168.56.100:8080/", |
| 61 | +#' user = "administrator", password = "datashield_test&", |
| 62 | +#' table = "CNSIM.CNSIM3", driver = "OpalDriver") |
| 63 | +#' logindata <- builder$build() |
| 64 | +#' |
| 65 | +#' connections <- DSI::datashield.login(logins = logindata, assign = TRUE, symbol = "D") |
| 66 | +#' |
| 67 | +#' #Calculate the skewness of LAB_TSC numeric variable for each study separately and combined |
| 68 | +#' |
| 69 | +#' ds.skewness(x = "D$LAB_TSC", |
| 70 | +#' method = 1, |
| 71 | +#' type = "both", |
| 72 | +#' datasources = connections) |
| 73 | +#' |
| 74 | +#' # Clear the Datashield R sessions and logout |
| 75 | +#' DSI::datashield.logout(connections) |
| 76 | +#' |
| 77 | +#' } |
26 | 78 | #' @export |
27 | 79 | #' |
28 | 80 | ds.skewness <- function(x=NULL, method=1, type='both', datasources=NULL){ |
|
0 commit comments