Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lrm and Rcmdr conflict #137

Closed
MilosZarkovic opened this issue Dec 7, 2023 · 2 comments
Closed

lrm and Rcmdr conflict #137

MilosZarkovic opened this issue Dec 7, 2023 · 2 comments

Comments

@MilosZarkovic
Copy link

I found a problem of incompatibility between rms and Rcmdr. When I use rms::lrm without Rcmdr everything is fine.
However, when I loaded Rcmdr I got the following error: Error in X[, mmcolnames, drop = FALSE] : subscript out of bounds.
I use R 4.3.2 and R Studio2023.09.1 Build 494. Reproducible example follows:

library(rms)
n <- 1000 # define sample size
age <- rnorm(n, 50, 10)
blood.pressure <- rnorm(n, 120, 15)
cholesterol <- rnorm(n, 200, 25)
sex <- factor(sample(c('female','male'), n,TRUE))
diseased <- factor(sample(c('Healty','Sick'), n,TRUE))

f <- lrm(diseased ~ age + sex + cholesterol) ##this works
f

library(Rcmdr, warn.conflicts=TRUE, verbose = TRUE)

f <- lrm(diseased ~ age + sex + cholesterol) ##This does not work
f

Thank you

Miloš Žarković

@couthcommander
Copy link
Contributor

Hi Miloš - I was able to take a look at this. The "Rcmdr" package changes some R options which eventually leads to the error (by renaming columns in model.matrix.default).

Under base R:

> getOption("contrasts")
        unordered           ordered 
"contr.treatment"      "contr.poly" 

With "Rcmdr" attached:

> getOption("contrasts")
[1] "contr.Treatment" "contr.poly"     

I don't use "Rcmdr" and have no idea why it's making this change (see https://github.com/cran/Rcmdr/blob/3596637878b47a86051644e54539d21d2af7c573/R/file-menu.R#L348). But if you restore the option, lrm will work as desired.

Proposed solution:

(c_opt <- getOption("contrasts"))
library(Rcmdr)
options(contrasts = c_opt)

@MilosZarkovic
Copy link
Author

Thank you very much. Everything is now functioning correctly.
Regards,
Miloš

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants