lhe17 / nebula

GNU General Public License v2.0
28 stars 6 forks source link

Getting error - "dimension of 'A' must be at least 3" #33

Open Yifath7 opened 1 year ago

Yifath7 commented 1 year ago

Hey, I'm trying to use NEBULA on a scRNA Seura object and ask questions about the difference between males and females. I created the design matrix to contain only the intercept and a vector of 1, 0 to indicate if the subject is male. I have around 200 subjects, with corresponding IDs that I provide in the ID input parameter.

I run the HL model and with reml = 1 as some individuals don't have the best cell count.

However, I get the following error:

Error in { : task 1 failed - "dimension of 'A' must be at least 3"

What could be the reason for the error?

Thanks in advance, Yifat

lhe17 commented 1 year ago

Hi Yifat,

Thank you for your question. This error is new to me and I have not seen it before. So, I need more information to determine what's going wrong. Does this error occur only when you run with reml = 1, or it occurs with reml = 0 or method='LN'? Does it happen to a specific gene or no matter how many genes you have in the count matrix?

Just for your information, you could just use reml=0 if you have 200 subjects to estimate only two variables. Using reml=1 will not give very different results in this case.

Best regards, Liang

On Wed, Aug 23, 2023 at 10:42 AM Yifath7 @.***> wrote:

Hey, I'm trying to use NEBULA on a scRNA Seura object and ask questions about the difference between males and females. I created the design matrix to contain only the intercept and a vector of 1, 0 to indicate if the subject is male. I have around 200 subjects, with corresponding IDs that I provide in the ID input parameter.

I run the HL model and with reml = 1 as some individuals don't have the best cell count.

However, I get the following error:

Error in { : task 1 failed - "dimension of 'A' must be at least 3"

What could be the reason for the error?

Thanks in advance, Yifat

— Reply to this email directly, view it on GitHub https://github.com/lhe17/nebula/issues/33, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGDISUS7CVQKX7VQIOQQ5DDXWYJGZANCNFSM6AAAAAA33S7CEE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Yifath7 commented 1 year ago

Hey, Thanks for the quick response. Indeed, I've experimented with various combinations of input parameters for the function, including different methods, models, and reml. Yet I keep raising this particular error.

Regarding your second question, I don't explicitly specify genes. I provide the function with the count matrix from seurat and the grouped data by group_cell as shown in the following code:

predobj = model.matrix(~sex, data = obj@meta.data)
data_g <- group_cell(obj@assays$SCT@counts, id=obj$projid, pred = predobj)
re = nebula(data_g$count,id=data_g$id,pred=data_g$pred)

The follwoing lines are printed to the console when I run with a subset of the orignial object:

Remove  4384  genes having low expression.
Analyzing  15487  genes with  102  subjects and  8027  cells.

So it does remove the genes with low expression.

Thanks again. Bests, Yifat

lhe17 commented 1 year ago

Hi Yifat,

Thank you for your additional information. I want to replicate and investigate this issue. Could you please first check which gene is responsible for the error by doing the following

for(k in 1:nrow(data_g$count)) {

check only those genes with CPC>0.005

if(mean(data_g$count[k,]) > 0.005)

{re = nebula(data_g$count[k,],id=data_g$id,pred=data_g$pred)}

} When the program stops with the error, 'k' will tell you the index of the problematic gene. Then, could you please share me with this gene, data_g$count[k,], along with data_g$id, and data_g$pred, so that I can investigate the issue. If every single gene passes or fails, then you might check whether your count matrix is a sparse matrix or matrix object with non-negative integers.

Best regards, Liang

On Thu, Aug 24, 2023 at 4:59 AM Yifath7 @.***> wrote:

Hey, Thanks for the quick response. Indeed, I've experimented with various combinations of input parameters for the function, including different methods, models, and reml. Yet I keep raising this particular error.

Regarding your second question, I don't explicitly specify genes. I provide the function with the count matrix from seurat and the grouped data by group_cell as shown in the following code:

predobj = model.matrix(~sex, data = @.)data_g <- @*.**@*.***, id=obj$projid, pred = predobj)re = nebula(data_g$count,id=data_g$id,pred=data_g$pred)

The follwoing lines are printed to the console when I run with a subset of the orignial object:

Remove 4384 genes having low expression. Analyzing 15487 genes with 102 subjects and 8027 cells.

So it does remove the genes with low expression.

Thanks again. Bests, Yifat

— Reply to this email directly, view it on GitHub https://github.com/lhe17/nebula/issues/33#issuecomment-1691289019, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGDISUQFYMM4MNUQK74L5LLXW4JVXANCNFSM6AAAAAA33S7CEE . You are receiving this because you commented.Message ID: @.***>

Yifath7 commented 1 year ago

Thank you again.

Well, it is not all of the genes but it is definitley many. It is a sparsse matrix, I guess. Many genes, many cells. Do you have any idea how to proceed?

Best regards, Yifat

lhe17 commented 1 year ago

Hi Yifat,

If you share your count matrix, design matrix and subject IDs, I'm willing to check what is going wrong.

Best regards, Liang

On Mon, Aug 28, 2023 at 10:21 AM Yifath7 @.***> wrote:

Thank you again.

Well, it is not all of the genes but it is definitley many. It is a sparsse matrix, I guess. Many genes, many cells. Do you have any idea how to proceed?

Best regards, Yifat

— Reply to this email directly, view it on GitHub https://github.com/lhe17/nebula/issues/33#issuecomment-1695789422, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGDISURA7TUF6SZVY6VEZN3XXSSNJANCNFSM6AAAAAA33S7CEE . You are receiving this because you commented.Message ID: @.***>

TheAustinator commented 1 year ago

I'm having this issue as well. I can't share my counts matrix, but my formula is a single subject-level parameter. Here are my other params: method="HL", model="NBGMM", reml=0, ncore=64, verbose=TRUE, and I'm using total_counts as my offset Tomorrow I can post more about my environment and whether there are any parameters that don't cause this issue

lhe17 commented 1 year ago

Hi Austin and Yifat,

Thank you very much for your additional information. I have replicated this error on my side, and have figured out the problem. This bug was first introduced in v1.4.2 when I utilize an R package "RSpectra" to call eigenvalues. I now notice that this package only works for a matrix that has at least three columns. So, if the design matrix has only two columns, this package gives an error.

I'll fix this bug in the upcoming v1.5.0, which will be published next week.

Best regards, Liang

On Fri, Sep 1, 2023 at 4:42 AM Austin McKay @.***> wrote:

I'm having this issue as well. I can't share my counts matrix, but my formula is a single subject-level parameter. Here are my other params: method="HL", model="NBGMM", reml=0, ncore=64, verbose=TRUE, and I'm using total_counts as my offset Tomorrow I can post more about my environment and whether there are any parameters that don't cause this issue

— Reply to this email directly, view it on GitHub https://github.com/lhe17/nebula/issues/33#issuecomment-1702388309, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGDISUQJIRGQBPWJ3PCWNBDXYGNXXANCNFSM6AAAAAA33S7CEE . You are receiving this because you commented.Message ID: @.***>

TheAustinator commented 1 year ago

Great -- thanks, Liang! And thanks for such a prompt response.

So using v1.4.1 should be a good solution in the meantime?

One other question that this raises -- my formula had simply been "~condition", and I'd assumed "id" and "offset" would be added by the nebula function later since they're arguments (id as a random effect?). Is this the correct way to use it?

Cheers, Austin

TheAustinator commented 1 year ago

Downgrade worked! 🙏 🙌

lhe17 commented 1 year ago

Hi Austin,

Thank you for your confirmation. I just uploaded v1.5.0, which fixes this bug.

Regarding your question, "my formula had simply been "~condition", and I'd assumed "id" and "offset" would be added by the nebula function later since they're arguments (id as a random effect?). Is this the correct way to use it?", Yes, this is the correct way to use it. "id" and "offset" should not be included in the design matrix as they are specified in the separate arguments.

Best regards, Liang

On Sat, Sep 2, 2023 at 8:41 PM Austin McKay @.***> wrote:

Downgrade worked! 🙏 🙌

— Reply to this email directly, view it on GitHub https://github.com/lhe17/nebula/issues/33#issuecomment-1703974349, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGDISUXGBFRYINGWJM6Z46TXYPG33ANCNFSM6AAAAAA33S7CEE . You are receiving this because you commented.Message ID: @.***>