Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

umx_read_lower

Read lower-triangle of data matrix from console or file


Description

umx_read_lower will read a lower triangle of data, either from the console, or from file, and return a full matrix, optionally coerced to positive definite. This is useful, especially when copying data from a paper that includes just the lower triangle of a correlation matrix.

Usage

umx_read_lower(file = "", diag = TRUE, names = NULL, ensurePD = FALSE)

Arguments

file

Path to a file to read (Default "" will read from user input)

diag

Whether the data include the diagonal. Defaults to TRUE

names

The default names for the variables. Defaults to as.character(paste("X", 1:n, sep=""))

ensurePD

Whether to coerce the resultant matrix to positive definite (Defaults to FALSE)

Value

References

See Also

Examples

## Not run: 
require(umx) # for umxRAM
IQtests = c("brainstorm", "matrix", "moral", "shopping", "typing")
allCols = c("C", IQtests, "avgIQ", "maxIQ", "video")

df = umx_read_lower(diag = FALSE, names = allCols)
0.38
0.86	0.30
0.42	0.12	0.27
0.66	0.21	0.38	0.18
0.80	0.13	0.50	0.25	0.43
0.19	0.11	0.19	0.12	-0.06	0.22
0.27	0.09	0.33	0.05	-0.04	0.28	.73
0.52	0.17	0.38	0.37	0.39	0.44	0.18	0.13

dimnames(df) = list(allCols, allCols) # manually add

df = umx_read_lower(file = "", diag = FALSE, names = allCols, ensurePD= TRUE)
0.38
0.86	0.30
0.42	0.12	0.27
0.66	0.21	0.38	0.18
0.80	0.13	0.50	0.25	0.43
0.19	0.11	0.19	0.12	-0.06	0.22
0.27	0.09	0.33	0.05	-0.04	0.28	.73
0.52	0.17	0.38	0.37	0.39	0.44	0.18	0.13


round(df, 2) 

m1 = umxRAM("wooley", data = mxData(df, type="cov", numObs = 90),
	umxPath("g", to = IQtests),
	umxPath(var = "g", fixedAt= 1),
	umxPath(var = IQtests)
)
summary(m1)

## End(Not run)

umx

Structural Equation Modeling and Twin Modeling in R

v4.10.10
GPL-3
Authors
Timothy C. Bates [aut, cre] (<https://orcid.org/0000-0002-1153-9007>), Gillespie Nathan [wit], Michael Zakharin [wit], Brenton Wiernik [ctb], Joshua N. Pritikin [ctb], Michael C. Neale [ctb], Hermine Maes [ctb]
Initial release
2021-11-30

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.