Fits a Ridge regression model to the given data

fit_ridge_regression(data, x_vars, y_var, lambda, intercept = TRUE)

Arguments

data

dataframe containing the feature and label variables

x_vars

character vector of variable names to be used as predictors

y_var

character string of the variable name to be used as the response variable

lambda

the value of the regularization parameter

intercept

logical value indicating whether to include an intercept term in the model

Value

a list containing the model object and fitted values

Examples

data(mtcars)
ridge_fit <- fit_ridge_regression(data = mtcars, x_vars = c("wt"), y_var = "mpg", lambda = 0.1)
ridge_fit$model # display the model object
#> $coefficients
#>          mpg
#>    35.868553
#> wt -4.939006
#> 
#> $residuals
#>                            mpg
#> Mazda RX4           -1.9283571
#> Mazda RX4 Wag       -0.6689106
#> Datsun 710          -1.6100589
#> Hornet 4 Drive       1.4103515
#> Hornet Sportabout   -0.1783722
#> Valiant             -0.6795921
#> Duster 360          -3.9363014
#> Merc 240D            4.2868763
#> Merc 230             2.4893161
#> Merc 280             0.3216278
#> Merc 280C           -1.0783722
#> Merc 450SE           0.6332016
#> Merc 450SL          -0.1460604
#> Merc 450SLC         -1.9991101
#> Cadillac Fleetwood   0.4612287
#> Lincoln Continental  1.3206157
#> Chrysler Imperial    5.2304342
#> Fiat 128             7.3972604
#> Honda Civic          2.5079419
#> Toyota Corolla       7.0945232
#> Toyota Corona       -2.1939030
#> Dodge Challenger    -2.9832517
#> AMC Javelin         -3.7030672
#> Camaro Z28          -3.6027698
#> Pontiac Firebird     2.3219252
#> Fiat X1-9            0.9884238
#> Porsche 914-2        0.7009200
#> Lotus Europa         2.0041633
#> Ford Pantera L      -4.4119038
#> Ferrari Dino        -2.4875062
#> Maserati Bora       -3.2363014
#> Volvo 142E          -0.7381161
#> 
ridge_fit$fitted_values # display the fitted values
#>                           mpg
#> Mazda RX4           22.928357
#> Mazda RX4 Wag       21.668911
#> Datsun 710          24.410059
#> Hornet 4 Drive      19.989649
#> Hornet Sportabout   18.878372
#> Valiant             18.779592
#> Duster 360          18.236301
#> Merc 240D           20.113124
#> Merc 230            20.310684
#> Merc 280            18.878372
#> Merc 280C           18.878372
#> Merc 450SE          15.766798
#> Merc 450SL          17.446060
#> Merc 450SLC         17.199110
#> Cadillac Fleetwood   9.938771
#> Lincoln Continental  9.079384
#> Chrysler Imperial    9.469566
#> Fiat 128            25.002740
#> Honda Civic         27.892058
#> Toyota Corolla      26.805477
#> Toyota Corona       23.693903
#> Dodge Challenger    18.483252
#> AMC Javelin         18.903067
#> Camaro Z28          16.902770
#> Pontiac Firebird    16.878075
#> Fiat X1-9           26.311576
#> Porsche 914-2       25.299080
#> Lotus Europa        28.395837
#> Ford Pantera L      20.211904
#> Ferrari Dino        22.187506
#> Maserati Bora       18.236301
#> Volvo 142E          22.138116