#' @title Remote coxph + (optional) survfit.coxph
#' @description Executes coxph \{survival\} and survfit \{survival\} on the remote nodes
#' @param ... arguments to be sent to the 2 functions.
#' Note, the data argument must be a character, the name of the input dataframe.
#' If a newdata dataframe is present in the arguments, survfit will be called on the coxph object.
#' The newdata dataframe argument must be sent as text describing the arguments to a call to data.frame() (see example).
#' @param async same as in datashield.assign
#' @param datasources same as in datashield.assign
#' @return A list containing the stripped down coxph model (without the call and the residuals)
#' @examples
#' # open a local pseudo connection:
#' library(DSLite)
#' dslite.server1 <<- newDSLiteServer(config = defaultDSConfiguration(include=c('dsSwissKnife')))
#' builder <- newDSLoginBuilder()
#' builder$append(server="server1", url='dslite.server1',driver = "DSLiteDriver")
#' logindata <- builder$build()
#' opals <- datashield.login(logins = logindata)
#' # load the lung dataset
#' datashield.aggregate(opals[1], as.symbol('partialData("lung", NULL, NULL, "survival")'))
#' #create the new.dataframe argument (note the reference to the 'lung' data frame)
#' new.df <- 'sex = c(1, 2), age = rep(mean(lung$age, na.rm = TRUE), 2), ph.ecog = c(1, 1)'
#'
#' # execute the function:
#' cox.res <- dssCoxph(formula = survival::Surv(time, status) ~ age + sex + ph.ecog, data = 'lung', new.dataframe = new.df, async = FALSE, datasources = opals[1])
#' summary(cox.res$server1$model)
#' # plot the fit:
#' plot(cox.res$local1$fit, conf.int = TRUE, col = c('blue', 'red'))
#'
#' @export
#'
dssCoxph <- function(..., async = TRUE, datasources = NULL){
if(is.null(datasources)){
datasources <- datashield.connections_find()
}
arglist <- list(...) # pass the args list almost as is to coxph on the local nodes
if(typeof(arglist$formula) == 'language'){
arglist$formula <- Reduce(paste, deparse(arglist$formula)) # Reduce for formulas longer than 60 chars - deparse splits them into a vector
}
arglist <- .encode.arg(arglist)
cally <- paste0('coxphDSS("', arglist, '")')
datashield.aggregate(datasources, as.symbol(cally), async = async)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.