source("lm_function.R")

# Example 1: cars data
x <- cars$speed
y <- cars$dist
mylm(x, y, scale_x = FALSE, actual_vs_pred = TRUE)

## $n
## [1] 50
## 
## $df
## [1] 48
## 
## $coefficients
##        Term   Estimate  StdError t_statistic      p_value
## 1 Intercept -17.579095 6.7584402   -2.601058 1.231882e-02
## 2        x1   3.932409 0.4155128    9.463990 1.489836e-12
## 
## $sigma
## [1] 15.37959
## 
## $R2
## [1] 0.6510794
# Example 2: mtcars data
x <- mtcars[, 2:7]
y <- mtcars[, 1]
mylm(x, y, diagnostics = TRUE)

## $n
## [1] 32
## 
## $df
## [1] 25
## 
## $coefficients
##        Term   Estimate StdError t_statistic      p_value
## 1 Intercept  26.164407 3.482102   7.5139685 7.224742e-08
## 2       cyl  -3.274241 3.246252  -1.0086220 3.228191e-01
## 3      disp   5.293842 4.825523   1.0970505 2.830743e-01
## 4        hp  -5.074171 4.388007  -1.1563727 2.584599e-01
## 5      drat   2.865280 3.210463   0.8924821 3.806451e-01
## 6        wt -16.390345 4.919675  -3.3315908 2.686742e-03
## 7      qsec   3.372274 4.339307   0.7771457 4.443648e-01
## 
## $sigma
## [1] 2.557161
## 
## $R2
## [1] 0.8548224
# Example 3: LifeCycleSavings data
x <- LifeCycleSavings[, -1]
y <- LifeCycleSavings[, 1]
mylm(x, y, quadratic = TRUE, diagnostics = TRUE)

## $n
## [1] 50
## 
## $df
## [1] 41
## 
## $coefficients
##        Term   Estimate  StdError t_statistic     p_value
## 1 Intercept  16.231681  5.942887   2.7312789 0.009260773
## 2     pop15 -15.239784 10.510958  -1.4498949 0.154694932
## 3     pop75 -10.286942 13.150508  -0.7822468 0.438564170
## 4       dpi   6.261304 11.358531   0.5512424 0.584459345
## 5      ddpi  14.798326  9.658578   1.5321433 0.133167663
## 6   pop15^2   4.466102  9.258886   0.4823584 0.632116646
## 7   pop75^2   3.217247 10.354663   0.3107051 0.757598949
## 8     dpi^2  -8.038021 10.919439  -0.7361204 0.465848387
## 9    ddpi^2  -9.058591 11.543395  -0.7847424 0.437115618
## 
## $sigma
## [1] 3.855315
## 
## $R2
## [1] 0.3804554
# Example 4: swiss data
x <- swiss[, -1]
y <- swiss[, 1]
mylm(x, y, quadratic = TRUE, actual_vs_pred = TRUE)

## $n
## [1] 47
## 
## $df
## [1] 36
## 
## $coefficients
##                  Term   Estimate StdError t_statistic      p_value
## 1           Intercept  72.158061 10.24331   7.0444111 2.870972e-08
## 2         Agriculture   3.399372 24.98592   0.1360515 8.925385e-01
## 3         Examination -43.710810 21.71564  -2.0128723 5.165333e-02
## 4           Education -20.629389 21.79882  -0.9463536 3.502774e-01
## 5            Catholic -24.758243 22.08350  -1.1211197 2.696600e-01
## 6    Infant.Mortality  33.394956 23.16950   1.4413326 1.581334e-01
## 7       Agriculture^2 -16.823619 22.72824  -0.7402077 4.639743e-01
## 8       Examination^2  40.903516 24.90245   1.6425502 1.091839e-01
## 9         Education^2 -25.172873 23.79297  -1.0579962 2.971050e-01
## 10         Catholic^2  34.248852 22.50486   1.5218422 1.367849e-01
## 11 Infant.Mortality^2 -11.232037 20.45170  -0.5491981 5.862602e-01
## 
## $sigma
## [1] 7.035526
## 
## $R2
## [1] 0.7517468