ANCOMBC icon indicating copy to clipboard operation
ANCOMBC copied to clipboard

Contrast matrices for trend test not square

Open microbemarsh opened this issue 1 year ago • 1 comments

The error copied seems to be popping up after using the code adapted from the tutorial. ANCOMBC (v2.6) works for other variables with the same phyloseq object however this variable is causing issues. I've been using this ANCOMBC for a while now and have not had this issue before. Thank you!

Error: The contrast matrices for the trend test should be square matrices with dimension #group - 1 
The number of groups in current data is: 5

The code I ran

# Read in phyloseq for ancombc
tse <- mia::makeTreeSummarizedExperimentFromPhyloseq(good_ps)

# Subset to times if needed
tse = tse[, tse$Timepoint %in% c("BA", "7dpi1", "PRE", "POST", "5dpi2")]

# To manually change the reference level, for instance, setting `BA`
# as the reference level, use:
tse$Timepoint = factor(tse$Timepoint, levels = c("BA", "7dpi1", "PRE", "POST", "5dpi2"))

# set seed for ancombc
set.seed(123)

# run ancombc
output3 <- ancombc2(data = tse, assay_name = "counts", tax_level = "Genus",
                    fix_formula = "Timepoint", rand_formula = NULL,
                    p_adj_method = "holm", pseudo_sens = TRUE,
                    prv_cut = 0.1, lib_cut = 10000, s0_perc = 0.05,
                    group = "Timepoint", struc_zero = TRUE, neg_lb = TRUE,
                    alpha = 0.05, n_cl = 2, verbose = TRUE,
                    global = TRUE, pairwise = TRUE, dunnet = TRUE, trend = TRUE,
                    iter_control = list(tol = 1e-2, max_iter = 20, 
                                        verbose = TRUE),
                    em_control = list(tol = 1e-5, max_iter = 100),
                    lme_control = lme4::lmerControl(),
                    mdfdr_control = list(fwer_ctrl_method = "holm", B = 100),
                    trend_control = list(contrast = list(matrix(c(1, 0, -1, 1),
                                                                nrow = 2, 
                                                                byrow = TRUE),
                                                         matrix(c(-1, 0, 1, -1),
                                                                nrow = 2, 
                                                                byrow = TRUE),
                                                         matrix(c(1, 0, 1, -1),
                                                                nrow = 2, 
                                                                byrow = TRUE)),
                                         node = list(2, 2, 1),
                                         solver = "ECOS",
                                         B = 100))

microbemarsh avatar Nov 19 '24 18:11 microbemarsh

I had the same problem. Expect someone to answer.

YuZhang-learner avatar Dec 06 '24 02:12 YuZhang-learner