R/penalty.poly.R

Defines functions penalty.poly

Documented in penalty.poly

penalty.poly <-
  function(x, m = 2, xmin = min(x), xmax = max(x), 
           periodic = FALSE, rescale = FALSE, bernoulli = TRUE){
    # Polynomial Smoothing Spline Penalty
    # Nathaniel E. Helwig (helwig@umn.edu)
    # Update: 2021-04-09
    
    # initializations
    m <- as.integer(m)
    if(m < 1L | m > 3L) stop("Input 'm' must be 1 (linear), 2 (cubic), or 3 (quintic).")
    x <- (as.numeric(x) - xmin) / (xmax - xmin)
    
    # get kernel function name
    kerns <- c("lin", "cub", "qui")
    fname <- paste0(kerns[m], "kern", 0)
    if(!bernoulli) fname <- paste0(".", fname)
    
    # evaluate kernel function
    Q <- outer(X = x, Y = x, FUN = fname, periodic = periodic)
    
    # rescale?
    if(rescale) Q <- Q / mean(diag(Q))
    
    # return result
    return(Q)
    
  }

Try the npreg package in your browser

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

npreg documentation built on July 21, 2022, 1:06 a.m.