In this analysis, we’ll develop a model for predicting fuel efficiency from car characteristics using the auto_mpg data frame.

Model fitting is normally an iterative process. We’ll skip this to keep things simple.

Fit the model

library(qacReg)
data(auto_mpg)

fit <- lm(mpg ~ ., data = auto_mpg)

# or
# fit <- regress(mpg ~ ., data = auto_mpg)

Examine the model

info(fit)
#> MULTIPLE REGRESSION SUMMARY 
#> Model: mpg ~ .
#> Data : auto_mpg
#> N    : 388
#> 
#> Fit Indices 
#>  R.Squared Adj.R.Squared  AIC RMSE MAE
#>      0.824         0.821 2040 3.27 2.5
#> 
#> Omnibus Test 
#> F(8,379) = 222.481, p < <2e-16  *** 
#> 
#> Anova Table (type III tests) 
#>               Sum Sq  DF F value Pr(>F)    
#> (Intercept)   166.28   1  15.211 <0.001 ***
#> cyl           24.392   1   2.231  0.136    
#> disp         109.393   1  10.007  0.002  **
#> hp            17.858   1   1.634  0.202    
#> wt          1160.521   1  106.16 <0.001 ***
#> accel          7.599   1   0.695  0.405    
#> year        2471.376   1 226.073 <0.001 ***
#> origin       355.806   2  16.274 <0.001 ***
#> Residuals   4143.146 379                   
#> 
#> Regression Coefficients 
#>                     B      B*       SE       t Pr(>|t|)    
#> (Intercept) -18.29959  0.0000 4.692103  -3.900 1.14e-04 ***
#> cyl          -0.48327 -0.1056 0.323528  -1.494 1.36e-01    
#> disp          0.02450  0.3290 0.007746   3.163 1.69e-03  **
#> hp           -0.01754 -0.0867 0.013725  -1.278 2.02e-01    
#> wt           -0.00683 -0.7409 0.000663 -10.303 4.12e-22 ***
#> accel         0.08242  0.0292 0.098848   0.834 4.05e-01    
#> year          0.78281  0.3688 0.052063  15.036 2.11e-40 ***
#> origin2       2.62905  0.1282 0.568612   4.624 5.18e-06 ***
#> origin3       2.88572  0.1483 0.556654   5.184 3.54e-07 ***

Perform regression diagnostics

Visualize the model parameters

Evaluate variable importance

relimp(fit)
#> working ...

Assess predictive performance

performance(fit)
#> Multiple Regression Performance 
#> Data:  auto_mpg 
#> N:     388 
#> 
#> Model: lm(formula = mpg ~ ., data = auto_mpg) 
#> 
#>     RMSE Rsquared      MAE 
#>   3.2678   0.8244   2.5047