# positive time
x <- c( 1, 1.5, 2, 3, 4.2, 5.0, 6.1, 5.3, 4.5, 0.9, 2.1, 4.3)
# status censored/uncensored
d <- c( 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1)
#################
# dim =1
#################
f <- function(x) {x-3.7} # \sum f(ti) wi ~ 0
g <- list(f=f) ; #define constraint as a list
kmc.solve(x, d, g) ; #using default
kmc.solve(x, d, g, using.C=TRUE) ; #using Rcpp
#################
# dim =2
#################
myfun5 <- function( x) {
x^2-16.5
}
g <- list( f1=f,f2=myfun5) ; #define constraint as a list
re0 <- kmc.solve(x,d,g);
###################################################
# Print Estimation and other information
# with option: digits = 5
###################################################
#' Print kmc object
#'
#' @param x kmc object
#' @param digits minimal number of significant digits, see print.default.
f_print <- function(x, digits = 5){
cat("\n----------------------------------------------------------------\n")
cat("A Recursive Formula for the Kaplan-Meier Estimator with Constraint\n")
cat("Information:\n")
cat("Number of Constraints:\t", length(x$g), "\n")
cat("lamda(s):\t", x$lambda,'\n');
cat("\n----------------------------------------------------------------\n")
names <- c("Log-likelihood(Ha)", "Log-likelihood(H0)",
"-2LLR", paste("p-Value(df=", length(x$g), ")",sep = ""))
re <- matrix(c(x[[1]], x[[2]], x[[3]], 1 - pchisq(x[[3]],
length(x$g))), nrow = 1)
colnames(re) <- names
rownames(re) <- "Est"
print.default(format(re, digits = digits), print.gap = 2,
quote = FALSE, df = length(x$g))
cat("------------------------------------------------------------------\n")
}
f_print(re0)
Run the code above in your browser using DataLab