variani / lme4qtl

Mixed models @lme4 + custom covariances + parameter constraints
GNU General Public License v3.0
48 stars 10 forks source link

Error in is.nloptr(ret) : objective in x0 returns NA #32

Closed NicMAlexandre closed 2 years ago

NicMAlexandre commented 2 years ago

I keep getting the following error when I run:

lme4qtl::relmatLmer(FG ~ SeasonDay + (1|Site) + (1|Sample), Data, relmat = list(Sample=A))

Error in is.nloptr(ret) : objective in x0 returns NA In addition: Warning message: In sqrt(out$values) : NaNs produced

head(Data)

Sample FG SeasonDay Site 1 AL-5-28-2 20.42 148 Almont1 2 AL-5_28-1 21.13 148 Almont1 3 AL-5_29-1 22.43 149 Almont1 4 AL-5_29-2 20.55 149 Almont1 5 AL-5_29-3 20.58 149 Almont1 6 AL-5_29-4 20.14 149 Almont1

head(A)

Formal class 'dgCMatrix' [package "Matrix"] with 6 slots ..@ i : int [1:260100] 0 1 2 3 4 5 6 7 8 9 ... ..@ p : int [1:511] 0 510 1020 1530 2040 2550 3060 3570 4080 4590 ... ..@ Dim : int [1:2] 510 510 ..@ Dimnames:List of 2 .. ..$ : chr [1:510] "AL-5-28-2" "AL-5_28-1" "AL-5_29-1" "AL-5_29-2" ... .. ..$ : chr [1:510] "AL-5-28-2" "AL-5_28-1" "AL-5_29-1" "AL-5_29-2" ... ..@ x : num [1:260100] 0 0.000013 0.00127 0.000013 0.002184 ... ..@ factors : list()

I generated this matrix using a file with all possible pairs and "rab" values.

File:

Sample1   Sample2      rab

1 AL-5-28-2 AL-5-28-2 0.000000 2 AL-5-28-2 AL-5_28-1 0.000013 3 AL-5_28-1 AL-5_28-1 0.000000 4 AL-5-28-2 AL-5_29-1 0.001270 5 AL-5_29-1 AL-5_29-1 0.000000 6 AL-5_28-1 AL-5_29-1 0.008056

G <- graph.data.frame(File,directed=FALSE) A <- as_adjacency_matrix(G,names=TRUE,attr="rab",type='both')

variani commented 2 years ago

Having a reproducible example with toy dataset would help a lot, but my first guess is that your matrix A is rank deficient. Could you check this?

NicMAlexandre commented 2 years ago

Yes, I think you are right. Something seems to not be right and the matrix is rank deficient, which it shouldn't be. I was having a lot of trouble getting an appropriate matrix for the file above since every pairwise comparison is conducted (there are repeats). Do you have any suggestions?

Sample1 Sample2 rab 1 AL-5-28-2 AL-5-28-2 0.000000 2 AL-5-28-2 AL-5_28-1 0.000013 3 AL-5_28-1 AL-5_28-1 0.000000 4 AL-5-28-2 AL-5_29-1 0.001270 5 AL-5_29-1 AL-5_29-1 0.000000 6 AL-5_28-1 AL-5_29-1 0.008056

variani commented 2 years ago

I believe that you control for repeated measurements by having (1|Sample) term in the formula. I would work on preparing the matrix A to be full-rank. A quick solution can be https://stat.ethz.ch/R-manual/R-devel/library/Matrix/html/nearPD.html, but I don't claim it is optimal.

NicMAlexandre commented 2 years ago

That worked!! Thank you so much!

On Wed, Jul 27, 2022 at 1:00 PM Andrey Ziyatdinov @.***> wrote:

I believe that you control for repeated measurements by having (1|Sample) term in the formula. I would work on preparing the matrix A to be full-rank. A quick solution can be https://stat.ethz.ch/R-manual/R-devel/library/Matrix/html/nearPD.html, but I don't claim it is optimal.

— Reply to this email directly, view it on GitHub https://github.com/variani/lme4qtl/issues/32#issuecomment-1197243957, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFB6335WFO2GOQSM6UOLY7TVWGBOFANCNFSM542MOKXQ . You are receiving this because you authored the thread.Message ID: @.***>

-- Best,

Nicolas Alexandre PhD Candidate, Integrative Biology Whiteman Lab University of California - Berkeley @. @.>