Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contrast matrices for trend test not square #296

Open
microbemarsh opened this issue Nov 19, 2024 · 1 comment
Open

Contrast matrices for trend test not square #296

microbemarsh opened this issue Nov 19, 2024 · 1 comment

Comments

@microbemarsh
Copy link

microbemarsh commented Nov 19, 2024

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))
@YuZhang-learner
Copy link

I had the same problem. Expect someone to answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants