utility.r

来自「使用R语言的马尔科夫链蒙特卡洛模拟(MCMC)源代码程序。」· R 代码 · 共 37 行

R
37
字号
########## Utility Functions ########### takes a symmetric matrix x and returns lower diagonal# note: does not check for symmetry## ADM 4/18/2003 "vech" <-  function (x) {    x <- as.matrix(x)    if (dim(x)[1] != dim(x)[2]) {      stop("Non-square matrix passed to vech().\n")    }    output <- x[lower.tri(x, diag = TRUE)]    dim(output) <- NULL    return(output)  }# takes vector x and returns an nrow times nrow symmetric matrix# this will recycle the elements of x as needed to fill the matrix## ADM 4/18/2003# ADM 11/13/2003 [bug fix]# ADM 1/25/2006 [patch to automatically compute matrix size]"xpnd" <-  function (x, nrow = NULL) {    dim(x) <- NULL    if(is.null(nrow)) nrow <- (-1 + sqrt(1 + 8 * length(x))) / 2    output <- matrix(0, nrow, nrow)    output[lower.tri(output, diag = TRUE)] <- x    hold <- output    hold[upper.tri(hold, diag=TRUE)] <- 0    output <- output + t(hold)        return(output)  }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?