Error in svd (x, nu = 0): 0 emergency measurements

I am trying to make a PCA on a data frame with 5,000 columns and 30 rows

Sample <- read.table(file.choose(), header=F,sep="\t") Sample.scaled <- data.frame(apply(Sample,2,scale)) pca.Sample <- prcomp(Sample.scaled,retx=TRUE)` 

Error received

 Error in svd(x, nu = 0) : infinite or missing values in 'x' sum(is.na(Sample)) [1] 0 sum(is.na(Sample.scaled)) [1] 90 

Tried to ignore all na values ​​using the following

 pca.Sample <- prcomp(na.omit(Sample.scaled),retx=TRUE) 

What gives the following error

 Error in svd(x, nu = 0) : 0 extent dimensions 

There have been reports that na.action requires a formula to be given, and therefore tried below

 pca.Sample <- prcomp(~.,center=TRUE,scale=TRUE,Sample, na.action=na.omit) 

Now we get the following error

 Error in prcomp.default(x, ...) : cannot rescale a constant/zero column to unit variance 

Think that the problem may be that β€œone of my data columns is constant. The variance of the constant is 0, and the scaling is divisible by 0, which is impossible.”

But not sure how to handle this. Any help is much appreciated ....

+4
source share
2 answers

Judging by the fact that sum(is.na(Sample.scaled)) appears as 90 , when sum(is.na(Sample)) was 0 , it looks like you have three constant columns.

Here's a random generated (reproducible) example that gives the same error messages:

 Sample <- matrix(rnorm(30 * 5000), 30) Sample[, c(128, 256, 512)] <- 1 Sample <- data.frame(Sample) Sample.scaled <- data.frame(apply(Sample, 2, scale)) > sum(is.na(Sample)) [1] 0 > sum(is.na(Sample.scaled)) [1] 90 # constant columns are "scaled" to NA. > pca.Sample <- prcomp(Sample.scaled,retx=TRUE) Error in svd(x, nu = 0) : infinite or missing values in 'x' # 3 entire columns are entirely NA, so na.omit omits every row > pca.Sample <- prcomp(na.omit(Sample.scaled),retx=TRUE) Error in svd(x, nu = 0) : 0 extent dimensions # can't scale the 3 constant columns > pca.Sample <- prcomp(~.,center=TRUE,scale=TRUE,Sample, na.action=na.omit) Error in prcomp.default(x, ...) : cannot rescale a constant/zero column to unit variance 

You can try something like:

 Sample.scaled.2 <- data.frame(t(na.omit(t(Sample.scaled)))) pca.Sample.2 <- prcomp(Sample.scaled.2, retx=TRUE) 

i.e. use na.omit in transpose to get rid of NA columns, not rows.

+5
source

Negative infinity values ​​can be replaced after the log conversion, as shown below.

 log_features <- log(data_matrix[,1:8]) log_features[is.infinite(log_features)] <- -99999 
+2
source

Source: https://habr.com/ru/post/1445643/


All Articles