0
$\begingroup$

I'm trying to run the Non-Negative Matrix Factorization(NMF) for my Gene Expression dataset which was originally in matrix form. But it throws errors as given below:

expr <- read_excel("./expr.xlsx")
expr<- as.matrix(expr)

#removing the first column containing gene symbols before clustering
expr_rm <- expr[,-1]
class(expr_rm)
[1] "matrix" "array" 

So converted these expr_rm to numeric:

expr_rm <- as.numeric(expr_rm)

#removing negative values for running NMF
eps <- .Machine$double.eps
expr_rm[expr_rm<=0] = eps

estimate <- NMF::nmf(expr_rm, 3, nrun = 10, method = "lee", seed = 123)

Error: NMF::nmf - 10/10 fit(s) threw an error. Error(s) thrown: run #1: 'x' must be numeric Timing stopped at: 1.95 0.14 4.4*

cluster <- cbind(names(NMF::predict(estimate)), NMF::predict(estimate))

Error in h(simpleError(msg, call)) : error in evaluating the argument 'object' in selecting a method for function 'predict': object 'estimate' not found

result <- list(estimate, cluster)

Error: object 'estimate' not found

For clarity, my expr_rm has row indices as 1, 2, 3, 4,.. which indicates different genes and column headings as samples.

Please suggest a solution for this soon!

Additional information (requested from comments):

>summary(expr_rm) - before conversion 
 Sample_C44_0001.genes.results Sample_C44_0002.genes.results Sample_C44_0003.genes.results Sample_C44_0005.genes.results 
 Length:145   Length:145 Length:145  Length:145  Class :character

 > summary(expr_rm) - after numeric type conversion
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  0.000   1.808   4.264   4.220   6.333  16.246

If in expr_rm is data.matrix() also, it gives the error like:

> median_centered_data<- expr_rm - med
Error in expr_rm - med : non-numeric argument to binary operator 
$\endgroup$
0
0
$\begingroup$

Answer from @maximilian-press, converted from comment:

Sometimes casting to as.numeric() will convert from two-dimensional matrix to one-dimensional vector. Based on the output you put into comments (which would be helpful in the question), I wonder if this has occurred and caused an issue. For data.matrix, I suggest reading docs for that function- it should have returned only numeric, such that your med variable is likely not numeric, or there is a problem with your data. Possibly the tidyverse tibble created by read_excel might be the issue. I don't know enough tidyverse to say what exactly is going on.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.