File: lagImpactMat.R

package info (click to toggle)
r-cran-xtable 1%3A1.8-2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,060 kB
  • sloc: sh: 19; makefile: 1
file content (44 lines) | stat: -rw-r--r-- 1,465 bytes parent folder | download
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
42
43
44
### This function is a copy of spdep:::lagImpactMat
### It has been copied because lagImpactMat is not exported by spdep
### There is no help available for lagImpactMat in spdep,
### so I have not provided any help, and I am unable to trace the author
###
lagImpactMat <- function (x, reportQ = NULL) 
{
  if (is.null(x$res)) {
    direct <- x$direct
    indirect <- x$indirect
    total <- x$total
  } else {
    direct <- x$res$direct
    indirect <- x$res$indirect
    total <- x$res$total
  }
  mat <- cbind(direct, indirect, total)
  colnames(mat) <- c("Direct", "Indirect", "Total")
  rownames(mat) <- attr(x, "bnames")
  if (!is.null(reportQ) && reportQ) {
    if (is.null(x$res)) {
      Qobj <- attr(x, "Qres")
    } else {
      Qobj <- attr(x$res, "Qres")
    }
    if (is.null(Qobj)) {
      warning("No impact components to report")
    } else {
      if (length(attr(x, "bnames")) == 1L) {
        Qobj$direct <- matrix(Qobj$direct, ncol = 1)
        Qobj$indirect <- matrix(Qobj$indirect, ncol = 1)
        Qobj$total <- matrix(Qobj$total, ncol = 1)
      }
      colnames(Qobj$direct) <- attr(x, "bnames")
      colnames(Qobj$indirect) <- attr(x, "bnames")
      colnames(Qobj$total) <- attr(x, "bnames")
      rownames(Qobj$direct) <- paste0("Q", 1:nrow(Qobj$direct))
      rownames(Qobj$indirect) <- paste0("Q", 1:nrow(Qobj$indirect))
      rownames(Qobj$total) <- paste0("Q", 1:nrow(Qobj$total))
      attr(mat, "Qobj") <- Qobj
    }
  }
  mat
}