-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerics.R
45 lines (40 loc) · 1.25 KB
/
generics.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#' Generic
#'
#' @param object An object of class lmcp
#' @export
print.lmcp <- function(object, ...){
stats:::print.lm(object, ...)
cat(paste0("Change-point fitted at ", object$cp_var, "=", object$change_point,
" with slope ", signif(object$cp_coefficients[1, 1], 5), " before and ",
signif(object$cp_coefficients[2, 1], 5), " after.")
)
}
#' Generic
#'
#' @param object An object of class lmcp
#' @export
summary.lmcp <- function(object, ...){
sum_fit <- stats:::summary.lm(object, ...)
sum_fit$cp_coefficients <- object$cp_coefficients
sum_fit$cp_var <- object$cp_var
sum_fit$change_point <- object$change_point
class(sum_fit) <- c("summary.lmcp", "summary.lm")
sum_fit
}
#' Generic
#'
#' @param object An object of class summary.lmcp
#' @export
print.summary.lmcp <- function(object, ...){
stats:::print.summary.lm(object, ...)
cat(paste0("\nOptimal change-point found at ", object$cp_var, "=", object$change_point, ", with coefficients: \n"))
printCoefmat(object$cp_coefficients)
}
#' Generic
#'
#' @param object An object of class lmcp_pvalue
#' @export
print.lmcp_pvalue <- function(object, ...){
cat(paste("Approximate P-value based on", attr(object, "n_sim"), "Monte-Carlo iterations:\n", as.numeric(object)
))
}