File: readMoments.R

package info (click to toggle)
r-cran-sem 3.1.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 936 kB
  • sloc: ansic: 2,241; cpp: 1,646; sh: 4; makefile: 2
file content (22 lines) | stat: -rw-r--r-- 709 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# last modified 2014-10-27 by J. Fox

read.moments <- function(...){
	.Deprecated("readMoments", package="sem")
	readMoments(...)
}

readMoments <- function(file="", text, diag=TRUE, 
        names=as.character(paste("X", 1:n, sep=""))){
    elements <- if (!missing(text)) scan(text=text) else scan(file=file)
    m <- length(elements)
    d <- if (diag) 1 else -1
    n <- floor((sqrt(1 + 8*m) - d)/2)
    if (m != n*(n + d)/2) 
        stop("wrong number of elements (cannot make square matrix)")
    if (length(names) != n) stop("wrong number of variable names")
    X <- diag(n)
    X[upper.tri(X, diag=diag)] <- elements
    rownames(X) <- colnames(X) <- names
    t(X)
    }