1
$\begingroup$

I am trying to compare 2 lmRob() models. One for male and one for female gender. Imagine my model like this:

model <- robust::lmRob(Y ~ X_dummy1 + X_dummy2 + X_dummy3 + 
            X_dummy4 + covariate1 + covariate2 + covariate3, 
            data = df)

When using gender (0 = female, 1 = male) as interaction, like this:

model <- robust::lmRob(Y ~ X_dummy1* gender + X_dummy2* gender + 
    X_dummy3* gender + X_dummy4* gender + covariate1* gender + 
    covariate2* gender + covariate3* gender, data = df)

this error appears:

    Error in lmRob.fit.compute(x, y, x1.idx = x1.idx, nrep = nrep, 
    robust.control = robust.control,  : 
      Singular matrix encountered in FORTRAN subroutine rlfastse

Is this not how to include the interaction in the lmRob() function? Do I have other options to compare the models for gender then?

$\endgroup$
3
  • $\begingroup$ Looks to be a continuation of stats.stackexchange.com/questions/637247/… $\endgroup$ Commented Jan 22, 2024 at 19:42
  • 1
    $\begingroup$ Questions solely about how software works are off-topic here, but you may have a real statistical question buried here. You may want to edit your question to clarify the underlying statistical issue. You may find that when you understand the statistical concepts involved, the software-specific elements are self-evident or at least easy to get from the documentation. $\endgroup$ Commented Jan 23, 2024 at 13:39
  • $\begingroup$ Also see stats.stackexchange.com/questions/117052/…, $\endgroup$ Commented Jan 23, 2024 at 16:42

1 Answer 1

3
$\begingroup$

Your problems seems to be a mixture of statistical and R programming. First, lmRob is written to be used (as much as possible ...) as a drop-in replacement for the lm function. So how to specify models with the R formula language is exactly as for lm. First, you seems to be making dummys for a factor variable by hand. In it place, do something like X <- as.factor(X) and R will make dummys for you (this might solve your singular matrix problem, maybe you made as many dummys as there are levels in X?). Then something like

model0 <- robust::lmRob(Y ~ X + covariate1 + covariate2 + covariate3, 
            data = df)

model <- robust::lmRob(Y ~ X * gender +   covariate1 * gender + 
    covariate2 * gender + covariate3 * gender, data = df)

Then for model comparison do

anova(model0, model, test="RF")

which will compare the models using a robustified F test. If this still gives errors like the one reported, there must be data problems. Could you share the data set?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.