Skip to content

Commit

Permalink
Fixed issue with wrong random effects matrix in GetOLRE
Browse files Browse the repository at this point in the history
when random effects include variables not in fixed effects, previously failed to recover the proper values when RE = "all"
  • Loading branch information
Jon Lefcheck committed Dec 2, 2022
1 parent 2e4b612 commit f95e22e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions R/helpers.R
Original file line number Diff line number Diff line change
@@ -422,15 +422,21 @@ GetOLRE <- function(sigma, model, X, data, RE = c("all", "RE", "OLRE")) {

sum(rowSums(Z %*% i) * Z) / nrow(X.)

} ) } } else if(RE == "all")
} ) } } else if(RE == "all") {

if(all(rownames(i) %in% colnames(X))) X. <- X else

X. <- do.call(cbind, model.matrix(model, type = "randomListRaw"))

out <- sapply(sigma, function(i) {

Z <- as.matrix(X.[, rownames(i), drop = FALSE])

sum(rowSums(Z %*% i) * Z) / nrow(X.)

} )
} )

}

if(length(out) == 0) out <- 0

0 comments on commit f95e22e

Please sign in to comment.