R version 2.9.0 (2009-04-17) Copyright (C) 2009 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # chex44.r J F Monahan, June 2001, May 2010 > # > # likelihood computation for ARMA(1,1) model > # > # set parameter values > phi <- .9 > th <- .5 > n <- 4 > # table covariance function -- gamma(0) stored in gam[1] > gam <- rep(0,n+1) > gam[1] <- (1+th*th-2*phi*th)/(1-phi*phi) > gam[2] <- (1-phi*th)*(phi-th)/(1-phi*phi) > for(j in 3:(n+1)) gam[j] <- phi*gam[j-1] > "covariance function" [1] "covariance function" > gam [1] 1.8421053 1.1578947 1.0421053 0.9378947 0.8441053 > # Toeplitz covariance matrix > d <- 1 + abs(matrix(1:n,n,n) - t(matrix(1:n,n,n))) > A <- matrix(gam[d],n,n) > "covariance matrix" [1] "covariance matrix" > A [,1] [,2] [,3] [,4] [1,] 1.8421053 1.157895 1.042105 0.9378947 [2,] 1.1578947 1.842105 1.157895 1.0421053 [3,] 1.0421053 1.157895 1.842105 1.1578947 [4,] 0.9378947 1.042105 1.157895 1.8421053 > > "Cholesky factor" [1] "Cholesky factor" > Lt <- chol(A) > Lt [,1] [,2] [,3] [,4] [1,] 1.357242 0.8531234 0.7678111 0.6910300 [2,] 0.000000 1.0555973 0.4763721 0.4287349 [3,] 0.000000 0.0000000 1.0127394 0.4177550 [4,] 0.000000 0.0000000 0.0000000 1.0031201 > det <-prod(diag(Lt)) > "determinant" [1] "determinant" > det*det [1] 2.118421 > z <- c(-2, 1, 0, 1) > one <- rep(1,4) > LiBz <- forwardsolve(t(Lt),z) > LiBone <- forwardsolve(t(Lt),one) > zAiz <- sum( LiBz * LiBz ) > zAione <- sum( LiBz * LiBone ) > oneAione <- sum( LiBone * LiBone ) > muhat <- zAione / oneAione > "muhat" [1] "muhat" > muhat [1] -0.07971014 > "quadratic form" [1] "quadratic form" > qf <- zAiz - zAione*muhat > qf [1] 7.857101 > # clean up > rm(list=ls()) > q()