R/coef.R

Defines functions coef.L0TFinvopt coef.L0TFinvfix

Documented in coef.L0TFinvfix coef.L0TFinvopt

#' @title Extract estimated trends
#' @description Extract the coefficients of the estimated trends under the constraint of a given number of change points.
#' @param object The output of L0TFinvfix or L0TFinvopt
#' @param k The given number of change points
#' @param ... ignore
#' @return Estimated parameters and trends for L0TFinvfix or L0TFinvopt models with specified numbers of change points
#' @method coef L0TFinvfix
#' @seealso \code{\link{print.L0TFinvfix}}
#' @export
coef.L0TFinvfix <- function(object, k=NULL, ...) {
  if(is.null(k)){
    return(list(A.all=object$A.all,beta.all=object$beta.all,y.all=object$y.all))
  }else{
    if(k > ncol(object$beta.all)){
      stop("The number of given change points exceeds the maximum range")
    }else{
      return(list(A=object$A.all[[k]],beta=object$beta.all[,k],yhat=object$y.all[,k]))
    }
  }
}

#' @rdname coef.L0TFinvfix
#' @method coef L0TFinvopt
#' @export
coef.L0TFinvopt <- function(object, k=NULL, ...) {
  if(is.null(k)){
    return(list(A.all=object$A.all,beta.all=object$beta.all,y.all=object$y.all))
  }else{
    if(k > ncol(object$beta.all)){
      stop("The number of given change points exceeds the maximum range")
    }else{
      return(list(A=object$A.all[[k]],beta=object$beta.all[,k],yhat=object$y.all[,k]))
    }
  }
}

Try the L0TFinv package in your browser

Any scripts or data that you put into this service are public.

L0TFinv documentation built on June 10, 2025, 5:14 p.m.