From a410517bf76be2fbead3be746f3729dcbe488a04 Mon Sep 17 00:00:00 2001 From: matthew Date: Fri, 17 May 2024 15:20:24 -0500 Subject: [PATCH] fix major issue with re-ordering of dii and f vectors - caused major issues and errors in makeA relatedness matrices - reason was code tried to transpose perm vector of a permutation matrix instead of using invPerm - permutation matrices class "pMatrix" have perm slot as EITHER row index or column index vector - converting perm slot from row to column index vectors (or vice versa) requires usinv invPerm and NOT transposing matrix then taking perm slot - note this is not an issue where makeAinv.fuzzy() reorders f and dii vectors because the fsOrd1 matrix is not a pMatrix but ngCMatrix --- R/makeAinv.R | 8 ++++---- R/makeTinvDF.R | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/R/makeAinv.R b/R/makeAinv.R index 5a3c1fa..e5b3da0 100644 --- a/R/makeAinv.R +++ b/R/makeAinv.R @@ -294,12 +294,12 @@ makeAinv.default <- function(pedigree, f = NULL, Ainv <- crossprod(fsOrd, Ainv) %*% fsOrd if(ptype == "D"){ Ainv@Dimnames <- list(as.character(pedalt[, 1]), NULL) - f <- Cout[[3]][t(fsOrd)@perm][-seq(nggroups)] - dii <- Cout[[4]][t(fsOrd)@perm][-seq(nggroups)] + f <- Cout[[3]][invPerm(fsOrd@perm)][-seq(nggroups)] + dii <- Cout[[4]][invPerm(fsOrd@perm)][-seq(nggroups)] } else { Ainv@Dimnames <- list(as.character(pedigree[, 1]), NULL) - f <- c(rep(0, nggroups), Cout[[3]][t(fsOrd)@perm][(nggroups+1):(nggroups + eN)]) - dii <- c(rep(0, nggroups), Cout[[4]][t(fsOrd)@perm][(nggroups+1):(nggroups + eN)]) + f <- c(rep(0, nggroups), Cout[[3]][invPerm(fsOrd@perm)][(nggroups+1):(nggroups + eN)]) + dii <- c(rep(0, nggroups), Cout[[4]][invPerm(fsOrd@perm)][(nggroups+1):(nggroups + eN)]) } if(!is.null(ggroups) && !gOnTop){ permute <- as(as.integer(c(seq(eN+1, N, 1), seq(eN))), "pMatrix") diff --git a/R/makeTinvDF.R b/R/makeTinvDF.R index 41bac9b..49be78b 100644 --- a/R/makeTinvDF.R +++ b/R/makeTinvDF.R @@ -229,8 +229,8 @@ makeDiiF.default <- function(pedigree, f = NULL, ...){ as.integer(0), #number genetic groups as.integer(fmiss - 1)) #first f to calculate (not supplied) fsOrd <- as(as.integer(renPed), "pMatrix") - f <- Cout[[3]][t(fsOrd)@perm] - dii <- Cout[[4]][t(fsOrd)@perm] + f <- Cout[[3]][invPerm(fsOrd@perm)] + dii <- Cout[[4]][invPerm(fsOrd@perm)] return(list(D = Diagonal(x = dii, n = N), @@ -265,8 +265,8 @@ makeDiiF.numPed <- function(pedigree, f = NULL, ...){ as.integer(0), #number genetic groups as.integer(fmiss)) #first f to calculate (not supplied) fsOrd <- as(as.integer(renPed), "pMatrix") - f <- Cout[[3]][t(fsOrd)@perm] - dii <- Cout[[4]][t(fsOrd)@perm] + f <- Cout[[3]][invPerm(fsOrd@perm)] + dii <- Cout[[4]][invPerm(fsOrd@perm)] return(list(D = Diagonal(x = dii, n = N),