Adds two columns to the original data of the scikit learn's linear regression model. This includes predictions and residuals.
augment_lr(my_lr, x, y)
my_lr | the linear model to augment |
---|---|
x | the data frame containing the explanatory variables |
y | the data frame containing the target variable |
output data.frame
# Import libraries library(dplyr) library(sptidy) data("longley") my_lr <- lm(Employed~., data = longley) augment_lr(my_lr, (longley %>% select(!Employed)), as.data.frame(longley$Employed))#> GNP.deflator GNP Unemployed Armed.Forces Population Year #> 1947 83.0 234.289 235.6 159.0 107.608 1947 #> 1948 88.5 259.426 232.5 145.6 108.632 1948 #> 1949 88.2 258.054 368.2 161.6 109.773 1949 #> 1950 89.5 284.599 335.1 165.0 110.929 1950 #> 1951 96.2 328.975 209.9 309.9 112.075 1951 #> 1952 98.1 346.999 193.2 359.4 113.270 1952 #> 1953 99.0 365.385 187.0 354.7 115.094 1953 #> 1954 100.0 363.112 357.8 335.0 116.219 1954 #> 1955 101.2 397.469 290.4 304.8 117.388 1955 #> 1956 104.6 419.180 282.2 285.7 118.734 1956 #> 1957 108.4 442.769 293.6 279.8 120.445 1957 #> 1958 110.8 444.546 468.1 263.7 121.950 1958 #> 1959 112.6 482.704 381.3 255.2 123.366 1959 #> 1960 114.2 502.601 393.1 251.4 125.368 1960 #> 1961 115.7 518.173 480.6 257.2 127.852 1961 #> 1962 116.9 554.894 400.7 282.7 130.081 1962 #> longley$Employed predictions residuals #> 1947 60.323 60.05566 0.26734003 #> 1948 61.122 61.21601 -0.09401394 #> 1949 60.171 60.12471 0.04628717 #> 1950 61.187 61.59711 -0.41011462 #> 1951 63.221 62.91129 0.30971459 #> 1952 63.639 63.88831 -0.24931122 #> 1953 64.989 65.15305 -0.16404896 #> 1954 63.761 63.77418 -0.01318036 #> 1955 66.019 66.00470 0.01430477 #> 1956 67.857 67.40161 0.45539409 #> 1957 68.169 68.18627 -0.01726893 #> 1958 66.513 66.55206 -0.03905504 #> 1959 68.655 68.81055 -0.15554997 #> 1960 69.564 69.64967 -0.08567131 #> 1961 69.331 68.98907 0.34193151 #> 1962 70.551 70.75776 -0.20675783