Skip to content

Commit

Permalink
fix major issue with re-ordering of dii and f vectors
Browse files Browse the repository at this point in the history
  - 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
  • Loading branch information
matthewwolak committed May 17, 2024
1 parent b1233a3 commit a410517
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions R/makeAinv.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions R/makeTinvDF.R
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit a410517

Please sign in to comment.