Error: Error in solve.default(h, z[[2]]) : Lapack routine dgesv: system is exactly singular: U[9,9] = 0

Dear all,

I would be very thankful for help on below error:

Error in solve.default(h, z[[2]]) :
Lapack routine dgesv: system is exactly singular: U[9,9] = 0

This error occurs when I run the following loop below. The strange thing is that this only occurs when I ran it with high numbers (e.g. with i in 2:10 this error does not occur!)

After googling the error it seems to be related to the fact that the matrix is a singular matrix and does not have a matrix inverse. But I dont understand why it runs fine e.g. with 10 loops and what causes this error.

> result<-matrix(0,0,4) 
> 
> for(i in 2:500){               
>   expr<-as.vector(predicted_gene[,i] )
> 
>   resi<-crr(
>     ftime = pheno$survalltime,
>     fstatus = pheno$event_status,
>     cov1 = model.matrix(~ factor(sex) + age  +  factor(Site_Category) + factor(ajcc) +expr , data = pheno)[, -1], 
>     failcode =1, cencode = 0)
> 
>   coef<-matrix(c(summary(resi)$coef[9,c(2,3,4,5)]),1,4)
>   rownames(coef)<-colnames(predicted_gene)[i]
>   {result<-rbind(result,coef)}
> }

Has anyone an idea what could be the problem with higher numbers?

Thanks so much!!

it may simply be a coincident/ accident that its higher and not lower.

We must ask; what is the role of i in what you are doing.

  expr<-as.vector(predicted_gene[,i] )

its role is to change the content of expr ; it pulls a further column from predicted gene

2 Likes

The problem was solved: There was a column with all 0s in predicted gene (in i=142) which lead to the crash in the program.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.