#'Estimate beta (Allow Different Types of Facilities)
#'
#'This function estimates beta in a stratified Cox proportional hazard model. You can also set facility to be
#'the same and model an unstratified Cox model with this function. Note, missingness is not allowed, and ties
#'might affect the correctness.
#'
#'@param delta indicator vector of event
#'@param z design matrix
#'@param facility_ori which facility each patient belongs to
#'@param time observed time
#'@param num_facility number of facilities (strata)
#'@param tol tolerance of precision, when highest change in beta is lower than or equal to tol, iteration stops
#'
#'@return estimated beta
#'
#'@examples
#'set.seed(2019)
#'testdata = generate_data(F_pre = c("a", "b", "c", "d"), gamma = rep(1, 4), order = FALSE)
#'stratified_cox(testdata$delta, testdata$z, testdata$facility, testdata$time,
#'testdata$num_facility, tol= 1.0e-6)
#'
#'@export
stratified_cox = function(delta, z, facility_ori, time, num_facility, tol) {
# convert facility
facility_uni = unique(facility_ori)
facility = 1:length(facility_ori)
sapply(1:num_facility, FUN = function(x){facility[facility_ori == facility_uni[x]] <<- x})
# order data
od = order(time)
delta = delta[od]
z = z[od, ]
facility = facility[od]
time = time[od]
# call Rcpp function
.Call('_survival19_CoxC', PACKAGE = 'survival19', delta, z, facility, num_facility, tol)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.