famuvie / breedR

Statistical methods for forest genetic resources analysts
http://famuvie.github.io/breedR/
GNU General Public License v3.0
31 stars 24 forks source link

parse large covariance matrices from REML log #101

Closed famuvie closed 5 years ago

famuvie commented 5 years ago
library(breedR)
#> Loading required package: sp
tdat <- data.frame(replicate(n = 10, rnorm(1e2)))
res <- remlf90(
  cbind(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10) ~ 1,
  data = tdat,
  method = "ai"
)
#> Using default initial variances given by default_initial_variance()
#> See ?breedR.getOption.
#> Error in (function (x, names = NULL, square = TRUE) : Could not figure out square matrix dimensions.

Created on 2019-02-04 by the reprex package (v0.2.1)

famuvie commented 5 years ago

The problem is that the REML log is a text file with fixed width. Whenever a covariance matrix is large enough it gets line-wrapped, and the parsing algorithm fails to gather it entirely. In this case, it gets the first 10 lines, because it knows that the matrix has 10 rows.

famuvie commented 5 years ago

I need to parse matrices more robustly, accounting for the fact that there can be line-wrapping. This implies detecting the full block of numerical lines, and checking that its size is a multiple of the expected matrix size.