Hi, I notice that the Matrix::sparse.model.matrix produces inconsistent matrix when the contrasts is a sparse matrix.
Here is a minimal example: ```r library(Matrix) class(CO2[[1]]) <- class(CO2[[2]]) <- "factor" get_contr <- function(is_sparse) { contr <- list() contr[["Plant"]] <- contrasts(CO2[[1]], FALSE, sparse = is_sparse) contr[["Type"]] <- contrasts(CO2[[2]], FALSE, sparse = is_sparse) contr[["Treatment"]] <- contrasts(CO2[[3]], FALSE, sparse = is_sparse) contr } m1 <- sparse.model.matrix(~.^2, CO2, get_contr(TRUE)) m2 <- sparse.model.matrix(~.^2, CO2, get_contr(FALSE)) dim(m1) dim(m2) ``` The dimension is different: > dim(m1) [1] 84 66 > dim(m2) [1] 84 104 > The example should be reproduced with docker image rocker/r-base Wush PhD Student of Graduate Institute of Electrical Engineering, National Taiwan University [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.