adibender / pammtools
Showing 1 of 1 files from the diff.
Newly tracked file
R/penalize-laglead.R created.

@@ -0,0 +1,53 @@
Loading
1 +
smooth.construct.fdl.smooth.spec <- function(object, data, knots) {
2 +
  
3 +
  # modify object so that it's fitted as a p-spline signal regression term:
4 +
  object$bs <- "ps"
5 +
  object <- smooth.construct.ps.smooth.spec(object, data, knots)
6 +
  
7 +
  if (!is.null(object$xt$fullrankpen) && object$xt$fullrankpen) {
8 +
    # add ridge penalty to first <order of B-spline>+1 (=m+2) basis functions with
9 +
    # same variance as difference penalty : penalty = lambda * coef' (DiffPen +
10 +
    # RidgePen) coef
11 +
    object$S[[1]][cbind(1:(object$m[1] + 2), 1:(object$m[1] + 2))] <- object$S[[1]][cbind(1:(object$m[1] + 2),
12 +
                                                                                          1:(object$m[1] + 2))] + 1
13 +
    object$rank <- min(object$bs.dim, object$rank + object$m[1] + 2)
14 +
  }
15 +
  if (!is.null(object$xt$ridge) && object$xt$ridge) {
16 +
    # add lag-lead penalty to first and last <order of B-spline>+1 (=m+2) basis functions penalty
17 +
    # = coef' (lambda_1*DiffPen + lambda_2*LagLeadPen) coef
18 +
    if (!is.null(object$xt$leadpen) && !is.null(object$xt$lagpen) && object$xt$leadpen && object$xt$lagpen) {
19 +
      object$S[[2]] <- matrix(0, object$bs.dim, object$bs.dim)
20 +
      # penalize lead
21 +
      object$S[[2]][cbind(1:(object$m[1] + 2), 1:(object$m[1] + 2))] <- 1
22 +
      # penalize lag
23 +
      object$S[[2]][cbind((object$bs.dim - (object$m[1] + 2) + 1): object$bs.dim, 
24 +
                          (object$bs.dim - (object$m[1] + 2) + 1): object$bs.dim)] <- 1
25 +
      
26 +
      object$rank <- c(object$rank, min(2*(object$m[1] + 2), object$bs.dim))
27 +
    }
28 +
    else if (!is.null(object$xt$leadpen) && object$xt$leadpen) {
29 +
      # add ridge penalty (lead penalty) to first <order of B-spline>+1 (=m+2) basis functions penalty
30 +
      # = coef' (lambda_1*DiffPen + lambda_2*RidgePen) coef
31 +
      object$S[[2]] <- matrix(0, object$bs.dim, object$bs.dim)
32 +
      object$S[[2]][cbind(1:(object$m[1] + 2), 1:(object$m[1] + 2))] <- 1
33 +
      object$rank <- c(object$rank, object$m[1] + 2)
34 +
    } 
35 +
    else if (!is.null(object$xt$lagpen) && object$xt$lagpen) {
36 +
      # add lag penalty to last <order of B-spline>+1 (=m+2) basis functions penalty
37 +
      # = coef' (lambda_1*DiffPen + lambda_2*LagPen) coef
38 +
      object$S[[2]] <- matrix(0, object$bs.dim, object$bs.dim)
39 +
      object$S[[2]][cbind((object$bs.dim - (object$m[1] + 2) + 1): object$bs.dim, 
40 +
                          (object$bs.dim - (object$m[1] + 2) + 1): object$bs.dim)] <- 1
41 +
      object$rank <- c(object$rank, object$m[1] + 2)
42 +
    } 
43 +
  }
44 +
  if (!is.null(object$xt$constrain) && object$xt$constrain) {
45 +
    # constrain to end in zero (i.e (X%*%coefficients)[1] == 0) -->
46 +
    # Constraint matric C = X[1,]
47 +
    object$C <- matrix(object$X[1, ], nrow = 1)
48 +
    object$C <- structure(object$C, always.apply = TRUE)
49 +
  }
50 +
  
51 +
  return(object)
52 +
  
53 +
}
Files Coverage
R 91.94%
Project Totals (28 files) 91.94%
Notifications are pending CI completion. Periodically Codecov will check the CI state, when complete notifications will be submitted. Push notifications now.
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
    patch:
10
      default:
11
        target: auto
12
        threshold: 1%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading