@@ -572,12 +572,25 @@ testNhoods <- function(x, design, design.df, kinship=NULL,
572572 " SE" = unlist(lapply(lapply(fit , `[[` , " SE" ), function (x ) x [ret.beta ])),
573573 " tvalue" = unlist(lapply(lapply(fit , `[[` , " t" ), function (x ) x [ret.beta ])),
574574 " PValue" = unlist(lapply(lapply(fit , `[[` , " PVALS" ), function (x ) x [ret.beta ])),
575- matrix (unlist(lapply(fit , `[[` , " Sigma" )), ncol = length(rand.levels ), byrow = TRUE ),
576575 " Converged" = unlist(lapply(fit , `[[` , " converged" )), " Dispersion" = unlist(lapply(fit , `[[` , " Dispersion" )),
577576 " Logliklihood" = unlist(lapply(fit , `[[` , " LOGLIHOOD" )))
578577
579- rownames(res ) <- 1 : length(fit )
580- colnames(res )[6 : (6 + length(rand.levels )- 1 )] <- paste(names(rand.levels ), " variance" , sep = " _" )
578+ # need to know how many variance components there are to get proper data frame dimensions
579+ n.sigmas <- unique(unlist(lapply(lapply(fit , `[[` , " Sigma" ), length )))
580+ varcomps <- as.data.frame(matrix (unlist(lapply(fit , `[[` , " Sigma" )), ncol = n.sigmas , byrow = TRUE ))
581+
582+ if (n.sigmas == length(rand.levels )){
583+ colnames(varcomps ) <- paste(names(rand.levels ), " variance" , sep = " _" )
584+ } else {
585+ colnames(varcomps ) <- paste(c(names(rand.levels ), " CovarMat" ), " variance" , sep = " _" )
586+ }
587+
588+ res <- do.call(cbind.data.frame , list (res [, c(" logFC" , " logCPM" , " SE" , " tvalue" , " PValue" )],
589+ varcomps ,
590+ res [, c(" Converged" , " Logliklihood" )]))
591+
592+ rownames(res ) <- c(1 : n.nhoods )
593+ # colnames(res)[6:(6+length(rand.levels)-1)] <- paste(names(rand.levels), "variance", sep="_")
581594 } else {
582595 # need to use legacy=TRUE to maintain original edgeR behaviour
583596 fit <- glmQLFit(dge , x.model , robust = robust , legacy = TRUE )
0 commit comments