fls: Flexible Least Squares

Description Usage Arguments Examples

Description

The Kalaba-Tesfatsion Flexible Least Squares method. Numbered equations refer to the paper: R. Kalaba and L. Tesfatsion, Time-Varying Linear Regression Via Flexible Least Squares, Computers and Mathematics with Applications, Vol. 17 (1989), pp. 1215-1245.

Usage

1
fls(A, b, mu = 1, ncap = length(b))

Arguments

A
b
mu
ncap

Examples

 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
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (A, b, mu=1, ncap=length(b))
{
  m <- nrow (A)
  n <- ncol (A)
  M <- array (0,c(n,n,ncap))
  E <- array (0,c(n,ncap))
  X <- array (0,c(n,ncap))
  R <- matrix(0,n,n)
  diag(R) <- diag(R) + mu
  for (j in 1:ncap) {
    Z <- solve(qr(R + tcrossprod(A[j,]),LAPACK=TRUE),diag(1.0,n));
    M[,,j] <- mu*Z             # (5.7b)
    v <- b[j]*A[j,]
    if(j==1) p <- rep(0,n)
    else p <- mu*E[,j-1]
    w <- p + v
    E[,j] <- Z %*% w           # (5.7c)
    R <- -mu*mu*Z
    diag(R) <- diag(R) + 2*mu
  }
# Calculate eqn (5.15) FLS estimate at ncap
  Q <- -mu*M[,,ncap-1]
  diag(Q) <- diag(Q) + mu
  Ancap <- A[ncap,,drop=FALSE]
  C <- Q + t(Ancap) %*% Ancap
  d <- mu*E[,ncap-1,drop=FALSE] + b[ncap]*t(Ancap)
  X[,ncap] <- C %*% d
  X[,ncap] <- solve(qr(C,LAPACK=TRUE),d)
# Use eqn (5.16) to obtain smoothed FLS estimates for 
# X[,1], X[,2], ..., X[,ncap-1]
  for (j in 1:(ncap-1)) {
    l <- ncap - j
    X[,l] <- E[,l] + M[,,l] %*% X[,l+1]
  }
  X
  }

bwlewis/fls documentation built on May 13, 2019, 9:06 a.m.

Related to fls in bwlewis/fls...