Search code examples
modeldistancelm

Linear model (lm) on distance matrix is not working on R 4.1.0


I had some code that computed a linear model between two distance matrices to obtain a slope estimate for abline(). In this case, Dgen is a pairwise matrix of genetic distances, while Dgeo is a pairwise triangular matrix of Euclidean distances. Before upgrading to R 4.1.0, the linear model ran perfectly, and now it produces the following error:

model <- lm(Dgen~Dgeo)
Error in xj[i, , drop = FALSE] : incorrect number of dimensions

Did something change in R 4.1.0 that I'm unaware? I checked the what's new on CRAN and didn't see anything that mentioned lm().

Am I doing something wrong?


Solution

  • I had the same issue and solved it by changing lm(Dgen~Dgeo) to lm(as.numeric(Dgen)~as.numeric(Dgeo)).