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

ols_correlations() returns error for models with 2 predictors #168

Closed
njrockwood opened this issue Nov 10, 2020 · 1 comment
Closed

ols_correlations() returns error for models with 2 predictors #168

njrockwood opened this issue Nov 10, 2020 · 1 comment
Assignees
Labels

Comments

@njrockwood
Copy link

The example code for ols_correlations() works fine for the example model with 4 predictors, as well as a model with 3, but returns an error for models with 2 predictors. It would make sense to return an error for models with a single predictor, but the function should work for models with 2 predictors. I've had similar issues with using ols_correlations() on other models with 2 predictors.

library(olsrr)
#> 
#> Attaching package: 'olsrr'
#> The following object is masked from 'package:datasets':
#> 
#>     rivers

model.4 <- lm(mpg ~ disp + hp + wt + qsec, data = mtcars)
ols_correlations(model.4)
#>                Correlations                 
#> -------------------------------------------
#> Variable    Zero Order    Partial     Part  
#> -------------------------------------------
#> disp            -0.848      0.048     0.019 
#> hp              -0.776     -0.224    -0.093 
#> wt              -0.868     -0.574    -0.285 
#> qsec             0.419      0.219     0.091 
#> -------------------------------------------

model.3 <- lm(mpg ~ disp + hp + wt, data = mtcars)
ols_correlations(model.3)
#>                Correlations                 
#> -------------------------------------------
#> Variable    Zero Order    Partial     Part  
#> -------------------------------------------
#> disp            -0.848     -0.017    -0.007 
#> hp              -0.776     -0.458    -0.214 
#> wt              -0.868     -0.559    -0.280 
#> -------------------------------------------

model.2 <- lm(mpg ~ disp + hp, data = mtcars)
ols_correlations(model.2)
#> Error in terms.formula(formula, data = data): '.' in formula and no 'data' argument
@aravindhebbali aravindhebbali self-assigned this Nov 11, 2020
@aravindhebbali
Copy link
Member

> model.2 <- lm(mpg ~ disp + hp, data = mtcars)
> ols_correlations(model.2)
               Correlations                 
-------------------------------------------
Variable    Zero Order    Partial     Part  
-------------------------------------------
disp            -0.848     -0.606    -0.382 
hp              -0.776     -0.326    -0.173 
-------------------------------------------

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

No branches or pull requests

2 participants