Unit 19 Psi weights with AR models:

\[\psi_0 = 1\] \[\psi_1 = \phi_1\] \[\psi_2 = \phi_1 \psi_1 +\phi_2\] \[\psi_3 = \phi_1 \psi_2 + \phi_2 \psi_1 + \phi_3\] \[\psi_\ell = \sum_{i =1} ^p \phi_i \psi_{\ell - i}\]

multfun <- function(phi, l, psi) {
    sum(phi[1:l] * psi[1:l])
}
phitest <- function(phi, l) {
    if (l > length(phi)) {
        return(append(phi, rep(0, l - length(phi))))
    } else {
        return(phi)
    }
}
arpsiweights <- function(phi, theta = as.numeric(0), l) {
    phi <- phitest(phi, l)
    psi <- as.numeric(1)
    for (i in 2:l) {
        psi[i] <- multfun(phi, i - 1, rev(psi))
    }
    psi
}

19.1 Psi weights for ARMA

\[\psi_0 = 1\] \[\psi_1 = \phi_1 - \theta_1\] \[\psi_2 = \phi_1 \psi_1 +\phi_2 - \theta_2\] \[\psi_3 = \phi_1 \psi_2 + \phi_2 \psi_1 + \phi_3 -theta_3\] \[\psi_\ell = \sum_{i =1} ^p \phi_i \psi_{\ell - i} - \theta_i\]

psiweights <- function(phi, theta = as.numeric(0), l) {
    phi <- phitest(phi, l)
    psi <- as.numeric(1)
    theta <- c(0, theta)
    theta <- phitest(theta, l)
    for (i in 2:l) {
        psi[i] <- multfun(phi, i - 1, rev(psi)) - theta[i]
    }
    psi
}