easystats / easystats/performance

Error and Incomplete Output Using performance::check_collinearity with Cox Models

Open
#714 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

3 investigators :grey_question::question: Bug :bug:
Dominant language
R
Stars
1.2k
Forks
109
Avg merge
6h 34m
Merged PRs (30d)
8

Description

Hello,

I encountered an issue when using the performance package to assess multicollinearity in Cox proportional hazards models. When I specify a model with exactly two predictors, the function check_collinearity throws an error, but it works as expected when there are more than two predictors, although it omits the output for the first predictor. Here are the details:

Code to Reproduce:

library(survival)
library(performance)

# Cox model with two predictors
cox_model_2vars <- coxph(Surv(time, status) ~ age + sex, data = lung)
performance::check_collinearity(cox_model_2vars)
# Error: 'V' is not a square numeric matrix

# Cox model with three predictors
cox_model_3vars <- coxph(Surv(time, status) ~ age + sex + ph.ecog, data = lung)
performance::check_collinearity(cox_model_3vars)

Expected Behavior:
The function check_collinearity should provide the multicollinearity diagnostics for models regardless of the number of predictors.

Actual Behavior:
With two predictors, it results in an error: Error in stats::cov2cor(v) : 'V' is not a square numeric matrix. However, with three or more predictors, the function works correctly and outputs the multicollinearity statistics, with an omission of the statistics for the first predictor (age in this case). Here are the results for the model with three predictors:

# Check for Multicollinearity

Low Correlation

    Term  VIF  VIF 95% CI Increased SE Tolerance Tolerance 95% CI
     sex 1.00 [1.00, Inf]         1.00      1.00     [0.00, 1.00]
 ph.ecog 1.00 [1.00, Inf]         1.00      1.00     [0.00, 1.00]

I am using R version 4.3.3 and performance package version 0.11.0. It would be helpful to understand whether this is a bug or if there's a recommended workaround for models with only two predictors.

Thank you for your assistance!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the check_collinearity entry point and reproduce the reported Cox model examples with two and three predictors. Verify that diagnostics are returned without the matrix error and that the first predictor is included in the output for both models.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.