Skip to content

Bug with model.matrix when no collinear fixed effects #229

@kylebutts

Description

@kylebutts

Small bug found in model.matrix. If there are no collinear fixed effects, this fails. A first check to make sure that there are collinear variables can fix this. Something like: if(!"collin.var" %in% names(object))

fixest/R/MiscFuns.R

Lines 7887 to 7894 in 6c99dfe

if(collin.rm){
qui = which(colnames(linear.mat) %in% object$collin.var)
if(length(qui) == ncol(linear.mat)){
linear.mat = NULL
} else if(length(qui) > 0){
linear.mat = linear.mat[, -qui, drop = FALSE]
}
}

Reprex:

library(palmerpenguins)
library(fixest)

est <- feols(bill_length_mm ~ 0 | species, data = penguins)
#> NOTE: 2 observations removed because of NA values (LHS: 2).

model.matrix(est)
#> Error in if (length(qui) == ncol(linear.mat)) {: argument is of length zero

Created on 2021-11-09 by the reprex package (v2.0.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions