Skip to content

Commit

Permalink
feat: add split linear regression
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasopaum committed Jun 14, 2023
1 parent 187461a commit 31d8887
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export(ds.boundedSumDP)
export(ds.boundedVarianceDP)
export(ds.chisqDP)
export(ds.countDP)
export(ds.linearRegressionDP)
export(ds.maxDP)
export(ds.medianDP)
export(ds.minDP)
Expand Down
31 changes: 31 additions & 0 deletions R/ds.linearRegressionDP.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
source("R/utils.R")

#' @title Differentially private count
#'
#' @param target_column target response
#' @param input_columns explanatory variables
#' @param epsilon privacy budget
#' @param type a character string that represents the type of analysis to carry out.
#' This can be set as \code{'combine'}, \code{'split'} or \code{'both'}.
#' @param datasources a list of \code{\link{DSConnection-class}}
#' objects obtained after login. If the \code{datasources} argument is not specified
#' the default set of connections will be used: see \code{\link{datashield.connections_default}}.
#'
#' @return \code{ds.countDP} returns to the client-side a list including: \cr
#' \code{Count.by.Study} (private count) for each study (if \code{type = split} or \code{type = both}). \cr
#' \code{Global.Count} (private count) and across all studies combined (if \code{type = combine} or \code{type = both}).
#' @export

ds.linearRegressionDP <- function(target_column, input_columns, epsilon, type="split", datasources=NULL) {

if (is.null(datasources)) {
datasources <- DSI::datashield.connections_find()
}

coefficients.split <- callAggregationMethod(datasources, paste0("linearRegressionDP(", target_column, ", ", input_columns, ", ", epsilon, ")"))
coefficients.combine <- NULL

if (type=="combine") return(list(Global.Coefficients=coefficients.combine))
if (type=="split") return(list(Coefficients.by.Study=coefficients.split))
if (type=="both") return(list(Coefficients.by.Study=coefficients.split,Global.Coefficients=coefficients.combine))
}

0 comments on commit 31d8887

Please sign in to comment.