rsquaredacademy / olsrr

Tools for developing OLS regression models
https://olsrr.rsquaredacademy.com/
Other
102 stars 22 forks source link

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

Closed njrockwood closed 3 years ago

njrockwood commented 3 years ago

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 commented 3 years ago
> 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 
-------------------------------------------