# Copyright (C) [2024] [Mattia Bennati]

# DATASET 1 GlobClus_prop
#### ASTRO DATA: 20 different measures for 147 globular star clusters in the Milky Way Galaxy
# https://astrostatistics.psu.edu/MSMA/datasets/index.html
# Properties include Galactic location, integrated stellar luminosity, metallicity, ellipticity,
# central surface brightness, color, and seven measures of dynamical state
# (core and tidal radius, concentration, central star density and relaxation time,
# central velocity dispersion and escape velocity).
# https://search.r-project.org/CRAN/refmans/astrodatR/html/GlobClus_prop.html
# data description: Appendix C.7 of Feigelson & Babu (2012)
# with statistical analysis in Chapter 8.

# Importing packages
#install.packages("igraph")
#install.packages("RcppEigen")
#install.packages("RcppArmadillo")
#install.packages("gRbase")
#install.packages("gRain")
#install.packages("gRim")
library(gRbase)
library(gRain)
library(gRim)
library(bnlearn)
## 
## Attaching package: 'bnlearn'
## The following objects are masked from 'package:gRbase':
## 
##     ancestors, children, parents
# Clears the current environment
rm(list=ls(all=TRUE))
# Sets the current working directory
setwd("~/Desktop/university/AI/FOSM/project/GlobusClus_prop-Analysis/")

# Installing the "astrodatR" dataset
# install.packages("astrodatR")
# Importing the dataset
require(astrodatR)
## Loading required package: astrodatR
# Parsing the dataset data
data(GlobClus_prop)
# Saves the data into the dat variable
dat <- GlobClus_prop

# Prints the first 5 rows of the dataset
# print(head(dat, n=5))


# CHOSEN OBJECTIVE:
# Study of the dynamics of globular clusters
# Identifying which parameters influence the dispersion of the
# central velocity of a globular star cluster and how they affect it


# PHASE 1:
# IDENTIFICATION OF VARIABLES
# Name: Common name
# Gal.long: Galactic longitude (degrees)
# Gal.lat: Galactic latitude (degrees)
# R.sol: Distance from the Sun (kiloparsecs, kpc)
# R.GC: Distance from the Galactic Center (kpc)
# Metal: Log metallicity with respect to solar metallicity
# Mv: Absolute magnitude
# r.core: Core radius (parsecs, pc)
# r.tidal: Tidal radius (pc)
# Conc: Core concentration parameter
# log.t: Log central relaxation timescale (years)
# log.rho: Log central density (solar masses per cubic parsec)
# S0: Central velocity dispersion (kilometers per second)
# V.esc: Central escape velocity (km/s)
# VHB: Level of the horizontal branch (magnitude)
# E.B-V: Color excess (magnitude)
# B-V: Color index (magnitude)
# Ellipt: Ellipticity
# V.t: Integrated V magnitude (magnitude)
# CSBt: Central surface brightness (magnitude per square arcsecond)

# PHASE 2:
# CLEANING THE DATASET FROM NAN VALUES (WITH INCOMPLETE DATA) AND EXCLUDING
# THE NAME COLUMN AS IT IS SUPERFLUOUS FOR THE STUDY
dat <- na.omit(dat[,-1])
# First 5 records of the dataset
head(dat, n=5)
##   Gal.long Gal.lat R.sol  R.GC Metal   Mv r.core r.tidal Conc log.t log.rho
## 1   305.90  -44.89   4.6   8.1  -0.8 -9.6    0.5    60.3  2.1   7.9     5.0
## 2   151.15  -89.38   8.2  12.1  -1.4 -6.6    4.0    37.0  0.9   9.0     2.0
## 3   301.53  -46.25   8.7   9.9  -1.4 -8.4    0.5    25.9  1.7   7.8     4.8
## 4   270.54  -52.13  16.1  18.3  -1.2 -7.8    1.9    37.1  1.3   8.6     3.2
## 7   258.36  -48.47 116.4 117.9  -1.7 -4.5    9.5    81.2  0.9   9.3     0.0
##     S0 V.esc  VHB E.B.V B.V Ellipt V.t CSBt
## 1 13.2  56.8 14.1     0 1.0    3.8   3  5.6
## 2  2.8  10.0 15.3     0 0.9    8.1   1 11.0
## 3 10.3  41.8 15.4     0 0.9    6.4   6  6.1
## 4  5.5  20.7 16.6     0 0.9    8.2   8  8.7
## 7  0.7   2.4 20.9     0 0.8   15.8   4 15.0
# PHASE 3:
# DEFINITION OF VARIABLES
y = dat$S0
x1 = dat$Gal.long
x2 = dat$Gal.lat
x3 = dat$R.sol
x4 = dat$R.GC
x5 = dat$Metal
x6 = dat$Mv
x7 = dat$r.core
x8 = dat$r.tidal
x9 = dat$Conc
x10 = dat$log.t
x11 = dat$log.rho
x12 = dat$V.esc
x13 = dat$VHB
x14 = dat$E.B.V
x15 = dat$B.V
x16 = dat$Ellipt
x17 = dat$V.t
x18 = dat$CSBt

# PHASE 4:
# ANALYSIS OF SIGNIFICANT VARIABLES:
# Definition of the complete model:
mq <- lm(y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18)
summary(mq)
## 
## Call:
## lm(formula = y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + 
##     x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.35240 -0.08275 -0.01367  0.06688  0.70644 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.4932971  4.0122361   0.123  0.90241    
## x1          -0.0001159  0.0001097  -1.056  0.29370    
## x2           0.0008409  0.0006320   1.331  0.18654    
## x3           0.0058477  0.0058386   1.002  0.31913    
## x4          -0.0027320  0.0046645  -0.586  0.55949    
## x5          -0.1743371  0.1230087  -1.417  0.15971    
## x6           0.4107678  0.4499448   0.913  0.36362    
## x7          -0.0277227  0.0175895  -1.576  0.11836    
## x8          -0.0001507  0.0010495  -0.144  0.88616    
## x9          -0.0349403  0.2545558  -0.137  0.89112    
## x10          1.1866765  0.3453261   3.436  0.00088 ***
## x11         -0.3031051  0.3517006  -0.862  0.39098    
## x12          0.2364541  0.0032508  72.736  < 2e-16 ***
## x13         -0.1351995  0.4372948  -0.309  0.75787    
## x14          1.4366685  0.4871607   2.949  0.00402 ** 
## x15          0.5159395  0.4768871   1.082  0.28207    
## x16          0.1026885  0.4341540   0.237  0.81354    
## x17         -0.0029176  0.0080131  -0.364  0.71659    
## x18         -0.5989269  0.1782506  -3.360  0.00113 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1661 on 94 degrees of freedom
## Multiple R-squared:  0.998,  Adjusted R-squared:  0.9976 
## F-statistic:  2604 on 18 and 94 DF,  p-value: < 2.2e-16
# Definition of the null model (intercept only):
mq0 <- lm(y ~ 1)
summary(mq0)
## 
## Call:
## lm(formula = y ~ 1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.5283 -2.3283 -0.6283  1.9717 12.8717 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   6.2283     0.3201   19.46   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.402 on 112 degrees of freedom
# 1st - P-VALUE STRATEGY WITH "BACKWARD" METHOD:
# Starting from the complete model, iteratively eliminate the variable
# with the highest p-value (Pr(>|t|)) until there are no non-significant variables
mq1 <- update(mq, .~. -x9)
summary(mq1)
## 
## Call:
## lm(formula = y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x10 + 
##     x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.35253 -0.08095 -0.01351  0.06982  0.70550 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.2358663  3.5285428   0.067 0.946845    
## x1          -0.0001171  0.0001088  -1.077 0.284318    
## x2           0.0008386  0.0006285   1.334 0.185311    
## x3           0.0058135  0.0058030   1.002 0.318987    
## x4          -0.0026871  0.0046290  -0.580 0.562954    
## x5          -0.1765506  0.1213157  -1.455 0.148883    
## x6           0.4220482  0.4400854   0.959 0.339986    
## x7          -0.0276866  0.0174965  -1.582 0.116880    
## x8          -0.0001718  0.0010327  -0.166 0.868230    
## x10          1.2283975  0.1630443   7.534 2.85e-11 ***
## x11         -0.2940487  0.3436676  -0.856 0.394361    
## x12          0.2363726  0.0031795  74.343  < 2e-16 ***
## x13         -0.1401001  0.4335784  -0.323 0.747311    
## x14          1.4483989  0.4771228   3.036 0.003097 ** 
## x15          0.5259681  0.4688171   1.122 0.264731    
## x16          0.1074227  0.4305412   0.250 0.803508    
## x17         -0.0030333  0.0079274  -0.383 0.702847    
## x18         -0.6052511  0.1713015  -3.533 0.000636 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1653 on 95 degrees of freedom
## Multiple R-squared:  0.998,  Adjusted R-squared:  0.9976 
## F-statistic:  2786 on 17 and 95 DF,  p-value: < 2.2e-16
mq1 <- update(mq1, .~. -x8)
summary(mq1)
## 
## Call:
## lm(formula = y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x10 + x11 + 
##     x12 + x13 + x14 + x15 + x16 + x17 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.35442 -0.08096 -0.01251  0.07026  0.70668 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.3351778  3.4600193   0.097 0.923030    
## x1          -0.0001178  0.0001082  -1.089 0.278953    
## x2           0.0008111  0.0006034   1.344 0.182008    
## x3           0.0058245  0.0057732   1.009 0.315563    
## x4          -0.0028468  0.0045053  -0.632 0.528968    
## x5          -0.1782262  0.1202830  -1.482 0.141689    
## x6           0.4362329  0.4295541   1.016 0.312397    
## x7          -0.0278998  0.0173609  -1.607 0.111328    
## x10          1.2320327  0.1607530   7.664 1.45e-11 ***
## x11         -0.3033374  0.3373798  -0.899 0.370850    
## x12          0.2365381  0.0030045  78.728  < 2e-16 ***
## x13         -0.1332178  0.4294089  -0.310 0.757055    
## x14          1.4653611  0.4637341   3.160 0.002111 ** 
## x15          0.5335312  0.4642385   1.149 0.253304    
## x16          0.1006465  0.4264339   0.236 0.813921    
## x17         -0.0030075  0.0078856  -0.381 0.703762    
## x18         -0.6130698  0.1638913  -3.741 0.000312 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1644 on 96 degrees of freedom
## Multiple R-squared:  0.998,  Adjusted R-squared:  0.9977 
## F-statistic:  2991 on 16 and 96 DF,  p-value: < 2.2e-16
mq1 <- update(mq1, .~. -x16)
summary(mq1)
## 
## Call:
## lm(formula = y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x10 + x11 + 
##     x12 + x13 + x14 + x15 + x17 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.35641 -0.08289 -0.01025  0.06667  0.70961 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.1996146  3.3953637   0.059 0.953240    
## x1          -0.0001167  0.0001075  -1.085 0.280620    
## x2           0.0008166  0.0006000   1.361 0.176647    
## x3           0.0057490  0.0057362   1.002 0.318725    
## x4          -0.0027745  0.0044729  -0.620 0.536525    
## x5          -0.1730569  0.1176951  -1.470 0.144694    
## x6           0.5369299  0.0496387  10.817  < 2e-16 ***
## x7          -0.0276555  0.0172454  -1.604 0.112045    
## x10          1.2355184  0.1592921   7.756 8.81e-12 ***
## x11         -0.2949216  0.3338532  -0.883 0.379211    
## x12          0.2365294  0.0029896  79.117  < 2e-16 ***
## x13         -0.0320368  0.0245645  -1.304 0.195255    
## x14          1.4713379  0.4607828   3.193 0.001898 ** 
## x15          0.5154334  0.4556279   1.131 0.260735    
## x17         -0.0041297  0.0062600  -0.660 0.511005    
## x18         -0.6094081  0.1623592  -3.753 0.000297 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1636 on 97 degrees of freedom
## Multiple R-squared:  0.998,  Adjusted R-squared:  0.9977 
## F-statistic:  3221 on 15 and 97 DF,  p-value: < 2.2e-16
mq1 <- update(mq1, .~. -x4)
summary(mq1)
## 
## Call:
## lm(formula = y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x11 + x12 + 
##     x13 + x14 + x15 + x17 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.35257 -0.08184 -0.00729  0.06178  0.71043 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.1741975  3.3844423   0.051 0.959056    
## x1          -0.0001181  0.0001072  -1.102 0.273374    
## x2           0.0008270  0.0005979   1.383 0.169705    
## x3           0.0024359  0.0020852   1.168 0.245566    
## x5          -0.1684015  0.1170863  -1.438 0.153544    
## x6           0.5395782  0.0492993  10.945  < 2e-16 ***
## x7          -0.0277383  0.0171907  -1.614 0.109837    
## x10          1.2366363  0.1587811   7.788 7.16e-12 ***
## x11         -0.3001491  0.3326975  -0.902 0.369180    
## x12          0.2364865  0.0029794  79.373  < 2e-16 ***
## x13         -0.0243882  0.0211786  -1.152 0.252308    
## x14          1.4698092  0.4593275   3.200 0.001853 ** 
## x15          0.5130562  0.4541794   1.130 0.261388    
## x17         -0.0035160  0.0061618  -0.571 0.569575    
## x18         -0.6148681  0.1616107  -3.805 0.000247 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1631 on 98 degrees of freedom
## Multiple R-squared:  0.998,  Adjusted R-squared:  0.9977 
## F-statistic:  3473 on 14 and 98 DF,  p-value: < 2.2e-16
mq1 <- update(mq1, .~. -x17)
summary(mq1)
## 
## Call:
## lm(formula = y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x11 + x12 + 
##     x13 + x14 + x15 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.36375 -0.07854 -0.00903  0.06905  0.72228 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.1749390  3.3728946   0.052 0.958740    
## x1          -0.0001227  0.0001065  -1.152 0.252102    
## x2           0.0007614  0.0005847   1.302 0.195842    
## x3           0.0022720  0.0020583   1.104 0.272345    
## x5          -0.1743596  0.1162218  -1.500 0.136737    
## x6           0.5400045  0.0491254  10.992  < 2e-16 ***
## x7          -0.0263506  0.0169597  -1.554 0.123443    
## x10          1.2313887  0.1579737   7.795 6.58e-12 ***
## x11         -0.3062268  0.3313924  -0.924 0.357701    
## x12          0.2366298  0.0029587  79.978  < 2e-16 ***
## x13         -0.0224821  0.0208421  -1.079 0.283350    
## x14          1.4453521  0.4557630   3.171 0.002021 ** 
## x15          0.5381038  0.4505107   1.194 0.235163    
## x18         -0.6163417  0.1610387  -3.827 0.000227 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1626 on 99 degrees of freedom
## Multiple R-squared:  0.998,  Adjusted R-squared:  0.9977 
## F-statistic:  3766 on 13 and 99 DF,  p-value: < 2.2e-16
mq1 <- update(mq1, .~. -x11)
summary(mq1)
## 
## Call:
## lm(formula = y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x12 + x13 + 
##     x14 + x15 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.40040 -0.07510 -0.00540  0.06222  0.72767 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.8889521  0.6181588  -4.673 9.26e-06 ***
## x1          -0.0001284  0.0001063  -1.209  0.22970    
## x2           0.0007332  0.0005835   1.257  0.21180    
## x3           0.0026776  0.0020095   1.332  0.18573    
## x5          -0.1262483  0.1038314  -1.216  0.22689    
## x6           0.5336481  0.0486059  10.979  < 2e-16 ***
## x7          -0.0277277  0.0168818  -1.642  0.10363    
## x10          1.3579486  0.0786667  17.262  < 2e-16 ***
## x12          0.2361010  0.0029007  81.395  < 2e-16 ***
## x13         -0.0254384  0.0205801  -1.236  0.21933    
## x14          1.2120506  0.3791654   3.197  0.00186 ** 
## x15          0.3320253  0.3911531   0.849  0.39800    
## x18         -0.4735346  0.0452432 -10.466  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1624 on 100 degrees of freedom
## Multiple R-squared:  0.998,  Adjusted R-squared:  0.9977 
## F-statistic:  4086 on 12 and 100 DF,  p-value: < 2.2e-16
mq1 <- update(mq1, .~. -x15)
summary(mq1)
## 
## Call:
## lm(formula = y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x12 + x13 + 
##     x14 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.40103 -0.07663 -0.00220  0.06881  0.73009 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.4772228  0.3826742  -6.473  3.5e-09 ***
## x1          -0.0001360  0.0001057  -1.287    0.201    
## x2           0.0007073  0.0005819   1.216    0.227    
## x3           0.0026031  0.0020048   1.298    0.197    
## x5          -0.0425866  0.0326172  -1.306    0.195    
## x6           0.5250776  0.0474798  11.059  < 2e-16 ***
## x7          -0.0277405  0.0168584  -1.646    0.103    
## x10          1.3418453  0.0762393  17.600  < 2e-16 ***
## x12          0.2362477  0.0028915  81.704  < 2e-16 ***
## x13         -0.0268126  0.0204879  -1.309    0.194    
## x14          1.5176539  0.1187795  12.777  < 2e-16 ***
## x18         -0.4647963  0.0439954 -10.565  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1622 on 101 degrees of freedom
## Multiple R-squared:  0.9979, Adjusted R-squared:  0.9977 
## F-statistic:  4469 on 11 and 101 DF,  p-value: < 2.2e-16
mq1 <- update(mq1, .~. -x2)
summary(mq1)
## 
## Call:
## lm(formula = y ~ x1 + x3 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + 
##     x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.39884 -0.07960  0.00595  0.06595  0.73189 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.5026243  0.3829965  -6.534 2.55e-09 ***
## x1          -0.0001293  0.0001058  -1.222    0.225    
## x3           0.0023564  0.0019991   1.179    0.241    
## x5          -0.0461214  0.0325632  -1.416    0.160    
## x6           0.5140892  0.0467202  11.004  < 2e-16 ***
## x7          -0.0248856  0.0167330  -1.487    0.140    
## x10          1.3349987  0.0762086  17.518  < 2e-16 ***
## x12          0.2354596  0.0028245  83.364  < 2e-16 ***
## x13         -0.0261963  0.0205295  -1.276    0.205    
## x14          1.5251507  0.1188966  12.828  < 2e-16 ***
## x18         -0.4649954  0.0440980 -10.545  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1626 on 102 degrees of freedom
## Multiple R-squared:  0.9979, Adjusted R-squared:  0.9977 
## F-statistic:  4893 on 10 and 102 DF,  p-value: < 2.2e-16
mq1 <- update(mq1, .~. -x3)
summary(mq1)
## 
## Call:
## lm(formula = y ~ x1 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + 
##     x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.40344 -0.07574  0.00478  0.06350  0.73465 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.6547450  0.3612783  -7.348 4.91e-11 ***
## x1          -0.0001312  0.0001060  -1.238    0.219    
## x5          -0.0478541  0.0325915  -1.468    0.145    
## x6           0.5211999  0.0464166  11.229  < 2e-16 ***
## x7          -0.0159458  0.0149436  -1.067    0.288    
## x10          1.3297908  0.0762241  17.446  < 2e-16 ***
## x12          0.2358231  0.0028129  83.836  < 2e-16 ***
## x13         -0.0085629  0.0140858  -0.608    0.545    
## x14          1.4782901  0.1122645  13.168  < 2e-16 ***
## x18         -0.4677794  0.0441178 -10.603  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1629 on 103 degrees of freedom
## Multiple R-squared:  0.9979, Adjusted R-squared:  0.9977 
## F-statistic:  5416 on 9 and 103 DF,  p-value: < 2.2e-16
mq1 <- update(mq1, .~. -x13)
summary(mq1)
## 
## Call:
## lm(formula = y ~ x1 + x5 + x6 + x7 + x10 + x12 + x14 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.39788 -0.07868  0.00587  0.06454  0.75390 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.7721244  0.3044254  -9.106 6.66e-15 ***
## x1          -0.0001289  0.0001056  -1.221    0.225    
## x5          -0.0490928  0.0324290  -1.514    0.133    
## x6           0.5310377  0.0433721  12.244  < 2e-16 ***
## x7          -0.0179257  0.0145401  -1.233    0.220    
## x10          1.3495416  0.0687440  19.631  < 2e-16 ***
## x12          0.2354506  0.0027370  86.025  < 2e-16 ***
## x14          1.4877723  0.1108382  13.423  < 2e-16 ***
## x18         -0.4791671  0.0398222 -12.033  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1624 on 104 degrees of freedom
## Multiple R-squared:  0.9979, Adjusted R-squared:  0.9977 
## F-statistic:  6131 on 8 and 104 DF,  p-value: < 2.2e-16
mq1 <- update(mq1, .~. -x1)
summary(mq1)
## 
## Call:
## lm(formula = y ~ x5 + x6 + x7 + x10 + x12 + x14 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.42602 -0.07545  0.00083  0.06638  0.74943 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.743152   0.304207  -9.017 9.77e-15 ***
## x5          -0.046819   0.032451  -1.443    0.152    
## x6           0.534608   0.043374  12.325  < 2e-16 ***
## x7          -0.018145   0.014573  -1.245    0.216    
## x10          1.353216   0.068838  19.658  < 2e-16 ***
## x12          0.235025   0.002721  86.373  < 2e-16 ***
## x14          1.498104   0.110772  13.524  < 2e-16 ***
## x18         -0.483881   0.039727 -12.180  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1628 on 105 degrees of freedom
## Multiple R-squared:  0.9979, Adjusted R-squared:  0.9977 
## F-statistic:  6974 on 7 and 105 DF,  p-value: < 2.2e-16
mq1 <- update(mq1, .~. -x7)
summary(mq1)
## 
## Call:
## lm(formula = y ~ x5 + x6 + x10 + x12 + x14 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.42766 -0.08150  0.01102  0.06488  0.74583 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.462762   0.205057 -12.010   <2e-16 ***
## x5          -0.040194   0.032095  -1.252    0.213    
## x6           0.550194   0.041636  13.214   <2e-16 ***
## x10          1.361043   0.068728  19.803   <2e-16 ***
## x12          0.234268   0.002659  88.098   <2e-16 ***
## x14          1.566623   0.096386  16.254   <2e-16 ***
## x18         -0.511718   0.032924 -15.542   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1632 on 106 degrees of freedom
## Multiple R-squared:  0.9978, Adjusted R-squared:  0.9977 
## F-statistic:  8094 on 6 and 106 DF,  p-value: < 2.2e-16
mq1 <- update(mq1, .~. -x5)
summary(mq1)
## 
## Call:
## lm(formula = y ~ x6 + x10 + x12 + x14 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.44914 -0.07025  0.01326  0.06725  0.75342 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.404720   0.200281  -12.01   <2e-16 ***
## x6           0.536888   0.040365   13.30   <2e-16 ***
## x10          1.346157   0.067872   19.83   <2e-16 ***
## x12          0.233623   0.002616   89.32   <2e-16 ***
## x14          1.541982   0.094606   16.30   <2e-16 ***
## x18         -0.506816   0.032777  -15.46   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1636 on 107 degrees of freedom
## Multiple R-squared:  0.9978, Adjusted R-squared:  0.9977 
## F-statistic:  9661 on 5 and 107 DF,  p-value: < 2.2e-16
# IDENTIFIED MODEL:
# lm(formula = y ~ x6 + x10 + x12 + x14 + x18)
# Summary information of the model:
summary(mq1)
## 
## Call:
## lm(formula = y ~ x6 + x10 + x12 + x14 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.44914 -0.07025  0.01326  0.06725  0.75342 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.404720   0.200281  -12.01   <2e-16 ***
## x6           0.536888   0.040365   13.30   <2e-16 ***
## x10          1.346157   0.067872   19.83   <2e-16 ***
## x12          0.233623   0.002616   89.32   <2e-16 ***
## x14          1.541982   0.094606   16.30   <2e-16 ***
## x18         -0.506816   0.032777  -15.46   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1636 on 107 degrees of freedom
## Multiple R-squared:  0.9978, Adjusted R-squared:  0.9977 
## F-statistic:  9661 on 5 and 107 DF,  p-value: < 2.2e-16
# 2nd - P-VALUE STRATEGY WITH "FORWARD" METHOD:
# starting from the null model (intercept only), iteratively add
# a variable with the lowest p-value
mq2 <- update(mq0, .~. +x1)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.7523 -2.1354 -0.5117  2.0944 12.4285 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 5.803021   0.481501  12.052   <2e-16 ***
## x1          0.002513   0.002129   1.181     0.24    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.396 on 111 degrees of freedom
## Multiple R-squared:  0.0124, Adjusted R-squared:  0.003504 
## F-statistic: 1.394 on 1 and 111 DF,  p-value: 0.2403
mq2 <- update(mq0, .~. +x2)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.3923 -2.3107 -0.5819  1.7492 12.8901 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 6.228898   0.321407  19.380   <2e-16 ***
## x2          0.002819   0.011232   0.251    0.802    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.417 on 111 degrees of freedom
## Multiple R-squared:  0.0005672,  Adjusted R-squared:  -0.008437 
## F-statistic: 0.063 on 1 and 111 DF,  p-value: 0.8023
mq2 <- update(mq0, .~. +x3)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x3)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.9255 -2.3452 -0.6054  1.6366 12.8528 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.98328    0.39625  17.623  < 2e-16 ***
## x3          -0.05453    0.01793  -3.042  0.00294 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.283 on 111 degrees of freedom
## Multiple R-squared:  0.07693,    Adjusted R-squared:  0.06862 
## F-statistic: 9.251 on 1 and 111 DF,  p-value: 0.002937
mq2 <- update(mq0, .~. +x4)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x4)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.9886 -2.3528 -0.6407  1.7819 12.5366 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.87286    0.36236  18.967  < 2e-16 ***
## x4          -0.05526    0.01657  -3.335  0.00116 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.258 on 111 degrees of freedom
## Multiple R-squared:  0.09106,    Adjusted R-squared:  0.08287 
## F-statistic: 11.12 on 1 and 111 DF,  p-value: 0.001162
mq2 <- update(mq0, .~. +x5)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x5)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.6772 -2.3410 -0.7176  1.9016 12.3845 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   7.0730     0.9287   7.616 9.36e-12 ***
## x5            0.5958     0.6150   0.969    0.335    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.403 on 111 degrees of freedom
## Multiple R-squared:  0.008386,   Adjusted R-squared:  -0.0005474 
## F-statistic: 0.9387 on 1 and 111 DF,  p-value: 0.3347
mq2 <- update(mq0, .~. +x6)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.1414 -1.2443 -0.1092  0.9834  7.3929 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -10.2611     1.1210  -9.154 3.17e-15 ***
## x6           -2.2190     0.1488 -14.915  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.972 on 111 degrees of freedom
## Multiple R-squared:  0.6671, Adjusted R-squared:  0.6641 
## F-statistic: 222.5 on 1 and 111 DF,  p-value: < 2.2e-16
mq2 <- update(mq0, .~. +x7)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x7)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.1296 -2.0943 -0.8296  1.4996 12.0996 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   7.3881     0.3630  20.352  < 2e-16 ***
## x7           -0.6462     0.1233  -5.243 7.63e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.06 on 111 degrees of freedom
## Multiple R-squared:  0.1985, Adjusted R-squared:  0.1913 
## F-statistic: 27.49 on 1 and 111 DF,  p-value: 7.625e-07
mq2 <- update(mq0, .~. +x8)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x8)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.5330 -2.3352 -0.6233  1.9406 12.8074 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.527942   0.495343  13.179   <2e-16 ***
## x8          -0.007220   0.009099  -0.793    0.429    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.408 on 111 degrees of freedom
## Multiple R-squared:  0.00564,    Adjusted R-squared:  -0.003318 
## F-statistic: 0.6296 on 1 and 111 DF,  p-value: 0.4292
mq2 <- update(mq0, .~. +x9)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x9)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.3943 -1.8993 -0.7773  1.2430 11.9040 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   0.3619     1.1252   0.322    0.748    
## x9            3.7967     0.7043   5.391 3.99e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.042 on 111 degrees of freedom
## Multiple R-squared:  0.2075, Adjusted R-squared:  0.2003 
## F-statistic: 29.06 on 1 and 111 DF,  p-value: 3.992e-07
mq2 <- update(mq0, .~. +x10)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x10)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.4198 -2.4288 -0.8747  1.6892 12.8794 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  15.0509     3.2848   4.582 1.21e-05 ***
## x10          -1.0902     0.4041  -2.698  0.00806 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.311 on 111 degrees of freedom
## Multiple R-squared:  0.06154,    Adjusted R-squared:  0.05309 
## F-statistic: 7.279 on 1 and 111 DF,  p-value: 0.008064
mq2 <- update(mq0, .~. +x11)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x11)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.1329 -1.5530 -0.2982  1.1070  9.8971 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -0.6017     0.7075   -0.85    0.397    
## x11           1.8499     0.1811   10.21   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.454 on 111 degrees of freedom
## Multiple R-squared:  0.4844, Adjusted R-squared:  0.4798 
## F-statistic: 104.3 on 1 and 111 DF,  p-value: < 2.2e-16
mq2 <- update(mq0, .~. +x12)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x12)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.36563 -0.16324  0.00488  0.17539  1.40265 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.30958    0.07152   4.329  3.3e-05 ***
## x12          0.23609    0.00248  95.210  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3759 on 111 degrees of freedom
## Multiple R-squared:  0.9879, Adjusted R-squared:  0.9878 
## F-statistic:  9065 on 1 and 111 DF,  p-value: < 2.2e-16
mq2 <- update(mq0, .~. +x13)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x13)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.3583 -2.3759 -0.6308  1.8702 12.9087 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  7.32559    3.27505   2.237   0.0273 *
## x13         -0.06595    0.19589  -0.337   0.7370  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.416 on 111 degrees of freedom
## Multiple R-squared:  0.00102,    Adjusted R-squared:  -0.00798 
## F-statistic: 0.1133 on 1 and 111 DF,  p-value: 0.737
mq2 <- update(mq0, .~. +x14)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x14)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.0138 -2.4336 -0.7138  1.9457 12.9259 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   5.6336     0.4071  13.839   <2e-16 ***
## x14           1.8018     0.7845   2.297   0.0235 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.339 on 111 degrees of freedom
## Multiple R-squared:  0.04537,    Adjusted R-squared:  0.03677 
## F-statistic: 5.275 on 1 and 111 DF,  p-value: 0.02351
mq2 <- update(mq0, .~. +x15)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x15)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.1711 -2.3065 -0.6711  2.1466 12.6524 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   4.3826     0.8704   5.035 1.86e-06 ***
## x15           1.5884     0.6986   2.274   0.0249 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.341 on 111 degrees of freedom
## Multiple R-squared:  0.0445, Adjusted R-squared:  0.0359 
## F-statistic:  5.17 on 1 and 111 DF,  p-value: 0.0249
mq2 <- update(mq0, .~. +x16)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x16)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.0060 -2.0173 -0.4343  0.9868 11.6864 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  12.9745     1.1424  11.358  < 2e-16 ***
## x16          -0.7887     0.1295  -6.089 1.67e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.959 on 111 degrees of freedom
## Multiple R-squared:  0.2504, Adjusted R-squared:  0.2436 
## F-statistic: 37.08 on 1 and 111 DF,  p-value: 1.666e-08
mq2 <- update(mq0, .~. +x17)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x17)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.3912 -2.1912 -0.7825  1.6349 13.2001 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   5.3261     0.6327   8.418 1.51e-13 ***
## x17           0.1913     0.1160   1.649    0.102    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.376 on 111 degrees of freedom
## Multiple R-squared:  0.0239, Adjusted R-squared:  0.01511 
## F-statistic: 2.718 on 1 and 111 DF,  p-value: 0.102
mq2 <- update(mq0, .~. +x18)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x18)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.6436 -1.3141 -0.4282  0.5847 10.8293 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  16.6882     1.0316   16.18   <2e-16 ***
## x18          -1.1431     0.1099  -10.40   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.432 on 111 degrees of freedom
## Multiple R-squared:  0.4935, Adjusted R-squared:  0.4889 
## F-statistic: 108.1 on 1 and 111 DF,  p-value: < 2.2e-16
# Add x6 to the final model (minimum p-value)
mq2f <- update(mq0, .~. +x6)

# Continue iteratively:
mq2 <- update(mq2f, .~. +x1)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.1501 -1.2848 -0.0582  1.0189  7.4326 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.025e+01  1.127e+00  -9.100 4.51e-15 ***
## x6          -2.225e+00  1.512e-01 -14.715  < 2e-16 ***
## x1          -3.033e-04  1.256e-03  -0.242     0.81    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.98 on 110 degrees of freedom
## Multiple R-squared:  0.6673, Adjusted R-squared:  0.6613 
## F-statistic: 110.3 on 2 and 110 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x2)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.8824 -1.1688 -0.1992  1.0145  7.1102 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -10.79519    1.11515  -9.681   <2e-16 ***
## x6           -2.29044    0.14804 -15.472   <2e-16 ***
## x2           -0.01627    0.00645  -2.522   0.0131 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.926 on 110 degrees of freedom
## Multiple R-squared:  0.6853, Adjusted R-squared:  0.6796 
## F-statistic: 119.8 on 2 and 110 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x3)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x3)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.6609 -1.2479 -0.2373  0.9161  7.5433 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.35925    1.13152  -8.271 3.39e-13 ***
## x6          -2.15385    0.14600 -14.753  < 2e-16 ***
## x3          -0.03016    0.01056  -2.855  0.00514 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.911 on 110 degrees of freedom
## Multiple R-squared:  0.6901, Adjusted R-squared:  0.6845 
## F-statistic: 122.5 on 2 and 110 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x4)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x4)
## 
## Residuals:
##    Min     1Q Median     3Q    Max 
## -3.332 -1.189 -0.284  1.074  7.403 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.331641   1.122644  -8.312 2.74e-13 ***
## x6          -2.141164   0.145685 -14.697  < 2e-16 ***
## x4          -0.030093   0.009821  -3.064  0.00275 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.901 on 110 degrees of freedom
## Multiple R-squared:  0.6933, Adjusted R-squared:  0.6877 
## F-statistic: 124.3 on 2 and 110 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x5)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x5)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.5828 -1.4524 -0.1586  1.1689  6.3493 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -9.0022     1.1394  -7.901 2.28e-12 ***
## x6           -2.2660     0.1432 -15.820  < 2e-16 ***
## x5            1.1343     0.3430   3.307  0.00128 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.889 on 110 degrees of freedom
## Multiple R-squared:  0.6972, Adjusted R-squared:  0.6917 
## F-statistic: 126.7 on 2 and 110 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x7)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x7)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.1930 -1.1683 -0.4440  0.9228  7.2713 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -8.31248    1.02430  -8.115 7.58e-13 ***
## x6          -2.06048    0.13176 -15.639  < 2e-16 ***
## x7          -0.42936    0.07035  -6.103 1.59e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.712 on 110 degrees of freedom
## Multiple R-squared:  0.7513, Adjusted R-squared:  0.7468 
## F-statistic: 166.2 on 2 and 110 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x8)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x8)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.6280 -1.1807 -0.3168  0.9252  6.3427 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -11.058044   0.911817 -12.127  < 2e-16 ***
## x6           -2.519571   0.126352 -19.941  < 2e-16 ***
## x8           -0.034613   0.004471  -7.742 5.14e-12 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.594 on 110 degrees of freedom
## Multiple R-squared:  0.7845, Adjusted R-squared:  0.7806 
## F-statistic: 200.3 on 2 and 110 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x9)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x9)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.5490 -1.2200 -0.1636  0.8601  7.4614 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -11.1769     1.1230  -9.952  < 2e-16 ***
## x6           -2.0424     0.1549 -13.184  < 2e-16 ***
## x9            1.4421     0.4753   3.034  0.00301 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.903 on 110 degrees of freedom
## Multiple R-squared:  0.6928, Adjusted R-squared:  0.6873 
## F-statistic: 124.1 on 2 and 110 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x10)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x10)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.7396 -1.1031 -0.1862  0.5767  7.2223 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   0.5478     1.8207   0.301    0.764    
## x6           -2.2921     0.1251 -18.318  < 2e-16 ***
## x10          -1.4027     0.2024  -6.931 2.99e-10 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.652 on 110 degrees of freedom
## Multiple R-squared:  0.7683, Adjusted R-squared:  0.7641 
## F-statistic: 182.4 on 2 and 110 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x11)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x11)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -3.1229 -0.9135 -0.3397  0.4354  6.8664 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -10.5850     0.8653 -12.233  < 2e-16 ***
## x6           -1.7167     0.1283 -13.383  < 2e-16 ***
## x11           1.0987     0.1255   8.755 2.75e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.521 on 110 degrees of freedom
## Multiple R-squared:  0.8038, Adjusted R-squared:  0.8003 
## F-statistic: 225.4 on 2 and 110 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x12)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.43240 -0.14140 -0.00139  0.18146  1.28741 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.271747   0.277411  -0.980   0.3294    
## x6          -0.102734   0.047422  -2.166   0.0324 *  
## x12          0.228826   0.004146  55.191   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3698 on 110 degrees of freedom
## Multiple R-squared:  0.9884, Adjusted R-squared:  0.9882 
## F-statistic:  4686 on 2 and 110 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x13)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x13)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.3930 -1.1510 -0.0407  1.0131  7.3431 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -11.33333    2.27424  -4.983 2.34e-06 ***
## x6           -2.22514    0.14968 -14.866  < 2e-16 ***
## x13           0.06171    0.11376   0.542    0.589    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.978 on 110 degrees of freedom
## Multiple R-squared:  0.668,  Adjusted R-squared:  0.662 
## F-statistic: 110.7 on 2 and 110 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x14)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x14)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.5003 -1.0947 -0.2265  1.1109  7.3546 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -11.3108     1.0221 -11.066  < 2e-16 ***
## x6           -2.2616     0.1334 -16.958  < 2e-16 ***
## x14           2.2218     0.4152   5.351 4.82e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.764 on 110 degrees of freedom
## Multiple R-squared:  0.7359, Adjusted R-squared:  0.7311 
## F-statistic: 153.2 on 2 and 110 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x15)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x15)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.3039 -1.0562 -0.2362  1.0021  6.9502 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -13.1632     1.1069 -11.892  < 2e-16 ***
## x6           -2.2808     0.1313 -17.365  < 2e-16 ***
## x15           2.1028     0.3640   5.777 7.18e-08 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.735 on 110 degrees of freedom
## Multiple R-squared:  0.7446, Adjusted R-squared:   0.74 
## F-statistic: 160.4 on 2 and 110 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x16)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x16)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.3912 -1.1506 -0.0378  1.0161  7.3403 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -11.27216    2.19822  -5.128 1.27e-06 ***
## x6           -2.28561    0.19431 -11.763  < 2e-16 ***
## x16           0.06034    0.11273   0.535    0.594    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.978 on 110 degrees of freedom
## Multiple R-squared:  0.668,  Adjusted R-squared:  0.662 
## F-statistic: 110.7 on 2 and 110 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x17)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x17)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.0562 -1.3128 -0.1708  0.9670  7.4564 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -10.30992    1.13395  -9.092 4.69e-15 ***
## x6           -2.21016    0.15146 -14.592  < 2e-16 ***
## x17           0.02429    0.06898   0.352    0.725    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.98 on 110 degrees of freedom
## Multiple R-squared:  0.6675, Adjusted R-squared:  0.6615 
## F-statistic: 110.4 on 2 and 110 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x18)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x18)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -4.1281 -1.1594 -0.3613  0.8767  7.0361 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -2.0223     2.1589  -0.937    0.351    
## x6           -1.6973     0.1828  -9.287 1.68e-15 ***
## x18          -0.4767     0.1095  -4.355 3.00e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.829 on 110 degrees of freedom
## Multiple R-squared:  0.7161, Adjusted R-squared:  0.7109 
## F-statistic: 138.7 on 2 and 110 DF,  p-value: < 2.2e-16
# Add x12 (minimum p-value)
mq2f <- update(mq2f, .~. +x12)

# New iteration
mq2 <- update(mq2f, .~. +x1)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.44345 -0.14391 -0.00267  0.17740  1.29428 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.2701619  0.2785682  -0.970   0.3343    
## x6          -0.1044433  0.0478729  -2.182   0.0313 *  
## x12          0.2288017  0.0041634  54.955   <2e-16 ***
## x1          -0.0000808  0.0002355  -0.343   0.7322    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3713 on 109 degrees of freedom
## Multiple R-squared:  0.9884, Adjusted R-squared:  0.9881 
## F-statistic:  3099 on 3 and 109 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x2)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.43551 -0.14245 -0.00234  0.17972  1.28751 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.777e-01  2.917e-01  -0.952   0.3433    
## x6          -1.038e-01  4.995e-02  -2.078   0.0401 *  
## x12          2.288e-01  4.287e-03  53.362   <2e-16 ***
## x2          -8.835e-05  1.281e-03  -0.069   0.9451    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3715 on 109 degrees of freedom
## Multiple R-squared:  0.9884, Adjusted R-squared:  0.9881 
## F-statistic:  3095 on 3 and 109 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x3)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x3)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.43402 -0.14516  0.00206  0.17391  1.27943 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.248924   0.277041  -0.899   0.3709    
## x6          -0.109427   0.047539  -2.302   0.0232 *  
## x12          0.227457   0.004262  53.373   <2e-16 ***
## x3          -0.002762   0.002101  -1.315   0.1914    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3686 on 109 degrees of freedom
## Multiple R-squared:  0.9886, Adjusted R-squared:  0.9883 
## F-statistic:  3145 on 3 and 109 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x4)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x4)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.42562 -0.14535 -0.00505  0.17647  1.29249 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.258846   0.277266  -0.934   0.3526    
## x6          -0.108922   0.047668  -2.285   0.0242 *  
## x12          0.227526   0.004295  52.978   <2e-16 ***
## x4          -0.002255   0.001979  -1.140   0.2569    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3693 on 109 degrees of freedom
## Multiple R-squared:  0.9885, Adjusted R-squared:  0.9882 
## F-statistic:  3133 on 3 and 109 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x5)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x5)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.36746 -0.15277  0.01266  0.17534  1.29135 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.23306    0.27674  -0.842   0.4016    
## x6          -0.12448    0.04914  -2.533   0.0127 *  
## x12          0.22696    0.00429  52.905   <2e-16 ***
## x5           0.10826    0.06948   1.558   0.1221    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3674 on 109 degrees of freedom
## Multiple R-squared:  0.9887, Adjusted R-squared:  0.9883 
## F-statistic:  3165 on 3 and 109 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x7)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x7)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.40595 -0.17790  0.02701  0.19071  1.19800 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.218483   0.277406  -0.788    0.433    
## x6          -0.074407   0.050263  -1.480    0.142    
## x12          0.233038   0.004878  47.778   <2e-16 ***
## x7           0.028776   0.017876   1.610    0.110    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3671 on 109 degrees of freedom
## Multiple R-squared:  0.9887, Adjusted R-squared:  0.9884 
## F-statistic:  3170 on 3 and 109 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x8)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x8)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.42751 -0.15002  0.01715  0.16617  1.26693 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.812583   0.295672  -2.748 0.007014 ** 
## x6          -0.234637   0.056012  -4.189 5.71e-05 ***
## x12          0.218838   0.004668  46.877  < 2e-16 ***
## x8          -0.004553   0.001168  -3.897 0.000168 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.348 on 109 degrees of freedom
## Multiple R-squared:  0.9898, Adjusted R-squared:  0.9895 
## F-statistic:  3532 on 3 and 109 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x9)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.77194 -0.09375  0.05089  0.11431  0.68422 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.023302   0.179079   5.714  9.7e-08 ***
## x6          -0.055204   0.027120  -2.036   0.0442 *  
## x12          0.245654   0.002602  94.420  < 2e-16 ***
## x9          -0.882591   0.057964 -15.227  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2101 on 109 degrees of freedom
## Multiple R-squared:  0.9963, Adjusted R-squared:  0.9962 
## F-statistic:  9757 on 3 and 109 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x10)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x10)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.03501 -0.15868  0.02099  0.16530  0.95279 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.097817   0.338754  -6.193 1.07e-08 ***
## x6           0.110020   0.048723   2.258   0.0259 *  
## x12          0.249825   0.004464  55.962  < 2e-16 ***
## x10          0.355942   0.048765   7.299 4.98e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3044 on 109 degrees of freedom
## Multiple R-squared:  0.9922, Adjusted R-squared:  0.992 
## F-statistic:  4626 on 3 and 109 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x11)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x11)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.29883 -0.19587 -0.00159  0.16828  1.09479 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.427092   0.316294   1.350  0.17972    
## x6          -0.036368   0.047730  -0.762  0.44774    
## x12          0.243773   0.005461  44.640  < 2e-16 ***
## x11         -0.157200   0.040198  -3.911  0.00016 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3479 on 109 degrees of freedom
## Multiple R-squared:  0.9898, Adjusted R-squared:  0.9895 
## F-statistic:  3535 on 3 and 109 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x13)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x13)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.44496 -0.13628 -0.00455  0.15979  1.24610 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.135475   0.473051   0.286    0.775    
## x6          -0.097556   0.047644  -2.048    0.043 *  
## x12          0.229143   0.004154  55.157   <2e-16 ***
## x13         -0.022640   0.021309  -1.062    0.290    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3696 on 109 degrees of freedom
## Multiple R-squared:  0.9885, Adjusted R-squared:  0.9882 
## F-statistic:  3128 on 3 and 109 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x14)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x14)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.40654 -0.13205 -0.00347  0.20254  1.30772 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.465315   0.306648  -1.517   0.1321    
## x6          -0.132436   0.051445  -2.574   0.0114 *  
## x12          0.225904   0.004592  49.196   <2e-16 ***
## x14          0.139689   0.096385   1.449   0.1501    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3679 on 109 degrees of freedom
## Multiple R-squared:  0.9886, Adjusted R-squared:  0.9883 
## F-statistic:  3156 on 3 and 109 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x15)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x15)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.38951 -0.13162  0.00449  0.20165  1.30790 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.627728   0.348736  -1.800  0.07462 .  
## x6          -0.140150   0.052155  -2.687  0.00833 ** 
## x12          0.225239   0.004645  48.490  < 2e-16 ***
## x15          0.144471   0.086923   1.662  0.09937 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3668 on 109 degrees of freedom
## Multiple R-squared:  0.9887, Adjusted R-squared:  0.9884 
## F-statistic:  3175 on 3 and 109 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x16)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x16)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.44560 -0.13734 -0.00427  0.15915  1.24832 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.114204   0.459691   0.248    0.804    
## x6          -0.075335   0.054075  -1.393    0.166    
## x12          0.229136   0.004155  55.153   <2e-16 ***
## x16         -0.022227   0.021115  -1.053    0.295    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3696 on 109 degrees of freedom
## Multiple R-squared:  0.9885, Adjusted R-squared:  0.9882 
## F-statistic:  3127 on 3 and 109 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x17)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x17)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.42687 -0.13918 -0.00359  0.17431  1.29364 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.275793   0.280470  -0.983   0.3276    
## x6          -0.102290   0.047763  -2.142   0.0345 *  
## x12          0.228809   0.004167  54.911   <2e-16 ***
## x17          0.001647   0.012949   0.127   0.8990    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3714 on 109 degrees of freedom
## Multiple R-squared:  0.9884, Adjusted R-squared:  0.9881 
## F-statistic:  3096 on 3 and 109 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x18)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.31685 -0.17950  0.01691  0.18996  1.12690 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.431054   0.414322  -3.454 0.000788 ***
## x6          -0.130060   0.045632  -2.850 0.005226 ** 
## x12          0.235933   0.004397  53.664  < 2e-16 ***
## x18          0.085031   0.023465   3.624 0.000443 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3509 on 109 degrees of freedom
## Multiple R-squared:  0.9896, Adjusted R-squared:  0.9894 
## F-statistic:  3473 on 3 and 109 DF,  p-value: < 2.2e-16
# Add x9 (minimum p-value)
mq2f <- update(mq2f, .~. +x9)

# New iteration
mq2 <- update(mq2f, .~. +x1)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.79696 -0.09560  0.03489  0.12107  0.69838 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.0368556  0.1778955   5.828 5.88e-08 ***
## x6          -0.0594654  0.0270364  -2.199    0.030 *  
## x12          0.2457082  0.0025820  95.164  < 2e-16 ***
## x9          -0.8889203  0.0576475 -15.420  < 2e-16 ***
## x1          -0.0002175  0.0001325  -1.641    0.104    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2084 on 108 degrees of freedom
## Multiple R-squared:  0.9964, Adjusted R-squared:  0.9962 
## F-statistic:  7432 on 4 and 108 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x2)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.7437 -0.1100  0.0497  0.1197  0.6785 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.0965677  0.1873341   5.854 5.24e-08 ***
## x6          -0.0438592  0.0284291  -1.543    0.126    
## x12          0.2465274  0.0026806  91.966  < 2e-16 ***
## x9          -0.8894987  0.0580341 -15.327  < 2e-16 ***
## x2           0.0009362  0.0007251   1.291    0.199    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2094 on 108 degrees of freedom
## Multiple R-squared:  0.9963, Adjusted R-squared:  0.9962 
## F-statistic:  7363 on 4 and 108 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x3)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x3)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.76286 -0.08805  0.04025  0.10289  0.66162 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.080406   0.170348   6.342  5.4e-09 ***
## x6          -0.064495   0.025814  -2.498 0.013981 *  
## x12          0.243878   0.002512  97.101  < 2e-16 ***
## x9          -0.897993   0.055067 -16.307  < 2e-16 ***
## x3          -0.004176   0.001138  -3.671 0.000378 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.199 on 108 degrees of freedom
## Multiple R-squared:  0.9967, Adjusted R-squared:  0.9966 
## F-statistic:  8158 on 4 and 108 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x4)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x4)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.74643 -0.06977  0.04584  0.10312  0.68030 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.072640   0.170469   6.292 6.84e-09 ***
## x6          -0.064847   0.025871  -2.507 0.013681 *  
## x12          0.243772   0.002523  96.620  < 2e-16 ***
## x9          -0.901099   0.055237 -16.313  < 2e-16 ***
## x4          -0.003877   0.001073  -3.615 0.000459 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1993 on 108 degrees of freedom
## Multiple R-squared:  0.9967, Adjusted R-squared:  0.9966 
## F-statistic:  8131 on 4 and 108 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x5)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x5)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.78254 -0.09466  0.04556  0.11652  0.67636 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.027103   0.179533   5.721 9.57e-08 ***
## x6          -0.048641   0.028608  -1.700    0.092 .  
## x12          0.246360   0.002779  88.656  < 2e-16 ***
## x9          -0.892494   0.059630 -14.967  < 2e-16 ***
## x5          -0.030024   0.040868  -0.735    0.464    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2105 on 108 degrees of freedom
## Multiple R-squared:  0.9963, Adjusted R-squared:  0.9962 
## F-statistic:  7287 on 4 and 108 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x7)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x7)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.71667 -0.06769  0.01021  0.08369  0.75606 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.129043   0.162027   6.968 2.65e-10 ***
## x6          -0.100759   0.025861  -3.896  0.00017 ***
## x12          0.240430   0.002541  94.628  < 2e-16 ***
## x9          -1.022701   0.058545 -17.469  < 2e-16 ***
## x7          -0.053941   0.010331  -5.221 8.69e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1886 on 108 degrees of freedom
## Multiple R-squared:  0.997,  Adjusted R-squared:  0.9969 
## F-statistic:  9087 on 4 and 108 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x8)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x8)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.79824 -0.08617  0.03007  0.09396  0.69833 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.6312470  0.1906641   3.311  0.00127 ** 
## x6          -0.1389107  0.0320662  -4.332 3.32e-05 ***
## x12          0.2387281  0.0029224  81.690  < 2e-16 ***
## x9          -0.8434107  0.0547228 -15.412  < 2e-16 ***
## x8          -0.0028163  0.0006657  -4.231 4.90e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1955 on 108 degrees of freedom
## Multiple R-squared:  0.9968, Adjusted R-squared:  0.9967 
## F-statistic:  8456 on 4 and 108 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x10)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x10)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.77841 -0.05428  0.03065  0.07882  0.76133 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  3.059885   0.451208   6.782 6.58e-10 ***
## x6          -0.200526   0.038873  -5.158 1.14e-06 ***
## x12          0.236936   0.002976  79.614  < 2e-16 ***
## x9          -1.291647   0.099633 -12.964  < 2e-16 ***
## x10         -0.279980   0.057837  -4.841 4.33e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1913 on 108 degrees of freedom
## Multiple R-squared:  0.997,  Adjusted R-squared:  0.9968 
## F-statistic:  8829 on 4 and 108 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x11)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.71731 -0.04655  0.02823  0.06939  0.77004 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.685088   0.169941   4.031 0.000104 ***
## x6          -0.109118   0.025914  -4.211 5.29e-05 ***
## x12          0.235280   0.002967  79.310  < 2e-16 ***
## x9          -1.137521   0.068872 -16.517  < 2e-16 ***
## x11          0.160224   0.028842   5.555 2.01e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1861 on 108 degrees of freedom
## Multiple R-squared:  0.9971, Adjusted R-squared:  0.997 
## F-statistic:  9330 on 4 and 108 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x13)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x13)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.78334 -0.08513  0.04633  0.11684  0.61500 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.652433   0.277100   5.963 3.17e-08 ***
## x6          -0.046850   0.026393  -1.775   0.0787 .  
## x12          0.246324   0.002528  97.457  < 2e-16 ***
## x9          -0.892679   0.056183 -15.889  < 2e-16 ***
## x13         -0.034154   0.011741  -2.909   0.0044 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2032 on 108 degrees of freedom
## Multiple R-squared:  0.9966, Adjusted R-squared:  0.9964 
## F-statistic:  7821 on 4 and 108 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x14)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x14)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.76344 -0.07728  0.05012  0.11976  0.69875 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.915995   0.197025   4.649 9.48e-06 ***
## x6          -0.070613   0.029567  -2.388   0.0187 *  
## x12          0.244053   0.002876  84.848  < 2e-16 ***
## x9          -0.876416   0.057988 -15.114  < 2e-16 ***
## x14          0.070900   0.055051   1.288   0.2005    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2094 on 108 degrees of freedom
## Multiple R-squared:  0.9963, Adjusted R-squared:  0.9962 
## F-statistic:  7362 on 4 and 108 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x15)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x15)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.76464 -0.08432  0.05347  0.11741  0.69456 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.912112   0.224969   4.054 9.51e-05 ***
## x6          -0.066230   0.030316  -2.185   0.0311 *  
## x12          0.244505   0.002959  82.621  < 2e-16 ***
## x9          -0.876004   0.058606 -14.947  < 2e-16 ***
## x15          0.041203   0.050326   0.819   0.4147    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2104 on 108 degrees of freedom
## Multiple R-squared:  0.9963, Adjusted R-squared:  0.9962 
## F-statistic:  7296 on 4 and 108 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x16)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x16)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.78425 -0.08625  0.04472  0.11937  0.61667 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.633549   0.269983   6.051 2.12e-08 ***
## x6          -0.012424   0.029968  -0.415  0.67929    
## x12          0.246336   0.002525  97.545  < 2e-16 ***
## x9          -0.893327   0.056143 -15.912  < 2e-16 ***
## x16         -0.034237   0.011624  -2.945  0.00395 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.203 on 108 degrees of freedom
## Multiple R-squared:  0.9966, Adjusted R-squared:  0.9964 
## F-statistic:  7835 on 4 and 108 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x17)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x17)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.71382 -0.08869  0.03234  0.10133  0.73003 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.006786   0.176907   5.691  1.1e-07 ***
## x6          -0.050617   0.026861  -1.884   0.0622 .  
## x12          0.245752   0.002568  95.705  < 2e-16 ***
## x9          -0.895510   0.057566 -15.556  < 2e-16 ***
## x17          0.014438   0.007273   1.985   0.0497 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2073 on 108 degrees of freedom
## Multiple R-squared:  0.9964, Adjusted R-squared:  0.9963 
## F-statistic:  7516 on 4 and 108 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x18)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.74519 -0.08646  0.02632  0.10232  0.69880 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.05906    0.32835   6.271 7.57e-09 ***
## x6          -0.02799    0.02672  -1.048 0.297190    
## x12          0.24338    0.00254  95.833  < 2e-16 ***
## x9          -1.02789    0.06759 -15.208  < 2e-16 ***
## x18         -0.06033    0.01638  -3.684 0.000361 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1989 on 108 degrees of freedom
## Multiple R-squared:  0.9967, Adjusted R-squared:  0.9966 
## F-statistic:  8165 on 4 and 108 DF,  p-value: < 2.2e-16
# Add x11 (minimum p-value)
mq2f <- update(mq2f, .~. +x11)

# New iteration
mq2 <- update(mq2f, .~. +x1)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.72938 -0.05485  0.03316  0.06899  0.77366 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  7.001e-01  1.714e-01   4.084 8.56e-05 ***
## x6          -1.094e-01  2.597e-02  -4.214 5.25e-05 ***
## x12          2.356e-01  3.000e-03  78.531  < 2e-16 ***
## x9          -1.133e+00  6.924e-02 -16.366  < 2e-16 ***
## x11          1.558e-01  2.947e-02   5.287 6.63e-07 ***
## x1          -9.186e-05  1.209e-04  -0.760    0.449    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1865 on 107 degrees of freedom
## Multiple R-squared:  0.9971, Adjusted R-squared:  0.997 
## F-statistic:  7435 on 5 and 107 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x2)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.68934 -0.05608  0.02936  0.07388  0.76462 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.7444611  0.1783356   4.174 6.10e-05 ***
## x6          -0.0999040  0.0272390  -3.668 0.000383 ***
## x12          0.2360704  0.0030516  77.359  < 2e-16 ***
## x9          -1.1393966  0.0688340 -16.553  < 2e-16 ***
## x11          0.1581443  0.0288809   5.476 2.91e-07 ***
## x2           0.0007026  0.0006452   1.089 0.278647    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.186 on 107 degrees of freedom
## Multiple R-squared:  0.9971, Adjusted R-squared:  0.997 
## F-statistic:  7477 on 5 and 107 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x3)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x3)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.71951 -0.04905  0.02961  0.07630  0.76152 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.7142786  0.1850077   3.861 0.000194 ***
## x6          -0.1069910  0.0265318  -4.033 0.000104 ***
## x12          0.2356908  0.0031438  74.969  < 2e-16 ***
## x9          -1.1235461  0.0771648 -14.560  < 2e-16 ***
## x11          0.1501109  0.0381216   3.938 0.000147 ***
## x3          -0.0005735  0.0014064  -0.408 0.684219    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1868 on 107 degrees of freedom
## Multiple R-squared:  0.9971, Adjusted R-squared:  0.997 
## F-statistic:  7406 on 5 and 107 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x4)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x4)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.71717 -0.04900  0.02883  0.07507  0.76444 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.7116525  0.1836588   3.875 0.000184 ***
## x6          -0.1071992  0.0264752  -4.049 9.75e-05 ***
## x12          0.2356456  0.0031218  75.483  < 2e-16 ***
## x9          -1.1248655  0.0763534 -14.732  < 2e-16 ***
## x11          0.1507311  0.0377980   3.988 0.000122 ***
## x4          -0.0005128  0.0013125  -0.391 0.696773    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1868 on 107 degrees of freedom
## Multiple R-squared:  0.9971, Adjusted R-squared:  0.997 
## F-statistic:  7405 on 5 and 107 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x5)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x5)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.73521 -0.05168  0.01791  0.08078  0.75836 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.680300   0.168873   4.028 0.000105 ***
## x6          -0.098740   0.026601  -3.712 0.000328 ***
## x12          0.236236   0.003011  78.454  < 2e-16 ***
## x9          -1.165011   0.070683 -16.482  < 2e-16 ***
## x11          0.165860   0.028886   5.742 8.86e-08 ***
## x5          -0.056152   0.036186  -1.552 0.123673    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1849 on 107 degrees of freedom
## Multiple R-squared:  0.9972, Adjusted R-squared:  0.997 
## F-statistic:  7562 on 5 and 107 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x7)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x7)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.70985 -0.05390  0.02139  0.06674  0.77462 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.852503   0.196842   4.331 3.36e-05 ***
## x6          -0.112195   0.025778  -4.352 3.09e-05 ***
## x12          0.236377   0.003018  78.333  < 2e-16 ***
## x9          -1.116164   0.069549 -16.049  < 2e-16 ***
## x11          0.104804   0.044155   2.374   0.0194 *  
## x7          -0.025726   0.015609  -1.648   0.1023    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1847 on 107 degrees of freedom
## Multiple R-squared:  0.9972, Adjusted R-squared:  0.9971 
## F-statistic:  7583 on 5 and 107 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x8)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x8)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.73249 -0.05179  0.02669  0.06731  0.76115 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.6292997  0.1817498   3.462 0.000771 ***
## x6          -0.1237363  0.0308829  -4.007 0.000114 ***
## x12          0.2349454  0.0029945  78.458  < 2e-16 ***
## x9          -1.0892258  0.0884195 -12.319  < 2e-16 ***
## x11          0.1365173  0.0396491   3.443 0.000822 ***
## x8          -0.0007602  0.0008714  -0.872 0.384912    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1863 on 107 degrees of freedom
## Multiple R-squared:  0.9971, Adjusted R-squared:  0.997 
## F-statistic:  7447 on 5 and 107 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x10)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x10)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.51527 -0.06311  0.01123  0.07509  0.76495 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.806484   2.941230  -3.334 0.001176 ** 
## x6           0.329184   0.125133   2.631 0.009779 ** 
## x12          0.233187   0.002877  81.041  < 2e-16 ***
## x9          -0.314002   0.239618  -1.310 0.192856    
## x11          0.797302   0.180422   4.419 2.38e-05 ***
## x10          1.257455   0.351987   3.572 0.000532 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1767 on 107 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  8279 on 5 and 107 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x13)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x13)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.72812 -0.06004  0.01888  0.08413  0.72645 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.041637   0.281701   3.698 0.000345 ***
## x6          -0.099951   0.026381  -3.789 0.000251 ***
## x12          0.236558   0.003055  77.431  < 2e-16 ***
## x9          -1.119892   0.069302 -16.160  < 2e-16 ***
## x11          0.145856   0.030052   4.854 4.15e-06 ***
## x13         -0.017710   0.011203  -1.581 0.116868    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1848 on 107 degrees of freedom
## Multiple R-squared:  0.9972, Adjusted R-squared:  0.997 
## F-statistic:  7568 on 5 and 107 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x14)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x14)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.71920 -0.06078  0.02538  0.07557  0.76608 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.742412   0.177787   4.176 6.07e-05 ***
## x6          -0.101395   0.026847  -3.777 0.000261 ***
## x12          0.235629   0.002981  79.034  < 2e-16 ***
## x9          -1.166892   0.073921 -15.786  < 2e-16 ***
## x11          0.175448   0.032037   5.476 2.90e-07 ***
## x14         -0.059109   0.054340  -1.088 0.279144    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.186 on 107 degrees of freedom
## Multiple R-squared:  0.9971, Adjusted R-squared:  0.997 
## F-statistic:  7477 on 5 and 107 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x15)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x15)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.72386 -0.05873  0.01717  0.08363  0.76191 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.853168   0.197782   4.314 3.59e-05 ***
## x6          -0.095265   0.027091  -3.516 0.000643 ***
## x12          0.236066   0.002984  79.122  < 2e-16 ***
## x9          -1.185455   0.074431 -15.927  < 2e-16 ***
## x11          0.182353   0.031692   5.754 8.39e-08 ***
## x15         -0.079594   0.048918  -1.627 0.106664    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1847 on 107 degrees of freedom
## Multiple R-squared:  0.9972, Adjusted R-squared:  0.9971 
## F-statistic:  7578 on 5 and 107 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x16)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x16)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.72874 -0.05916  0.01862  0.08536  0.72697 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.033964   0.275174   3.757  0.00028 ***
## x6          -0.081883   0.030819  -2.657  0.00909 ** 
## x12          0.236589   0.003056  77.417  < 2e-16 ***
## x9          -1.119672   0.069273 -16.163  < 2e-16 ***
## x11          0.145492   0.030070   4.838 4.42e-06 ***
## x16         -0.017828   0.011109  -1.605  0.11147    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1848 on 107 degrees of freedom
## Multiple R-squared:  0.9972, Adjusted R-squared:  0.9971 
## F-statistic:  7573 on 5 and 107 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x17)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x17)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.69063 -0.05249  0.01616  0.07319  0.78930 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.690837   0.169899   4.066 9.15e-05 ***
## x6          -0.104607   0.026231  -3.988 0.000122 ***
## x12          0.235757   0.002997  78.656  < 2e-16 ***
## x9          -1.133422   0.068925 -16.444  < 2e-16 ***
## x11          0.153605   0.029469   5.213 9.14e-07 ***
## x17          0.007188   0.006672   1.077 0.283764    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.186 on 107 degrees of freedom
## Multiple R-squared:  0.9971, Adjusted R-squared:  0.997 
## F-statistic:  7475 on 5 and 107 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x18)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.71353 -0.05722  0.01883  0.07820  0.76401 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.185553   0.368657   3.216  0.00172 ** 
## x6          -0.089470   0.028790  -3.108  0.00242 ** 
## x12          0.235786   0.002967  79.469  < 2e-16 ***
## x9          -1.164082   0.070625 -16.482  < 2e-16 ***
## x11          0.137097   0.032420   4.229 4.97e-05 ***
## x18         -0.026308   0.017226  -1.527  0.12965    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.185 on 107 degrees of freedom
## Multiple R-squared:  0.9972, Adjusted R-squared:  0.997 
## F-statistic:  7556 on 5 and 107 DF,  p-value: < 2.2e-16
# Add x10 (lowest p-value)
mq2f <- update(mq2f, .~. +x10)

# Final iteration
mq2 <- update(mq2f, .~. +x1)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x10 + x1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.49169 -0.06137  0.01462  0.06378  0.76990 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.008e+01  2.948e+00  -3.419 0.000892 ***
## x6           3.410e-01  1.254e-01   2.719 0.007654 ** 
## x12          2.336e-01  2.893e-03  80.731  < 2e-16 ***
## x9          -2.849e-01  2.407e-01  -1.183 0.239326    
## x11          8.090e-01  1.805e-01   4.482 1.88e-05 ***
## x10          1.293e+00  3.529e-01   3.663 0.000392 ***
## x1          -1.292e-04  1.149e-04  -1.124 0.263378    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1765 on 106 degrees of freedom
## Multiple R-squared:  0.9975, Adjusted R-squared:  0.9973 
## F-statistic:  6917 on 6 and 106 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x2)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x10 + x2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.51283 -0.07031  0.00972  0.07710  0.76097 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.5565782  2.9592538  -3.229 0.001652 ** 
## x6           0.3275380  0.1253027   2.614 0.010251 *  
## x12          0.2338226  0.0029747  78.605  < 2e-16 ***
## x9          -0.3315242  0.2407826  -1.377 0.171456    
## x11          0.7832747  0.1813844   4.318 3.55e-05 ***
## x10          1.2328540  0.3535880   3.487 0.000713 ***
## x2           0.0005283  0.0006160   0.858 0.393036    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.177 on 106 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  6882 on 6 and 106 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x3)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x10 + x3)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.51590 -0.06244  0.01079  0.07741  0.76314 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.7744978  2.9756395  -3.285 0.001384 ** 
## x6           0.3285635  0.1259006   2.610 0.010372 *  
## x12          0.2332803  0.0030648  76.116  < 2e-16 ***
## x9          -0.3130354  0.2409683  -1.299 0.196738    
## x11          0.7935769  0.1857972   4.271 4.25e-05 ***
## x10          1.2543693  0.3552397   3.531 0.000614 ***
## x3          -0.0001226  0.0013426  -0.091 0.927405    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1776 on 106 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  6835 on 6 and 106 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x4)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x10 + x4)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.51534 -0.06308  0.01113  0.07529  0.76483 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.803e+00  2.982e+00  -3.287 0.001373 ** 
## x6           3.291e-01  1.261e-01   2.610 0.010350 *  
## x12          2.332e-01  3.047e-03  76.537  < 2e-16 ***
## x9          -3.140e-01  2.408e-01  -1.304 0.195097    
## x11          7.969e-01  1.865e-01   4.274 4.21e-05 ***
## x10          1.257e+00  3.559e-01   3.532 0.000612 ***
## x4          -1.113e-05  1.255e-03  -0.009 0.992943    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1776 on 106 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  6835 on 6 and 106 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x5)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x10 + x5)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.49098 -0.05739 -0.00121  0.07721  0.75347 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.776319   2.919701  -3.348 0.001126 ** 
## x6           0.337936   0.124334   2.718 0.007674 ** 
## x12          0.234135   0.002916  80.284  < 2e-16 ***
## x9          -0.343781   0.238578  -1.441 0.152543    
## x11          0.800729   0.179110   4.471 1.96e-05 ***
## x10          1.253275   0.349413   3.587 0.000508 ***
## x5          -0.055237   0.034334  -1.609 0.110631    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1754 on 106 degrees of freedom
## Multiple R-squared:  0.9975, Adjusted R-squared:  0.9973 
## F-statistic:  7002 on 6 and 106 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x7)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x10 + x7)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.51737 -0.06645  0.00246  0.06932  0.76914 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.415048   2.933487  -3.210 0.001760 ** 
## x6           0.316321   0.124615   2.538 0.012590 *  
## x12          0.234213   0.002935  79.789  < 2e-16 ***
## x9          -0.313989   0.238090  -1.319 0.190084    
## x11          0.733211   0.184028   3.984 0.000124 ***
## x10          1.228419   0.350249   3.507 0.000665 ***
## x7          -0.022922   0.014867  -1.542 0.126086    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1756 on 106 degrees of freedom
## Multiple R-squared:  0.9975, Adjusted R-squared:  0.9973 
## F-statistic:  6989 on 6 and 106 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x8)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x10 + x8)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.50911 -0.06348  0.00993  0.07093  0.75717 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.7812150  2.9462008  -3.320 0.001235 ** 
## x6           0.3132250  0.1268878   2.469 0.015166 *  
## x12          0.2329080  0.0029028  80.236  < 2e-16 ***
## x9          -0.2773696  0.2442634  -1.136 0.258712    
## x11          0.7719437  0.1834281   4.208  5.4e-05 ***
## x10          1.2485469  0.3527343   3.540 0.000596 ***
## x8          -0.0006685  0.0008283  -0.807 0.421449    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.177 on 106 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  6877 on 6 and 106 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x13)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x10 + x13)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.53524 -0.06405  0.00911  0.07310  0.73104 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.129835   2.978665  -3.065 0.002760 ** 
## x6           0.319740   0.124961   2.559 0.011917 *  
## x12          0.234266   0.002988  78.405  < 2e-16 ***
## x9          -0.331428   0.239258  -1.385 0.168889    
## x11          0.761912   0.181944   4.188 5.84e-05 ***
## x10          1.209788   0.352838   3.429 0.000865 ***
## x13         -0.013855   0.010738  -1.290 0.199767    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1762 on 106 degrees of freedom
## Multiple R-squared:  0.9975, Adjusted R-squared:  0.9973 
## F-statistic:  6943 on 6 and 106 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x14)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x10 + x14)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.52785 -0.06158  0.00979  0.07439  0.76238 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.526784   2.969195  -3.209 0.001765 ** 
## x6           0.324352   0.125530   2.584 0.011131 *  
## x12          0.233472   0.002906  80.328  < 2e-16 ***
## x9          -0.352803   0.245316  -1.438 0.153335    
## x11          0.792988   0.180854   4.385 2.75e-05 ***
## x10          1.228585   0.354650   3.464 0.000769 ***
## x14         -0.040036   0.052037  -0.769 0.443385    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1771 on 106 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  6873 on 6 and 106 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x15)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x10 + x15)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.52826 -0.06506  0.00912  0.07208  0.75869 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.268550   2.957104  -3.134 0.002228 ** 
## x6           0.323284   0.124735   2.592 0.010894 *  
## x12          0.233892   0.002914  80.272  < 2e-16 ***
## x9          -0.383809   0.244259  -1.571 0.119089    
## x11          0.790310   0.179812   4.395 2.64e-05 ***
## x10          1.208975   0.352489   3.430 0.000862 ***
## x15         -0.063192   0.046874  -1.348 0.180489    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1761 on 106 degrees of freedom
## Multiple R-squared:  0.9975, Adjusted R-squared:  0.9973 
## F-statistic:  6952 on 6 and 106 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x16)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x10 + x16)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.53589 -0.06302  0.00988  0.07363  0.73164 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.11891    2.97891  -3.061 0.002794 ** 
## x6           0.33299    0.12476   2.669 0.008804 ** 
## x12          0.23429    0.00299  78.350  < 2e-16 ***
## x9          -0.33278    0.23928  -1.391 0.167212    
## x11          0.76057    0.18204   4.178 6.06e-05 ***
## x10          1.20758    0.35293   3.422 0.000886 ***
## x16         -0.01387    0.01065  -1.302 0.195760    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1762 on 106 degrees of freedom
## Multiple R-squared:  0.9975, Adjusted R-squared:  0.9973 
## F-statistic:  6944 on 6 and 106 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x17)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x10 + x17)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.52291 -0.05896  0.01057  0.07494  0.77187 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.557347   3.021370  -3.163 0.002036 ** 
## x6           0.320453   0.127614   2.511 0.013544 *  
## x12          0.233405   0.002942  79.323  < 2e-16 ***
## x9          -0.331952   0.244942  -1.355 0.178228    
## x11          0.779961   0.186527   4.181 5.98e-05 ***
## x10          1.227838   0.361470   3.397 0.000961 ***
## x17          0.002537   0.006511   0.390 0.697543    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1774 on 106 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  6845 on 6 and 106 DF,  p-value: < 2.2e-16
mq2 <- update(mq2f, .~. +x18)
summary(mq2)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x10 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.53104 -0.06386  0.01086  0.06894  0.76057 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.026514   3.005359  -3.003 0.003330 ** 
## x6           0.327339   0.124877   2.621 0.010047 *  
## x12          0.233651   0.002897  80.656  < 2e-16 ***
## x9          -0.365582   0.242902  -1.505 0.135282    
## x11          0.755445   0.183352   4.120 7.53e-05 ***
## x10          1.209436   0.353488   3.421 0.000886 ***
## x18         -0.019940   0.016529  -1.206 0.230353    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1764 on 106 degrees of freedom
## Multiple R-squared:  0.9975, Adjusted R-squared:  0.9973 
## F-statistic:  6929 on 6 and 106 DF,  p-value: < 2.2e-16
# No further significant variables present.
# IDENTIFIED MODEL:
# lm(formula = y ~ x6 + x12 + x9 + x11 + x10)
# Summary information:
summary(mq2f)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x10)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.51527 -0.06311  0.01123  0.07509  0.76495 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.806484   2.941230  -3.334 0.001176 ** 
## x6           0.329184   0.125133   2.631 0.009779 ** 
## x12          0.233187   0.002877  81.041  < 2e-16 ***
## x9          -0.314002   0.239618  -1.310 0.192856    
## x11          0.797302   0.180422   4.419 2.38e-05 ***
## x10          1.257455   0.351987   3.572 0.000532 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1767 on 107 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  8279 on 5 and 107 DF,  p-value: < 2.2e-16
# 3rd Approach: P-VALUE METHOD "MIXED"
# • The procedure starts with the forward method considering the null model and
# iteratively adds the variable with a significant effect that has the smallest p-value.
# • If after adding significant effect variables, others in the
# model become non-significant, they are removed.
# • The procedure ends when there are no more variables to add or remove
# based on the p-value.

# Setting the starting model based on the previous "FORWARD" strategy
# (evaluating if adding a variable makes another one non-significant)
mq3f <- update(mq0, .~. +x6 + x12)
summary(mq3f)
## 
## Call:
## lm(formula = y ~ x6 + x12)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -1.43240 -0.14140 -0.00139  0.18146  1.28741 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.271747   0.277411  -0.980   0.3294    
## x6          -0.102734   0.047422  -2.166   0.0324 *  
## x12          0.228826   0.004146  55.191   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.3698 on 110 degrees of freedom
## Multiple R-squared:  0.9884, Adjusted R-squared:  0.9882 
## F-statistic:  4686 on 2 and 110 DF,  p-value: < 2.2e-16
# The significance of x6 is slightly reduced, but sufficient to keep
# both.
# Adding the third identified variable:
mq3f <- update(mq3f, .~. +x9)
summary(mq3f)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.77194 -0.09375  0.05089  0.11431  0.68422 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.023302   0.179079   5.714  9.7e-08 ***
## x6          -0.055204   0.027120  -2.036   0.0442 *  
## x12          0.245654   0.002602  94.420  < 2e-16 ***
## x9          -0.882591   0.057964 -15.227  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2101 on 109 degrees of freedom
## Multiple R-squared:  0.9963, Adjusted R-squared:  0.9962 
## F-statistic:  9757 on 3 and 109 DF,  p-value: < 2.2e-16
# The significance is not altered.
# Adding the fourth identified significant variable
mq3f <- update(mq3f, .~. +x11)
summary(mq3f)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.71731 -0.04655  0.02823  0.06939  0.77004 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.685088   0.169941   4.031 0.000104 ***
## x6          -0.109118   0.025914  -4.211 5.29e-05 ***
## x12          0.235280   0.002967  79.310  < 2e-16 ***
## x9          -1.137521   0.068872 -16.517  < 2e-16 ***
## x11          0.160224   0.028842   5.555 2.01e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1861 on 108 degrees of freedom
## Multiple R-squared:  0.9971, Adjusted R-squared:  0.997 
## F-statistic:  9330 on 4 and 108 DF,  p-value: < 2.2e-16
# The significance of all variables has now increased
# Adding the fifth significant variable
mq3f <- update(mq3f, .~. +x10)
summary(mq3f)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x10)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.51527 -0.06311  0.01123  0.07509  0.76495 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.806484   2.941230  -3.334 0.001176 ** 
## x6           0.329184   0.125133   2.631 0.009779 ** 
## x12          0.233187   0.002877  81.041  < 2e-16 ***
## x9          -0.314002   0.239618  -1.310 0.192856    
## x11          0.797302   0.180422   4.419 2.38e-05 ***
## x10          1.257455   0.351987   3.572 0.000532 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1767 on 107 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  8279 on 5 and 107 DF,  p-value: < 2.2e-16
# Now x9 becomes non-significant, removing it
mq3f <- update(mq3f, .~. -x9)
summary(mq3f)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x11 + x10)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.54633 -0.05866  0.00924  0.07217  0.76854 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -13.514137   0.806207  -16.76   <2e-16 ***
## x6            0.485352   0.038286   12.68   <2e-16 ***
## x12           0.232624   0.002854   81.50   <2e-16 ***
## x11           1.015592   0.069539   14.61   <2e-16 ***
## x10           1.701196   0.096391   17.65   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1773 on 108 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic: 1.028e+04 on 4 and 108 DF,  p-value: < 2.2e-16
# Since there is a difference from the previous "FORWARD" procedure, now checking
# for the presence of other significant variables
mq3 <- update(mq3f, .~. +x1)
summary(mq3)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x11 + x10 + x1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.51686 -0.07425  0.01495  0.05828  0.77368 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.343e+01  8.065e-01 -16.657   <2e-16 ***
## x6           4.824e-01  3.826e-02  12.609   <2e-16 ***
## x12          2.331e-01  2.872e-03  81.167   <2e-16 ***
## x11          1.006e+00  6.977e-02  14.418   <2e-16 ***
## x10          1.695e+00  9.628e-02  17.600   <2e-16 ***
## x1          -1.438e-04  1.144e-04  -1.257    0.212    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1768 on 107 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  8269 on 5 and 107 DF,  p-value: < 2.2e-16
mq3 <- update(mq3f, .~. +x2)
summary(mq3)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x11 + x10 + x2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.54571 -0.06362 -0.00261  0.07186  0.76528 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.348e+01  8.095e-01  -16.65   <2e-16 ***
## x6           4.915e-01  3.924e-02   12.52   <2e-16 ***
## x12          2.331e-01  2.946e-03   79.14   <2e-16 ***
## x11          1.014e+00  6.972e-02   14.54   <2e-16 ***
## x10          1.701e+00  9.659e-02   17.61   <2e-16 ***
## x2           4.563e-04  6.164e-04    0.74    0.461    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1777 on 107 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  8190 on 5 and 107 DF,  p-value: < 2.2e-16
mq3 <- update(mq3f, .~. +x3)
summary(mq3)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x11 + x10 + x3)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.54720 -0.06082  0.00899  0.06976  0.76558 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.344e+01  9.396e-01 -14.308   <2e-16 ***
## x6           4.836e-01  4.032e-02  11.994   <2e-16 ***
## x12          2.328e-01  3.050e-03  76.320   <2e-16 ***
## x11          1.008e+00  8.490e-02  11.877   <2e-16 ***
## x10          1.694e+00  1.085e-01  15.619   <2e-16 ***
## x3          -1.992e-04  1.346e-03  -0.148    0.883    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1781 on 107 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  8150 on 5 and 107 DF,  p-value: < 2.2e-16
mq3 <- update(mq3f, .~. +x4)
summary(mq3)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x11 + x10 + x4)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.54659 -0.05924  0.00897  0.07173  0.76808 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.350e+01  9.299e-01 -14.516   <2e-16 ***
## x6           4.850e-01  4.019e-02  12.065   <2e-16 ***
## x12          2.327e-01  3.028e-03  76.824   <2e-16 ***
## x11          1.014e+00  8.419e-02  12.044   <2e-16 ***
## x10          1.700e+00  1.076e-01  15.794   <2e-16 ***
## x4          -4.242e-05  1.259e-03  -0.034    0.973    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1781 on 107 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  8148 on 5 and 107 DF,  p-value: < 2.2e-16
mq3 <- update(mq3f, .~. +x5)
summary(mq3)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x11 + x10 + x5)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.52646 -0.07047 -0.00075  0.07733  0.75818 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -13.813256   0.826269 -16.718   <2e-16 ***
## x6            0.507277   0.040800  12.433   <2e-16 ***
## x12           0.233455   0.002892  80.713   <2e-16 ***
## x11           1.038044   0.070760  14.670   <2e-16 ***
## x10           1.736465   0.098710  17.592   <2e-16 ***
## x5           -0.051398   0.034402  -1.494    0.138    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1763 on 107 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  8319 on 5 and 107 DF,  p-value: < 2.2e-16
mq3 <- update(mq3f, .~. +x7)
summary(mq3)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x11 + x10 + x7)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.54842 -0.07179  0.01009  0.06365  0.77274 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -13.122529   0.840731 -15.608   <2e-16 ***
## x6            0.472482   0.038958  12.128   <2e-16 ***
## x12           0.233649   0.002914  80.178   <2e-16 ***
## x11           0.951489   0.080720  11.787   <2e-16 ***
## x10           1.672139   0.097638  17.126   <2e-16 ***
## x7           -0.022923   0.014918  -1.537    0.127    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1762 on 107 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  8328 on 5 and 107 DF,  p-value: < 2.2e-16
mq3 <- update(mq3f, .~. +x8)
summary(mq3)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x11 + x10 + x8)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.53398 -0.06481  0.01082  0.06448  0.75820 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.294e+01  9.803e-01 -13.196  < 2e-16 ***
## x6           4.422e-01  5.658e-02   7.816 4.02e-12 ***
## x12          2.324e-01  2.865e-03  81.090  < 2e-16 ***
## x11          9.515e-01  9.312e-02  10.217  < 2e-16 ***
## x10          1.625e+00  1.215e-01  13.374  < 2e-16 ***
## x8          -8.433e-04  8.150e-04  -1.035    0.303    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1773 on 107 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  8230 on 5 and 107 DF,  p-value: < 2.2e-16
mq3 <- update(mq3f, .~. +x13)
summary(mq3)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x11 + x10 + x13)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.56670 -0.07297  0.00859  0.07856  0.73688 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -13.071787   0.883806 -14.790   <2e-16 ***
## x6            0.484622   0.038209  12.683   <2e-16 ***
## x12           0.233608   0.002962  78.856   <2e-16 ***
## x11           0.993726   0.071710  13.858   <2e-16 ***
## x10           1.679551   0.097838  17.167   <2e-16 ***
## x13          -0.013015   0.010767  -1.209    0.229    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1769 on 107 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  8260 on 5 and 107 DF,  p-value: < 2.2e-16
mq3 <- update(mq3f, .~. +x14)
summary(mq3)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x11 + x10 + x14)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.55643 -0.05897  0.01077  0.07274  0.76724 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -13.624011   0.840632 -16.207   <2e-16 ***
## x6            0.494258   0.042641  11.591   <2e-16 ***
## x12           0.232756   0.002878  80.880   <2e-16 ***
## x11           1.029543   0.075560  13.626   <2e-16 ***
## x10           1.717181   0.102271  16.791   <2e-16 ***
## x14          -0.024651   0.051179  -0.482    0.631    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.178 on 107 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  8166 on 5 and 107 DF,  p-value: < 2.2e-16
mq3 <- update(mq3f, .~. +x15)
summary(mq3)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x11 + x10 + x15)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.56130 -0.06589  0.00677  0.07269  0.76443 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -13.729715   0.832619 -16.490   <2e-16 ***
## x6            0.507050   0.043673  11.610   <2e-16 ***
## x12           0.233060   0.002885  80.789   <2e-16 ***
## x11           1.046865   0.075841  13.803   <2e-16 ***
## x10           1.738969   0.103085  16.869   <2e-16 ***
## x15          -0.047578   0.046122  -1.032    0.305    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1773 on 107 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  8229 on 5 and 107 DF,  p-value: < 2.2e-16
mq3 <- update(mq3f, .~. +x16)
summary(mq3)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x11 + x10 + x16)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.56736 -0.07224  0.00831  0.07822  0.73758 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -13.078257   0.880799 -14.848   <2e-16 ***
## x6            0.497649   0.039520  12.592   <2e-16 ***
## x12           0.233623   0.002965  78.806   <2e-16 ***
## x11           0.993438   0.071742  13.847   <2e-16 ***
## x10           1.679357   0.097844  17.164   <2e-16 ***
## x16          -0.012978   0.010681  -1.215    0.227    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1769 on 107 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  8261 on 5 and 107 DF,  p-value: < 2.2e-16
mq3 <- update(mq3f, .~. +x17)
summary(mq3)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x11 + x10 + x17)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.54959 -0.05685  0.00601  0.07171  0.77101 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.350e+01  8.153e-01 -16.559   <2e-16 ***
## x6           4.854e-01  3.846e-02  12.620   <2e-16 ***
## x12          2.327e-01  2.906e-03  80.079   <2e-16 ***
## x11          1.014e+00  7.093e-02  14.294   <2e-16 ***
## x10          1.700e+00  9.743e-02  17.446   <2e-16 ***
## x17          8.781e-04  6.420e-03   0.137    0.891    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1781 on 107 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  8150 on 5 and 107 DF,  p-value: < 2.2e-16
mq3 <- update(mq3f, .~. +x18)
summary(mq3)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x11 + x10 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.56262 -0.06196  0.00829  0.07138  0.76559 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -13.380743   0.818676 -16.344   <2e-16 ***
## x6            0.503931   0.043000  11.719   <2e-16 ***
## x12           0.232913   0.002872  81.100   <2e-16 ***
## x11           1.010910   0.069744  14.495   <2e-16 ***
## x10           1.720606   0.098571  17.455   <2e-16 ***
## x18          -0.015561   0.016367  -0.951    0.344    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1774 on 107 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  8217 on 5 and 107 DF,  p-value: < 2.2e-16
# NO FURTHER VARIABLES TO ADD/REMOVE.
# IDENTIFIED MODEL:
# lm(formula = y ~ x6 + x12 + x11 + x10)
# Summary information:
summary(mq3f)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x11 + x10)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.54633 -0.05866  0.00924  0.07217  0.76854 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -13.514137   0.806207  -16.76   <2e-16 ***
## x6            0.485352   0.038286   12.68   <2e-16 ***
## x12           0.232624   0.002854   81.50   <2e-16 ***
## x11           1.015592   0.069539   14.61   <2e-16 ***
## x10           1.701196   0.096391   17.65   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1773 on 108 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic: 1.028e+04 on 4 and 108 DF,  p-value: < 2.2e-16
# 4th Approach: LIKELIHOOD FUNCTIONS COMPARISON (FORWARD WITH K=0)
# Starting from the null model
forw_lik <- step(mq0, scope=formula(mq), direction="forward", k=0)
## Start:  AIC=275.71
## y ~ 1
## 
##        Df Sum of Sq     RSS     AIC
## + x12   1   1280.71   15.68 -223.16
## + x6    1    864.86  431.53  151.41
## + x18   1    639.73  656.66  198.86
## + x11   1    627.98  668.41  200.86
## + x16   1    324.59  971.80  243.15
## + x9    1    268.98 1027.41  249.44
## + x7    1    257.31 1039.08  250.71
## + x4    1    118.04 1178.34  264.93
## + x3    1     99.74 1196.65  266.67
## + x10   1     79.79 1216.60  268.54
## + x14   1     58.82 1237.57  270.47
## + x15   1     57.69 1238.69  270.57
## + x17   1     30.99 1265.40  272.98
## + x1    1     16.08 1280.31  274.30
## + x5    1     10.87 1285.52  274.76
## + x8    1      7.31 1289.08  275.07
## + x13   1      1.32 1295.07  275.60
## + x2    1      0.74 1295.65  275.65
## <none>              1296.39  275.71
## 
## Step:  AIC=-223.16
## y ~ x12
## 
##        Df Sum of Sq     RSS     AIC
## + x9    1   10.6896  4.9926 -352.50
## + x10   1    5.1070 10.5752 -267.68
## + x11   1    2.4221 13.2602 -242.12
## + x18   1    1.2584 14.4238 -232.61
## + x7    1    0.6956 14.9866 -228.29
## + x6    1    0.6417 15.0405 -227.88
## + x16   1    0.5279 15.1543 -227.03
## + x8    1    0.3560 15.3262 -225.75
## + x13   1    0.2233 15.4590 -224.78
## + x3    1    0.1568 15.5255 -224.29
## + x4    1    0.1068 15.5754 -223.93
## + x5    1    0.1033 15.5789 -223.91
## + x2    1    0.0468 15.6354 -223.50
## + x15   1    0.0417 15.6405 -223.46
## + x14   1    0.0289 15.6533 -223.37
## + x17   1    0.0112 15.6711 -223.24
## + x1    1    0.0019 15.6803 -223.17
## <none>              15.6822 -223.16
## 
## Step:  AIC=-352.5
## y ~ x12 + x9
## 
##        Df Sum of Sq    RSS     AIC
## + x18   1   0.67626 4.3163 -368.94
## + x11   1   0.63758 4.3550 -367.93
## + x7    1   0.61248 4.3801 -367.29
## + x16   1   0.53335 4.4593 -365.26
## + x3    1   0.46914 4.5235 -363.65
## + x4    1   0.45227 4.5403 -363.23
## + x13   1   0.40222 4.5904 -361.99
## + x17   1   0.19959 4.7930 -357.11
## + x6    1   0.18284 4.8098 -356.71
## + x2    1   0.15157 4.8410 -355.98
## + x8    1   0.14968 4.8429 -355.94
## + x1    1   0.08969 4.9029 -354.54
## + x5    1   0.07865 4.9140 -354.29
## + x10   1   0.06663 4.9260 -354.01
## + x14   1   0.00542 4.9872 -352.62
## + x15   1   0.00127 4.9913 -352.52
## <none>              4.9926 -352.50
## 
## Step:  AIC=-368.94
## y ~ x12 + x9 + x18
## 
##        Df Sum of Sq    RSS     AIC
## + x14   1   0.57258 3.7438 -385.02
## + x11   1   0.32484 3.9915 -377.78
## + x15   1   0.32043 3.9959 -377.66
## + x7    1   0.26037 4.0560 -375.97
## + x4    1   0.18348 4.1329 -373.85
## + x3    1   0.17923 4.1371 -373.73
## + x2    1   0.17023 4.1461 -373.49
## + x17   1   0.10459 4.2118 -371.71
## + x8    1   0.07737 4.2390 -370.99
## + x10   1   0.04404 4.2723 -370.10
## + x6    1   0.04342 4.2729 -370.08
## + x1    1   0.03796 4.2784 -369.94
## + x16   1   0.02984 4.2865 -369.73
## + x5    1   0.02532 4.2910 -369.61
## + x13   1   0.00257 4.3138 -369.01
## <none>              4.3163 -368.94
## 
## Step:  AIC=-385.02
## y ~ x12 + x9 + x18 + x14
## 
##        Df Sum of Sq    RSS     AIC
## + x11   1   0.46634 3.2774 -400.06
## + x10   1   0.37854 3.3652 -397.07
## + x6    1   0.21610 3.5277 -391.74
## + x2    1   0.15441 3.5894 -389.78
## + x15   1   0.13998 3.6038 -389.33
## + x5    1   0.12387 3.6199 -388.83
## + x16   1   0.10409 3.6397 -388.21
## + x8    1   0.07438 3.6694 -387.29
## + x17   1   0.04280 3.7010 -386.32
## + x13   1   0.00461 3.7392 -385.16
## + x1    1   0.00440 3.7394 -385.16
## + x7    1   0.00267 3.7411 -385.10
## + x3    1   0.00076 3.7430 -385.05
## + x4    1   0.00039 3.7434 -385.04
## <none>              3.7438 -385.02
## 
## Step:  AIC=-400.06
## y ~ x12 + x9 + x18 + x14 + x11
## 
##        Df Sum of Sq    RSS     AIC
## + x6    1  0.108660 3.1688 -403.87
## + x7    1  0.053948 3.2235 -401.93
## + x5    1  0.035170 3.2423 -401.28
## + x2    1  0.034323 3.2431 -401.25
## + x13   1  0.031203 3.2462 -401.14
## + x15   1  0.029466 3.2480 -401.08
## + x8    1  0.023633 3.2538 -400.87
## + x1    1  0.016823 3.2606 -400.64
## + x17   1  0.012552 3.2649 -400.49
## + x16   1  0.008206 3.2692 -400.34
## + x10   1  0.003379 3.2740 -400.17
## + x4    1  0.002516 3.2749 -400.14
## + x3    1  0.002240 3.2752 -400.13
## <none>              3.2774 -400.06
## 
## Step:  AIC=-403.87
## y ~ x12 + x9 + x18 + x14 + x11 + x6
## 
##        Df Sum of Sq    RSS     AIC
## + x10   1   0.32012 2.8486 -415.90
## + x2    1   0.05939 3.1094 -406.01
## + x5    1   0.03656 3.1322 -405.18
## + x7    1   0.03283 3.1359 -405.04
## + x16   1   0.02809 3.1407 -404.87
## + x13   1   0.02716 3.1416 -404.84
## + x15   1   0.01545 3.1533 -404.42
## + x1    1   0.01518 3.1536 -404.41
## + x17   1   0.00866 3.1601 -404.18
## + x4    1   0.00787 3.1609 -404.15
## + x3    1   0.00758 3.1612 -404.14
## + x8    1   0.00037 3.1684 -403.88
## <none>              3.1688 -403.87
## 
## Step:  AIC=-415.9
## y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10
## 
##        Df Sum of Sq    RSS     AIC
## + x5    1  0.039604 2.8090 -417.48
## + x2    1  0.034882 2.8138 -417.29
## + x1    1  0.032374 2.8163 -417.19
## + x7    1  0.029136 2.8195 -417.06
## + x13   1  0.020397 2.8283 -416.71
## + x16   1  0.020351 2.8283 -416.71
## + x15   1  0.016779 2.8319 -416.57
## + x3    1  0.001520 2.8471 -415.96
## + x4    1  0.000816 2.8478 -415.93
## + x17   1  0.000454 2.8482 -415.92
## + x8    1  0.000208 2.8484 -415.91
## <none>              2.8487 -415.90
## 
## Step:  AIC=-417.48
## y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10 + x5
## 
##        Df Sum of Sq    RSS     AIC
## + x15   1  0.048922 2.7601 -419.47
## + x7    1  0.041810 2.7672 -419.18
## + x1    1  0.036431 2.7726 -418.96
## + x2    1  0.027843 2.7812 -418.61
## + x13   1  0.017891 2.7912 -418.21
## + x16   1  0.017752 2.7913 -418.20
## + x4    1  0.002365 2.8067 -417.58
## + x3    1  0.002073 2.8070 -417.57
## + x8    1  0.001347 2.8077 -417.54
## + x17   1  0.000605 2.8084 -417.51
## <none>              2.8090 -417.48
## 
## Step:  AIC=-419.47
## y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10 + x5 + x15
## 
##        Df Sum of Sq    RSS     AIC
## + x7    1  0.037507 2.7226 -421.01
## + x2    1  0.032349 2.7278 -420.80
## + x1    1  0.030108 2.7300 -420.71
## + x13   1  0.011770 2.7483 -419.95
## + x16   1  0.011469 2.7487 -419.94
## + x4    1  0.001919 2.7582 -419.55
## + x3    1  0.001255 2.7589 -419.52
## + x8    1  0.000277 2.7598 -419.48
## + x17   1  0.000174 2.7599 -419.48
## <none>              2.7601 -419.47
## 
## Step:  AIC=-421.01
## y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10 + x5 + x15 + x7
## 
##        Df Sum of Sq    RSS     AIC
## + x2    1  0.039221 2.6834 -422.65
## + x1    1  0.029649 2.6930 -422.25
## + x13   1  0.004810 2.7178 -421.21
## + x16   1  0.004510 2.7181 -421.20
## + x3    1  0.003694 2.7189 -421.17
## + x8    1  0.003529 2.7191 -421.16
## + x4    1  0.002923 2.7197 -421.14
## + x17   1  0.000967 2.7216 -421.05
## <none>              2.7226 -421.01
## 
## Step:  AIC=-422.65
## y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10 + x5 + x15 + x7 + x2
## 
##        Df Sum of Sq    RSS     AIC
## + x1    1  0.032456 2.6509 -424.03
## + x3    1  0.007529 2.6759 -422.97
## + x4    1  0.006694 2.6767 -422.94
## + x17   1  0.004438 2.6790 -422.84
## + x13   1  0.002708 2.6807 -422.77
## + x16   1  0.002430 2.6810 -422.76
## + x8    1  0.001066 2.6823 -422.70
## <none>              2.6834 -422.65
## 
## Step:  AIC=-424.03
## y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10 + x5 + x15 + x7 + x2 + 
##     x1
## 
##        Df Sum of Sq    RSS     AIC
## + x3    1 0.0063232 2.6446 -424.30
## + x4    1 0.0059010 2.6450 -424.28
## + x13   1 0.0037863 2.6471 -424.19
## + x16   1 0.0034497 2.6475 -424.18
## + x17   1 0.0030676 2.6479 -424.16
## + x8    1 0.0011118 2.6498 -424.08
## <none>              2.6509 -424.03
## 
## Step:  AIC=-424.3
## y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10 + x5 + x15 + x7 + x2 + 
##     x1 + x3
## 
##        Df Sum of Sq    RSS     AIC
## + x13   1 0.0301187 2.6145 -425.59
## + x16   1 0.0284085 2.6162 -425.52
## + x17   1 0.0032204 2.6414 -424.44
## + x4    1 0.0000409 2.6446 -424.30
## + x8    1 0.0000401 2.6446 -424.30
## <none>              2.6446 -424.30
## 
## Step:  AIC=-425.59
## y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10 + x5 + x15 + x7 + x2 + 
##     x1 + x3 + x13
## 
##        Df Sum of Sq    RSS     AIC
## + x4    1 0.0078665 2.6066 -425.93
## + x17   1 0.0075750 2.6069 -425.92
## + x16   1 0.0058415 2.6086 -425.85
## + x8    1 0.0008129 2.6137 -425.63
## <none>              2.6145 -425.59
## 
## Step:  AIC=-425.93
## y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10 + x5 + x15 + x7 + x2 + 
##     x1 + x3 + x13 + x4
## 
##        Df Sum of Sq    RSS     AIC
## + x17   1 0.0102530 2.5964 -426.38
## + x16   1 0.0080577 2.5986 -426.28
## + x8    1 0.0000583 2.6066 -425.94
## <none>              2.6066 -425.93
## 
## Step:  AIC=-426.38
## y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10 + x5 + x15 + x7 + x2 + 
##     x1 + x3 + x13 + x4 + x17
## 
##        Df  Sum of Sq    RSS     AIC
## + x16   1 0.00136872 2.5950 -426.44
## + x8    1 0.00039342 2.5960 -426.40
## <none>               2.5964 -426.38
## 
## Step:  AIC=-426.44
## y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10 + x5 + x15 + x7 + x2 + 
##     x1 + x3 + x13 + x4 + x17 + x16
## 
##        Df  Sum of Sq    RSS     AIC
## + x8    1 0.00056879 2.5944 -426.46
## <none>               2.5950 -426.44
## 
## Step:  AIC=-426.46
## y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10 + x5 + x15 + x7 + x2 + 
##     x1 + x3 + x13 + x4 + x17 + x16 + x8
# ALWAYS CHOOSES THE COMPLETE MODEL:
# y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10 + x5 + x15 + x7 + x2 + 
# x1 + x3 + x13 + x4 + x17 + x16 + x8
# Summary information
summary(forw_lik)
## 
## Call:
## lm(formula = y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10 + x5 + 
##     x15 + x7 + x2 + x1 + x3 + x13 + x4 + x17 + x16 + x8)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.35240 -0.08275 -0.01367  0.06688  0.70644 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.4932971  4.0122361   0.123  0.90241    
## x12          0.2364541  0.0032508  72.736  < 2e-16 ***
## x9          -0.0349403  0.2545558  -0.137  0.89112    
## x18         -0.5989269  0.1782506  -3.360  0.00113 ** 
## x14          1.4366685  0.4871607   2.949  0.00402 ** 
## x11         -0.3031051  0.3517006  -0.862  0.39098    
## x6           0.4107678  0.4499448   0.913  0.36362    
## x10          1.1866765  0.3453261   3.436  0.00088 ***
## x5          -0.1743371  0.1230087  -1.417  0.15971    
## x15          0.5159395  0.4768871   1.082  0.28207    
## x7          -0.0277227  0.0175895  -1.576  0.11836    
## x2           0.0008409  0.0006320   1.331  0.18654    
## x1          -0.0001159  0.0001097  -1.056  0.29370    
## x3           0.0058477  0.0058386   1.002  0.31913    
## x13         -0.1351995  0.4372948  -0.309  0.75787    
## x4          -0.0027320  0.0046645  -0.586  0.55949    
## x17         -0.0029176  0.0080131  -0.364  0.71659    
## x16          0.1026885  0.4341540   0.237  0.81354    
## x8          -0.0001507  0.0010495  -0.144  0.88616    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1661 on 94 degrees of freedom
## Multiple R-squared:  0.998,  Adjusted R-squared:  0.9976 
## F-statistic:  2604 on 18 and 94 DF,  p-value: < 2.2e-16
# 5th Approach: AIC PENALIZATION CRITERION (FORWARD WITH K=2)
# [Akaike Information Criterion:]
# The penalization term used is penAIC(d) = 2|d|, where given a model Fd(θ),
# the information index is AICd = 2|d| − ℓ(ˆθd; X).[estimator of theta in d]
# The best model within the explored class of models is the one with
# the minimum AICd value.
forw_aic <- step(mq0, scope=formula(mq), direction="forward", k=2)
## Start:  AIC=277.71
## y ~ 1
## 
##        Df Sum of Sq     RSS     AIC
## + x12   1   1280.71   15.68 -219.16
## + x6    1    864.86  431.53  155.41
## + x18   1    639.73  656.66  202.86
## + x11   1    627.98  668.41  204.86
## + x16   1    324.59  971.80  247.15
## + x9    1    268.98 1027.41  253.44
## + x7    1    257.31 1039.08  254.71
## + x4    1    118.04 1178.34  268.93
## + x3    1     99.74 1196.65  270.67
## + x10   1     79.79 1216.60  272.54
## + x14   1     58.82 1237.57  274.47
## + x15   1     57.69 1238.69  274.57
## + x17   1     30.99 1265.40  276.98
## <none>              1296.39  277.71
## + x1    1     16.08 1280.31  278.30
## + x5    1     10.87 1285.52  278.76
## + x8    1      7.31 1289.08  279.07
## + x13   1      1.32 1295.07  279.60
## + x2    1      0.74 1295.65  279.65
## 
## Step:  AIC=-219.16
## y ~ x12
## 
##        Df Sum of Sq     RSS     AIC
## + x9    1   10.6896  4.9926 -346.50
## + x10   1    5.1070 10.5752 -261.68
## + x11   1    2.4221 13.2602 -236.12
## + x18   1    1.2584 14.4238 -226.61
## + x7    1    0.6956 14.9866 -222.29
## + x6    1    0.6417 15.0405 -221.88
## + x16   1    0.5279 15.1543 -221.03
## + x8    1    0.3560 15.3262 -219.75
## <none>              15.6822 -219.16
## + x13   1    0.2233 15.4590 -218.78
## + x3    1    0.1568 15.5255 -218.29
## + x4    1    0.1068 15.5754 -217.93
## + x5    1    0.1033 15.5789 -217.91
## + x2    1    0.0468 15.6354 -217.50
## + x15   1    0.0417 15.6405 -217.46
## + x14   1    0.0289 15.6533 -217.37
## + x17   1    0.0112 15.6711 -217.24
## + x1    1    0.0019 15.6803 -217.17
## 
## Step:  AIC=-346.5
## y ~ x12 + x9
## 
##        Df Sum of Sq    RSS     AIC
## + x18   1   0.67626 4.3163 -360.94
## + x11   1   0.63758 4.3550 -359.93
## + x7    1   0.61248 4.3801 -359.29
## + x16   1   0.53335 4.4593 -357.26
## + x3    1   0.46914 4.5235 -355.65
## + x4    1   0.45227 4.5403 -355.23
## + x13   1   0.40222 4.5904 -353.99
## + x17   1   0.19959 4.7930 -349.11
## + x6    1   0.18284 4.8098 -348.71
## + x2    1   0.15157 4.8410 -347.98
## + x8    1   0.14968 4.8429 -347.94
## + x1    1   0.08969 4.9029 -346.54
## <none>              4.9926 -346.50
## + x5    1   0.07865 4.9140 -346.29
## + x10   1   0.06663 4.9260 -346.01
## + x14   1   0.00542 4.9872 -344.62
## + x15   1   0.00127 4.9913 -344.52
## 
## Step:  AIC=-360.94
## y ~ x12 + x9 + x18
## 
##        Df Sum of Sq    RSS     AIC
## + x14   1   0.57258 3.7438 -375.02
## + x11   1   0.32484 3.9915 -367.78
## + x15   1   0.32043 3.9959 -367.66
## + x7    1   0.26037 4.0560 -365.97
## + x4    1   0.18348 4.1329 -363.85
## + x3    1   0.17923 4.1371 -363.73
## + x2    1   0.17023 4.1461 -363.49
## + x17   1   0.10459 4.2118 -361.71
## + x8    1   0.07737 4.2390 -360.99
## <none>              4.3163 -360.94
## + x10   1   0.04404 4.2723 -360.10
## + x6    1   0.04342 4.2729 -360.08
## + x1    1   0.03796 4.2784 -359.94
## + x16   1   0.02984 4.2865 -359.73
## + x5    1   0.02532 4.2910 -359.61
## + x13   1   0.00257 4.3138 -359.01
## 
## Step:  AIC=-375.02
## y ~ x12 + x9 + x18 + x14
## 
##        Df Sum of Sq    RSS     AIC
## + x11   1   0.46634 3.2774 -388.06
## + x10   1   0.37854 3.3652 -385.07
## + x6    1   0.21610 3.5277 -379.74
## + x2    1   0.15441 3.5894 -377.78
## + x15   1   0.13998 3.6038 -377.33
## + x5    1   0.12387 3.6199 -376.83
## + x16   1   0.10409 3.6397 -376.21
## + x8    1   0.07438 3.6694 -375.29
## <none>              3.7438 -375.02
## + x17   1   0.04280 3.7010 -374.32
## + x13   1   0.00461 3.7392 -373.16
## + x1    1   0.00440 3.7394 -373.16
## + x7    1   0.00267 3.7411 -373.10
## + x3    1   0.00076 3.7430 -373.05
## + x4    1   0.00039 3.7434 -373.04
## 
## Step:  AIC=-388.06
## y ~ x12 + x9 + x18 + x14 + x11
## 
##        Df Sum of Sq    RSS     AIC
## + x6    1  0.108660 3.1688 -389.87
## <none>              3.2774 -388.06
## + x7    1  0.053948 3.2235 -387.93
## + x5    1  0.035170 3.2423 -387.28
## + x2    1  0.034323 3.2431 -387.25
## + x13   1  0.031203 3.2462 -387.14
## + x15   1  0.029466 3.2480 -387.08
## + x8    1  0.023633 3.2538 -386.87
## + x1    1  0.016823 3.2606 -386.64
## + x17   1  0.012552 3.2649 -386.49
## + x16   1  0.008206 3.2692 -386.34
## + x10   1  0.003379 3.2740 -386.17
## + x4    1  0.002516 3.2749 -386.14
## + x3    1  0.002240 3.2752 -386.13
## 
## Step:  AIC=-389.87
## y ~ x12 + x9 + x18 + x14 + x11 + x6
## 
##        Df Sum of Sq    RSS     AIC
## + x10   1   0.32012 2.8486 -399.90
## + x2    1   0.05939 3.1094 -390.01
## <none>              3.1688 -389.87
## + x5    1   0.03656 3.1322 -389.18
## + x7    1   0.03283 3.1359 -389.04
## + x16   1   0.02809 3.1407 -388.87
## + x13   1   0.02716 3.1416 -388.84
## + x15   1   0.01545 3.1533 -388.42
## + x1    1   0.01518 3.1536 -388.41
## + x17   1   0.00866 3.1601 -388.18
## + x4    1   0.00787 3.1609 -388.15
## + x3    1   0.00758 3.1612 -388.14
## + x8    1   0.00037 3.1684 -387.88
## 
## Step:  AIC=-399.9
## y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10
## 
##        Df Sum of Sq    RSS     AIC
## <none>              2.8487 -399.90
## + x5    1  0.039604 2.8090 -399.48
## + x2    1  0.034882 2.8138 -399.29
## + x1    1  0.032374 2.8163 -399.19
## + x7    1  0.029136 2.8195 -399.06
## + x13   1  0.020397 2.8283 -398.71
## + x16   1  0.020351 2.8283 -398.71
## + x15   1  0.016779 2.8319 -398.57
## + x3    1  0.001520 2.8471 -397.96
## + x4    1  0.000816 2.8478 -397.93
## + x17   1  0.000454 2.8482 -397.92
## + x8    1  0.000208 2.8484 -397.91
# CHOOSES THE MODEL:
# y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10
# Summary information
summary(forw_aic)
## 
## Call:
## lm(formula = y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.41987 -0.06391  0.01433  0.07466  0.75100 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.453316   3.649208   0.124 0.901376    
## x12          0.234117   0.002708  86.455  < 2e-16 ***
## x9          -0.103748   0.235824  -0.440 0.660885    
## x18         -0.575286   0.137484  -4.184 5.95e-05 ***
## x14          1.752429   0.431097   4.065 9.30e-05 ***
## x11         -0.221445   0.295084  -0.750 0.454664    
## x6           0.487450   0.123099   3.960 0.000137 ***
## x10          1.135744   0.330636   3.435 0.000850 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1647 on 105 degrees of freedom
## Multiple R-squared:  0.9978, Adjusted R-squared:  0.9977 
## F-statistic:  6811 on 7 and 105 DF,  p-value: < 2.2e-16
# 6th Approach: BIC PENALIZATION CRITERION (FORWARD WITH k=log(length(y)))
# [Bayesian Information Criterion]
# Penalization term: penBIC(d) = |d| log n.
# The criterion suggests choosing the model Fd(θ; X) with
# minimum BICd = |d| log n − ℓ(ˆθd; X).
forw_bic <- step(mq0, scope=formula(mq), direction="forward", k=log(length(y)))
## Start:  AIC=280.44
## y ~ 1
## 
##        Df Sum of Sq     RSS     AIC
## + x12   1   1280.71   15.68 -213.70
## + x6    1    864.86  431.53  160.87
## + x18   1    639.73  656.66  208.31
## + x11   1    627.98  668.41  210.31
## + x16   1    324.59  971.80  252.60
## + x9    1    268.98 1027.41  258.89
## + x7    1    257.31 1039.08  260.17
## + x4    1    118.04 1178.34  274.38
## + x3    1     99.74 1196.65  276.12
## + x10   1     79.79 1216.60  277.99
## + x14   1     58.82 1237.57  279.92
## + x15   1     57.69 1238.69  280.02
## <none>              1296.39  280.44
## + x17   1     30.99 1265.40  282.44
## + x1    1     16.08 1280.31  283.76
## + x5    1     10.87 1285.52  284.22
## + x8    1      7.31 1289.08  284.53
## + x13   1      1.32 1295.07  285.05
## + x2    1      0.74 1295.65  285.11
## 
## Step:  AIC=-213.7
## y ~ x12
## 
##        Df Sum of Sq     RSS     AIC
## + x9    1   10.6896  4.9926 -338.31
## + x10   1    5.1070 10.5752 -253.50
## + x11   1    2.4221 13.2602 -227.93
## + x18   1    1.2584 14.4238 -218.43
## + x7    1    0.6956 14.9866 -214.10
## <none>              15.6822 -213.70
## + x6    1    0.6417 15.0405 -213.70
## + x16   1    0.5279 15.1543 -212.85
## + x8    1    0.3560 15.3262 -211.57
## + x13   1    0.2233 15.4590 -210.60
## + x3    1    0.1568 15.5255 -210.11
## + x4    1    0.1068 15.5754 -209.75
## + x5    1    0.1033 15.5789 -209.72
## + x2    1    0.0468 15.6354 -209.31
## + x15   1    0.0417 15.6405 -209.28
## + x14   1    0.0289 15.6533 -209.19
## + x17   1    0.0112 15.6711 -209.06
## + x1    1    0.0019 15.6803 -208.99
## 
## Step:  AIC=-338.31
## y ~ x12 + x9
## 
##        Df Sum of Sq    RSS     AIC
## + x18   1   0.67626 4.3163 -350.03
## + x11   1   0.63758 4.3550 -349.02
## + x7    1   0.61248 4.3801 -348.38
## + x16   1   0.53335 4.4593 -346.35
## + x3    1   0.46914 4.5235 -344.74
## + x4    1   0.45227 4.5403 -344.32
## + x13   1   0.40222 4.5904 -343.08
## <none>              4.9926 -338.31
## + x17   1   0.19959 4.7930 -338.20
## + x6    1   0.18284 4.8098 -337.80
## + x2    1   0.15157 4.8410 -337.07
## + x8    1   0.14968 4.8429 -337.03
## + x1    1   0.08969 4.9029 -335.63
## + x5    1   0.07865 4.9140 -335.38
## + x10   1   0.06663 4.9260 -335.10
## + x14   1   0.00542 4.9872 -333.71
## + x15   1   0.00127 4.9913 -333.61
## 
## Step:  AIC=-350.03
## y ~ x12 + x9 + x18
## 
##        Df Sum of Sq    RSS     AIC
## + x14   1   0.57258 3.7438 -361.39
## + x11   1   0.32484 3.9915 -354.15
## + x15   1   0.32043 3.9959 -354.02
## + x7    1   0.26037 4.0560 -352.34
## + x4    1   0.18348 4.1329 -350.21
## + x3    1   0.17923 4.1371 -350.10
## <none>              4.3163 -350.03
## + x2    1   0.17023 4.1461 -349.85
## + x17   1   0.10459 4.2118 -348.08
## + x8    1   0.07737 4.2390 -347.35
## + x10   1   0.04404 4.2723 -346.46
## + x6    1   0.04342 4.2729 -346.45
## + x1    1   0.03796 4.2784 -346.30
## + x16   1   0.02984 4.2865 -346.09
## + x5    1   0.02532 4.2910 -345.97
## + x13   1   0.00257 4.3138 -345.37
## 
## Step:  AIC=-361.39
## y ~ x12 + x9 + x18 + x14
## 
##        Df Sum of Sq    RSS     AIC
## + x11   1   0.46634 3.2774 -371.69
## + x10   1   0.37854 3.3652 -368.71
## + x6    1   0.21610 3.5277 -363.38
## + x2    1   0.15441 3.5894 -361.42
## <none>              3.7438 -361.39
## + x15   1   0.13998 3.6038 -360.97
## + x5    1   0.12387 3.6199 -360.46
## + x16   1   0.10409 3.6397 -359.85
## + x8    1   0.07438 3.6694 -358.93
## + x17   1   0.04280 3.7010 -357.96
## + x13   1   0.00461 3.7392 -356.80
## + x1    1   0.00440 3.7394 -356.79
## + x7    1   0.00267 3.7411 -356.74
## + x3    1   0.00076 3.7430 -356.68
## + x4    1   0.00039 3.7434 -356.67
## 
## Step:  AIC=-371.69
## y ~ x12 + x9 + x18 + x14 + x11
## 
##        Df Sum of Sq    RSS     AIC
## <none>              3.2774 -371.69
## + x6    1  0.108660 3.1688 -370.78
## + x7    1  0.053948 3.2235 -368.84
## + x5    1  0.035170 3.2423 -368.18
## + x2    1  0.034323 3.2431 -368.16
## + x13   1  0.031203 3.2462 -368.05
## + x15   1  0.029466 3.2480 -367.99
## + x8    1  0.023633 3.2538 -367.78
## + x1    1  0.016823 3.2606 -367.55
## + x17   1  0.012552 3.2649 -367.40
## + x16   1  0.008206 3.2692 -367.25
## + x10   1  0.003379 3.2740 -367.08
## + x4    1  0.002516 3.2749 -367.05
## + x3    1  0.002240 3.2752 -367.04
# CHOOSES THE MODEL:
# y ~ x12 + x9 + x18 + x14 + x11
# Summary information
summary(forw_bic)
## 
## Call:
## lm(formula = y ~ x12 + x9 + x18 + x14 + x11)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.64191 -0.06187  0.02281  0.06056  0.74776 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.410137   0.925946   6.923 3.41e-10 ***
## x12          0.234033   0.002577  90.830  < 2e-16 ***
## x9          -0.974535   0.076614 -12.720  < 2e-16 ***
## x18         -0.362493   0.066296  -5.468 3.01e-07 ***
## x14          1.082834   0.224265   4.828 4.61e-06 ***
## x11         -0.428942   0.109931  -3.902 0.000167 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.175 on 107 degrees of freedom
## Multiple R-squared:  0.9975, Adjusted R-squared:  0.9974 
## F-statistic:  8443 on 5 and 107 DF,  p-value: < 2.2e-16
# 7th Approach: LIKELIHOOD FUNCTIONS COMPARISON (BOTH WITH K=0)
# STARTING FROM THE COMPLETE MODEL
both_lik <- step(mq, scope=formula(mq), direction="both", k=0)
## Start:  AIC=-426.46
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + 
##     x12 + x13 + x14 + x15 + x16 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## <none>                2.594 -426.46
## - x9    1     0.001   2.595 -426.44
## - x8    1     0.001   2.595 -426.44
## - x16   1     0.002   2.596 -426.40
## - x13   1     0.003   2.597 -426.35
## - x17   1     0.004   2.598 -426.30
## - x4    1     0.009   2.604 -426.05
## - x11   1     0.021   2.615 -425.57
## - x6    1     0.023   2.617 -425.47
## - x3    1     0.028   2.622 -425.26
## - x1    1     0.031   2.625 -425.13
## - x15   1     0.032   2.627 -425.07
## - x2    1     0.049   2.643 -424.36
## - x5    1     0.055   2.650 -424.07
## - x7    1     0.069   2.663 -423.52
## - x14   1     0.240   2.834 -416.46
## - x18   1     0.312   2.906 -413.65
## - x10   1     0.326   2.920 -413.09
## - x12   1   146.022 148.616   30.96
# ALWAYS CHOOSES THE COMPLETE MODEL:
# y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + 
# x12 + x13 + x14 + x15 + x16 + x17 + x18
# Summary information
summary(both_lik)
## 
## Call:
## lm(formula = y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + 
##     x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.35240 -0.08275 -0.01367  0.06688  0.70644 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.4932971  4.0122361   0.123  0.90241    
## x1          -0.0001159  0.0001097  -1.056  0.29370    
## x2           0.0008409  0.0006320   1.331  0.18654    
## x3           0.0058477  0.0058386   1.002  0.31913    
## x4          -0.0027320  0.0046645  -0.586  0.55949    
## x5          -0.1743371  0.1230087  -1.417  0.15971    
## x6           0.4107678  0.4499448   0.913  0.36362    
## x7          -0.0277227  0.0175895  -1.576  0.11836    
## x8          -0.0001507  0.0010495  -0.144  0.88616    
## x9          -0.0349403  0.2545558  -0.137  0.89112    
## x10          1.1866765  0.3453261   3.436  0.00088 ***
## x11         -0.3031051  0.3517006  -0.862  0.39098    
## x12          0.2364541  0.0032508  72.736  < 2e-16 ***
## x13         -0.1351995  0.4372948  -0.309  0.75787    
## x14          1.4366685  0.4871607   2.949  0.00402 ** 
## x15          0.5159395  0.4768871   1.082  0.28207    
## x16          0.1026885  0.4341540   0.237  0.81354    
## x17         -0.0029176  0.0080131  -0.364  0.71659    
## x18         -0.5989269  0.1782506  -3.360  0.00113 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1661 on 94 degrees of freedom
## Multiple R-squared:  0.998,  Adjusted R-squared:  0.9976 
## F-statistic:  2604 on 18 and 94 DF,  p-value: < 2.2e-16
# 8th Approach: AIC (BOTH WITH K=2)
both_aic <- step(mq, scope=formula(mq), direction="both", k=2)
## Start:  AIC=-388.46
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + 
##     x12 + x13 + x14 + x15 + x16 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x9    1     0.001   2.595 -390.44
## - x8    1     0.001   2.595 -390.44
## - x16   1     0.002   2.596 -390.40
## - x13   1     0.003   2.597 -390.35
## - x17   1     0.004   2.598 -390.30
## - x4    1     0.009   2.604 -390.05
## - x11   1     0.021   2.615 -389.57
## - x6    1     0.023   2.617 -389.47
## - x3    1     0.028   2.622 -389.26
## - x1    1     0.031   2.625 -389.13
## - x15   1     0.032   2.627 -389.07
## <none>                2.594 -388.46
## - x2    1     0.049   2.643 -388.36
## - x5    1     0.055   2.650 -388.07
## - x7    1     0.069   2.663 -387.52
## - x14   1     0.240   2.834 -380.46
## - x18   1     0.312   2.906 -377.65
## - x10   1     0.326   2.920 -377.09
## - x12   1   146.022 148.616   66.96
## 
## Step:  AIC=-390.44
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x10 + x11 + x12 + 
##     x13 + x14 + x15 + x16 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x8    1     0.001   2.596 -392.41
## - x16   1     0.002   2.597 -392.37
## - x13   1     0.003   2.598 -392.32
## - x17   1     0.004   2.599 -392.27
## - x4    1     0.009   2.604 -392.04
## - x11   1     0.020   2.615 -391.57
## - x6    1     0.025   2.620 -391.35
## - x3    1     0.027   2.622 -391.25
## - x1    1     0.032   2.627 -391.07
## - x15   1     0.034   2.629 -390.95
## <none>                2.595 -390.44
## - x2    1     0.049   2.644 -390.34
## - x5    1     0.058   2.653 -389.95
## - x7    1     0.068   2.663 -389.50
## + x9    1     0.001   2.594 -388.46
## - x14   1     0.252   2.847 -381.98
## - x18   1     0.341   2.936 -378.49
## - x10   1     1.551   4.145 -339.51
## - x12   1   150.967 153.562   68.66
## 
## Step:  AIC=-392.41
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x10 + x11 + x12 + x13 + 
##     x14 + x15 + x16 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x16   1     0.002   2.597 -394.34
## - x13   1     0.003   2.598 -394.30
## - x17   1     0.004   2.600 -394.24
## - x4    1     0.011   2.607 -393.94
## - x11   1     0.022   2.618 -393.46
## - x3    1     0.028   2.623 -393.22
## - x6    1     0.028   2.624 -393.20
## - x1    1     0.032   2.628 -393.02
## - x15   1     0.036   2.631 -392.86
## <none>                2.596 -392.41
## - x2    1     0.049   2.645 -392.30
## - x5    1     0.059   2.655 -391.85
## - x7    1     0.070   2.666 -391.41
## + x8    1     0.001   2.595 -390.44
## + x9    1     0.001   2.595 -390.44
## - x14   1     0.270   2.866 -383.23
## - x18   1     0.378   2.974 -379.03
## - x10   1     1.588   4.184 -340.46
## - x12   1   167.589 170.184   78.27
## 
## Step:  AIC=-394.34
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x10 + x11 + x12 + x13 + 
##     x14 + x15 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x4    1     0.010   2.608 -395.90
## - x17   1     0.012   2.609 -395.84
## - x11   1     0.021   2.618 -395.44
## - x3    1     0.027   2.624 -395.18
## - x1    1     0.032   2.629 -394.98
## - x15   1     0.034   2.631 -394.86
## - x13   1     0.046   2.643 -394.38
## <none>                2.597 -394.34
## - x2    1     0.050   2.647 -394.21
## - x5    1     0.058   2.655 -393.85
## - x7    1     0.069   2.666 -393.39
## + x16   1     0.002   2.596 -392.41
## + x9    1     0.001   2.596 -392.38
## + x8    1     0.001   2.597 -392.37
## - x14   1     0.273   2.870 -385.05
## - x18   1     0.377   2.974 -381.02
## - x10   1     1.611   4.208 -341.81
## - x6    1     3.133   5.730 -306.93
## - x12   1   167.601 170.198   76.28
## 
## Step:  AIC=-395.9
## y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x11 + x12 + x13 + x14 + 
##     x15 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x17   1     0.009   2.616 -397.52
## - x11   1     0.022   2.629 -396.96
## - x1    1     0.032   2.640 -396.51
## - x15   1     0.034   2.641 -396.43
## - x13   1     0.035   2.643 -396.38
## - x3    1     0.036   2.644 -396.33
## <none>                2.608 -395.90
## - x2    1     0.051   2.658 -395.71
## - x5    1     0.055   2.663 -395.54
## - x7    1     0.069   2.677 -394.93
## + x4    1     0.010   2.597 -394.34
## + x8    1     0.002   2.606 -393.98
## + x16   1     0.001   2.607 -393.94
## + x9    1     0.001   2.607 -393.92
## - x14   1     0.272   2.880 -386.67
## - x18   1     0.385   2.993 -382.33
## - x10   1     1.614   4.221 -343.45
## - x6    1     3.187   5.795 -307.66
## - x12   1   167.630 170.238   74.31
## 
## Step:  AIC=-397.52
## y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x11 + x12 + x13 + x14 + 
##     x15 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x11   1     0.023   2.639 -398.55
## - x13   1     0.031   2.647 -398.20
## - x3    1     0.032   2.648 -398.14
## - x1    1     0.035   2.651 -398.02
## - x15   1     0.038   2.654 -397.90
## - x2    1     0.045   2.661 -397.60
## <none>                2.616 -397.52
## - x5    1     0.059   2.676 -396.98
## - x7    1     0.064   2.680 -396.80
## + x17   1     0.009   2.608 -395.90
## + x4    1     0.007   2.609 -395.84
## + x16   1     0.007   2.609 -395.81
## + x9    1     0.002   2.614 -395.59
## + x8    1     0.001   2.615 -395.57
## - x14   1     0.266   2.882 -388.59
## - x18   1     0.387   3.003 -383.93
## - x10   1     1.606   4.222 -345.44
## - x6    1     3.193   5.809 -309.38
## - x12   1   169.034 171.650   73.24
## 
## Step:  AIC=-398.55
## y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + x15 + 
##     x18
## 
##        Df Sum of Sq     RSS     AIC
## - x15   1     0.019   2.658 -399.74
## - x1    1     0.039   2.677 -398.91
## - x5    1     0.039   2.678 -398.89
## - x13   1     0.040   2.679 -398.84
## - x2    1     0.042   2.680 -398.78
## - x3    1     0.047   2.686 -398.56
## <none>                2.639 -398.55
## - x7    1     0.071   2.710 -397.54
## + x11   1     0.023   2.616 -397.52
## + x17   1     0.010   2.629 -396.96
## + x4    1     0.008   2.631 -396.89
## + x16   1     0.005   2.634 -396.77
## + x8    1     0.003   2.635 -396.69
## + x9    1     0.000   2.639 -396.56
## - x14   1     0.270   2.908 -389.56
## - x18   1     2.891   5.529 -316.96
## - x6    1     3.181   5.820 -311.18
## - x10   1     7.863  10.502 -244.47
## - x12   1   174.820 177.459   75.00
## 
## Step:  AIC=-399.74
## y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x2    1     0.039   2.697 -400.10
## - x1    1     0.044   2.701 -399.90
## - x3    1     0.044   2.702 -399.87
## - x5    1     0.045   2.703 -399.85
## - x13   1     0.045   2.703 -399.84
## <none>                2.658 -399.74
## - x7    1     0.071   2.729 -398.75
## + x15   1     0.019   2.639 -398.55
## + x17   1     0.012   2.646 -398.26
## + x4    1     0.007   2.651 -398.03
## + x16   1     0.004   2.653 -397.92
## + x11   1     0.004   2.654 -397.90
## + x8    1     0.004   2.654 -397.89
## + x9    1     0.003   2.655 -397.86
## - x18   1     2.937   5.595 -317.63
## - x6    1     3.218   5.876 -312.08
## - x14   1     4.296   6.954 -293.06
## - x10   1     8.152  10.809 -243.21
## - x12   1   175.662 178.320   73.55
## 
## Step:  AIC=-400.1
## y ~ x1 + x3 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x3    1     0.037   2.733 -400.57
## - x1    1     0.039   2.736 -400.46
## - x13   1     0.043   2.740 -400.31
## <none>                2.697 -400.10
## - x5    1     0.053   2.750 -399.90
## + x2    1     0.039   2.658 -399.74
## - x7    1     0.058   2.755 -399.67
## + x15   1     0.016   2.680 -398.78
## + x4    1     0.009   2.688 -398.48
## + x17   1     0.005   2.692 -398.30
## + x11   1     0.003   2.693 -398.24
## + x16   1     0.002   2.694 -398.20
## + x9    1     0.001   2.696 -398.14
## + x8    1     0.000   2.697 -398.10
## - x18   1     2.940   5.636 -318.79
## - x6    1     3.201   5.898 -313.67
## - x14   1     4.350   7.047 -293.55
## - x10   1     8.113  10.810 -245.21
## - x12   1   183.729 186.426   76.57
## 
## Step:  AIC=-400.57
## y ~ x1 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x13   1     0.010   2.743 -402.16
## - x7    1     0.030   2.764 -401.33
## - x1    1     0.041   2.774 -400.90
## <none>                2.733 -400.57
## - x5    1     0.057   2.791 -400.23
## + x3    1     0.037   2.697 -400.10
## + x2    1     0.031   2.702 -399.87
## + x4    1     0.021   2.712 -399.44
## + x15   1     0.014   2.719 -399.16
## + x11   1     0.009   2.724 -398.96
## + x8    1     0.004   2.729 -398.74
## + x17   1     0.002   2.731 -398.66
## + x16   1     0.001   2.732 -398.62
## + x9    1     0.000   2.733 -398.59
## - x18   1     2.983   5.717 -319.19
## - x6    1     3.346   6.079 -312.24
## - x14   1     4.601   7.335 -291.03
## - x10   1     8.077  10.810 -247.20
## - x12   1   186.520 189.254   76.27
## 
## Step:  AIC=-402.16
## y ~ x1 + x5 + x6 + x7 + x10 + x12 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x1    1     0.039   2.782 -402.56
## - x7    1     0.040   2.783 -402.52
## <none>                2.743 -402.16
## - x5    1     0.060   2.804 -401.70
## + x2    1     0.034   2.710 -401.56
## + x15   1     0.018   2.725 -400.91
## + x13   1     0.010   2.733 -400.57
## + x16   1     0.010   2.734 -400.56
## + x11   1     0.008   2.735 -400.49
## + x4    1     0.004   2.739 -400.32
## + x3    1     0.003   2.740 -400.31
## + x17   1     0.001   2.742 -400.22
## + x8    1     0.001   2.742 -400.21
## + x9    1     0.001   2.742 -400.21
## - x18   1     3.819   6.562 -305.61
## - x6    1     3.954   6.697 -303.30
## - x14   1     4.752   7.496 -290.58
## - x10   1    10.165  12.909 -229.15
## - x12   1   195.196 197.939   79.34
## 
## Step:  AIC=-402.56
## y ~ x5 + x6 + x7 + x10 + x12 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x7    1     0.041   2.824 -402.90
## <none>                2.782 -402.56
## - x5    1     0.055   2.838 -402.34
## + x1    1     0.039   2.743 -402.16
## + x2    1     0.030   2.753 -401.76
## + x15   1     0.022   2.760 -401.47
## + x13   1     0.008   2.774 -400.90
## + x11   1     0.008   2.774 -400.90
## + x16   1     0.008   2.774 -400.89
## + x4    1     0.005   2.778 -400.75
## + x3    1     0.004   2.778 -400.73
## + x17   1     0.003   2.779 -400.69
## + x9    1     0.003   2.780 -400.67
## + x8    1     0.001   2.782 -400.59
## - x18   1     3.931   6.714 -305.02
## - x6    1     4.026   6.808 -303.45
## - x14   1     4.847   7.629 -290.58
## - x10   1    10.240  13.023 -230.16
## - x12   1   197.697 200.479   78.79
## 
## Step:  AIC=-402.9
## y ~ x5 + x6 + x10 + x12 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x5    1     0.042   2.865 -403.24
## <none>                2.824 -402.90
## + x7    1     0.041   2.782 -402.56
## + x1    1     0.040   2.783 -402.52
## + x15   1     0.026   2.797 -401.96
## + x2    1     0.023   2.800 -401.84
## + x13   1     0.018   2.806 -401.62
## + x16   1     0.018   2.806 -401.61
## + x11   1     0.007   2.817 -401.18
## + x9    1     0.003   2.820 -401.04
## + x8    1     0.002   2.821 -401.00
## + x17   1     0.002   2.822 -400.96
## + x4    1     0.001   2.822 -400.95
## + x3    1     0.001   2.822 -400.95
## - x6    1     4.651   7.475 -294.89
## - x18   1     6.435   9.258 -270.71
## - x14   1     7.037   9.861 -263.59
## - x10   1    10.446  13.270 -230.03
## - x12   1   206.741 209.565   81.79
## 
## Step:  AIC=-403.24
## y ~ x6 + x10 + x12 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## <none>                2.865 -403.24
## + x5    1     0.042   2.824 -402.90
## + x1    1     0.035   2.830 -402.64
## + x2    1     0.030   2.835 -402.44
## + x7    1     0.028   2.838 -402.34
## + x15   1     0.021   2.845 -402.05
## + x13   1     0.019   2.846 -402.01
## + x16   1     0.019   2.846 -402.01
## + x11   1     0.011   2.854 -401.69
## + x9    1     0.001   2.864 -401.30
## + x17   1     0.001   2.864 -401.28
## + x8    1     0.001   2.865 -401.27
## + x3    1     0.000   2.865 -401.26
## + x4    1     0.000   2.865 -401.24
## - x6    1     4.738   7.603 -294.97
## - x18   1     6.403   9.268 -272.59
## - x14   1     7.114   9.979 -264.24
## - x10   1    10.534  13.400 -230.93
## - x12   1   213.635 216.500   83.47
# CHOOSES THE MODEL:
# y ~ x6 + x10 + x12 + x14 + x18
# Summary information
summary(both_aic)
## 
## Call:
## lm(formula = y ~ x6 + x10 + x12 + x14 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.44914 -0.07025  0.01326  0.06725  0.75342 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.404720   0.200281  -12.01   <2e-16 ***
## x6           0.536888   0.040365   13.30   <2e-16 ***
## x10          1.346157   0.067872   19.83   <2e-16 ***
## x12          0.233623   0.002616   89.32   <2e-16 ***
## x14          1.541982   0.094606   16.30   <2e-16 ***
## x18         -0.506816   0.032777  -15.46   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1636 on 107 degrees of freedom
## Multiple R-squared:  0.9978, Adjusted R-squared:  0.9977 
## F-statistic:  9661 on 5 and 107 DF,  p-value: < 2.2e-16
# 9th Approach: BIC (BOTH WITH K=ln(length(y)))
both_bic <- step(mq, scope=formula(mq), direction="both", k=log(length(y)))
## Start:  AIC=-336.64
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + 
##     x12 + x13 + x14 + x15 + x16 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x9    1     0.001   2.595 -341.35
## - x8    1     0.001   2.595 -341.35
## - x16   1     0.002   2.596 -341.30
## - x13   1     0.003   2.597 -341.26
## - x17   1     0.004   2.598 -341.21
## - x4    1     0.009   2.604 -340.96
## - x11   1     0.021   2.615 -340.48
## - x6    1     0.023   2.617 -340.37
## - x3    1     0.028   2.622 -340.17
## - x1    1     0.031   2.625 -340.04
## - x15   1     0.032   2.627 -339.97
## - x2    1     0.049   2.643 -339.26
## - x5    1     0.055   2.650 -338.98
## - x7    1     0.069   2.663 -338.42
## <none>                2.594 -336.64
## - x14   1     0.240   2.834 -331.37
## - x18   1     0.312   2.906 -328.55
## - x10   1     0.326   2.920 -328.00
## - x12   1   146.022 148.616  116.05
## 
## Step:  AIC=-341.35
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x10 + x11 + x12 + 
##     x13 + x14 + x15 + x16 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x8    1     0.001   2.596 -346.04
## - x16   1     0.002   2.597 -346.00
## - x13   1     0.003   2.598 -345.95
## - x17   1     0.004   2.599 -345.90
## - x4    1     0.009   2.604 -345.68
## - x11   1     0.020   2.615 -345.21
## - x6    1     0.025   2.620 -344.99
## - x3    1     0.027   2.622 -344.89
## - x1    1     0.032   2.627 -344.71
## - x15   1     0.034   2.629 -344.59
## - x2    1     0.049   2.644 -343.98
## - x5    1     0.058   2.653 -343.58
## - x7    1     0.068   2.663 -343.14
## <none>                2.595 -341.35
## + x9    1     0.001   2.594 -336.64
## - x14   1     0.252   2.847 -335.61
## - x18   1     0.341   2.936 -332.12
## - x10   1     1.551   4.145 -293.14
## - x12   1   150.967 153.562  115.02
## 
## Step:  AIC=-346.04
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x10 + x11 + x12 + x13 + 
##     x14 + x15 + x16 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x16   1     0.002   2.597 -350.70
## - x13   1     0.003   2.598 -350.66
## - x17   1     0.004   2.600 -350.60
## - x4    1     0.011   2.607 -350.30
## - x11   1     0.022   2.618 -349.82
## - x3    1     0.028   2.623 -349.58
## - x6    1     0.028   2.624 -349.56
## - x1    1     0.032   2.628 -349.38
## - x15   1     0.036   2.631 -349.23
## - x2    1     0.049   2.645 -348.66
## - x5    1     0.059   2.655 -348.22
## - x7    1     0.070   2.666 -347.77
## <none>                2.596 -346.04
## + x8    1     0.001   2.595 -341.35
## + x9    1     0.001   2.595 -341.35
## - x14   1     0.270   2.866 -339.59
## - x18   1     0.378   2.974 -335.39
## - x10   1     1.588   4.184 -296.82
## - x12   1   167.589 170.184  121.91
## 
## Step:  AIC=-350.7
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x10 + x11 + x12 + x13 + 
##     x14 + x15 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x4    1     0.010   2.608 -354.98
## - x17   1     0.012   2.609 -354.93
## - x11   1     0.021   2.618 -354.53
## - x3    1     0.027   2.624 -354.27
## - x1    1     0.032   2.629 -354.07
## - x15   1     0.034   2.631 -353.95
## - x13   1     0.046   2.643 -353.47
## - x2    1     0.050   2.647 -353.29
## - x5    1     0.058   2.655 -352.94
## - x7    1     0.069   2.666 -352.48
## <none>                2.597 -350.70
## + x16   1     0.002   2.596 -346.04
## + x9    1     0.001   2.596 -346.01
## + x8    1     0.001   2.597 -346.00
## - x14   1     0.273   2.870 -344.14
## - x18   1     0.377   2.974 -340.11
## - x10   1     1.611   4.208 -300.90
## - x6    1     3.133   5.730 -266.02
## - x12   1   167.601 170.198  117.19
## 
## Step:  AIC=-354.98
## y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x11 + x12 + x13 + x14 + 
##     x15 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x17   1     0.009   2.616 -359.34
## - x11   1     0.022   2.629 -358.78
## - x1    1     0.032   2.640 -358.32
## - x15   1     0.034   2.641 -358.25
## - x13   1     0.035   2.643 -358.19
## - x3    1     0.036   2.644 -358.15
## - x2    1     0.051   2.658 -357.53
## - x5    1     0.055   2.663 -357.35
## - x7    1     0.069   2.677 -356.75
## <none>                2.608 -354.98
## + x4    1     0.010   2.597 -350.70
## + x8    1     0.002   2.606 -350.34
## + x16   1     0.001   2.607 -350.30
## + x9    1     0.001   2.607 -350.28
## - x14   1     0.272   2.880 -348.48
## - x18   1     0.385   2.993 -344.14
## - x10   1     1.614   4.221 -305.27
## - x6    1     3.187   5.795 -269.47
## - x12   1   167.630 170.238  112.49
## 
## Step:  AIC=-359.34
## y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x11 + x12 + x13 + x14 + 
##     x15 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x11   1     0.023   2.639 -363.09
## - x13   1     0.031   2.647 -362.74
## - x3    1     0.032   2.648 -362.68
## - x1    1     0.035   2.651 -362.56
## - x15   1     0.038   2.654 -362.45
## - x2    1     0.045   2.661 -362.15
## - x5    1     0.059   2.676 -361.52
## - x7    1     0.064   2.680 -361.34
## <none>                2.616 -359.34
## + x17   1     0.009   2.608 -354.98
## + x4    1     0.007   2.609 -354.93
## + x16   1     0.007   2.609 -354.90
## + x9    1     0.002   2.614 -354.68
## + x8    1     0.001   2.615 -354.66
## - x14   1     0.266   2.882 -353.13
## - x18   1     0.387   3.003 -348.47
## - x10   1     1.606   4.222 -309.99
## - x6    1     3.193   5.809 -273.92
## - x12   1   169.034 171.650  108.70
## 
## Step:  AIC=-363.09
## y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + x15 + 
##     x18
## 
##        Df Sum of Sq     RSS     AIC
## - x15   1     0.019   2.658 -367.01
## - x1    1     0.039   2.677 -366.18
## - x5    1     0.039   2.678 -366.16
## - x13   1     0.040   2.679 -366.11
## - x2    1     0.042   2.680 -366.05
## - x3    1     0.047   2.686 -365.83
## - x7    1     0.071   2.710 -364.81
## <none>                2.639 -363.09
## + x11   1     0.023   2.616 -359.34
## + x17   1     0.010   2.629 -358.78
## + x4    1     0.008   2.631 -358.70
## + x16   1     0.005   2.634 -358.59
## + x8    1     0.003   2.635 -358.51
## + x9    1     0.000   2.639 -358.38
## - x14   1     0.270   2.908 -356.83
## - x18   1     2.891   5.529 -284.23
## - x6    1     3.181   5.820 -278.45
## - x10   1     7.863  10.502 -211.74
## - x12   1   174.820 177.459  107.73
## 
## Step:  AIC=-367.01
## y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x2    1     0.039   2.697 -370.10
## - x1    1     0.044   2.701 -369.90
## - x3    1     0.044   2.702 -369.87
## - x5    1     0.045   2.703 -369.85
## - x13   1     0.045   2.703 -369.84
## - x7    1     0.071   2.729 -368.75
## <none>                2.658 -367.01
## + x15   1     0.019   2.639 -363.09
## + x17   1     0.012   2.646 -362.80
## + x4    1     0.007   2.651 -362.58
## + x16   1     0.004   2.653 -362.47
## + x11   1     0.004   2.654 -362.45
## + x8    1     0.004   2.654 -362.43
## + x9    1     0.003   2.655 -362.41
## - x18   1     2.937   5.595 -287.63
## - x6    1     3.218   5.876 -282.08
## - x14   1     4.296   6.954 -263.06
## - x10   1     8.152  10.809 -213.21
## - x12   1   175.662 178.320  103.55
## 
## Step:  AIC=-370.1
## y ~ x1 + x3 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x3    1     0.037   2.733 -373.30
## - x1    1     0.039   2.736 -373.18
## - x13   1     0.043   2.740 -373.03
## - x5    1     0.053   2.750 -372.62
## - x7    1     0.058   2.755 -372.40
## <none>                2.697 -370.10
## + x2    1     0.039   2.658 -367.01
## + x15   1     0.016   2.680 -366.05
## + x4    1     0.009   2.688 -365.75
## + x17   1     0.005   2.692 -365.57
## + x11   1     0.003   2.693 -365.51
## + x16   1     0.002   2.694 -365.47
## + x9    1     0.001   2.696 -365.42
## + x8    1     0.000   2.697 -365.37
## - x18   1     2.940   5.636 -291.52
## - x6    1     3.201   5.898 -286.40
## - x14   1     4.350   7.047 -266.28
## - x10   1     8.113  10.810 -217.93
## - x12   1   183.729 186.426  103.85
## 
## Step:  AIC=-373.3
## y ~ x1 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x13   1     0.010   2.743 -377.62
## - x7    1     0.030   2.764 -376.78
## - x1    1     0.041   2.774 -376.35
## - x5    1     0.057   2.791 -375.68
## <none>                2.733 -373.30
## + x3    1     0.037   2.697 -370.10
## + x2    1     0.031   2.702 -369.87
## + x4    1     0.021   2.712 -369.44
## + x15   1     0.014   2.719 -369.16
## + x11   1     0.009   2.724 -368.96
## + x8    1     0.004   2.729 -368.74
## + x17   1     0.002   2.731 -368.66
## + x16   1     0.001   2.732 -368.62
## + x9    1     0.000   2.733 -368.58
## - x18   1     2.983   5.717 -294.64
## - x6    1     3.346   6.079 -287.69
## - x14   1     4.601   7.335 -266.48
## - x10   1     8.077  10.810 -222.65
## - x12   1   186.520 189.254  100.82
## 
## Step:  AIC=-377.62
## y ~ x1 + x5 + x6 + x7 + x10 + x12 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x1    1     0.039   2.782 -380.74
## - x7    1     0.040   2.783 -380.71
## - x5    1     0.060   2.804 -379.88
## <none>                2.743 -377.62
## + x2    1     0.034   2.710 -374.28
## + x15   1     0.018   2.725 -373.63
## + x13   1     0.010   2.733 -373.30
## + x16   1     0.010   2.734 -373.28
## + x11   1     0.008   2.735 -373.21
## + x4    1     0.004   2.739 -373.05
## + x3    1     0.003   2.740 -373.03
## + x17   1     0.001   2.742 -372.95
## + x8    1     0.001   2.742 -372.94
## + x9    1     0.001   2.742 -372.93
## - x18   1     3.819   6.562 -283.79
## - x6    1     3.954   6.697 -281.48
## - x14   1     4.752   7.496 -268.76
## - x10   1    10.165  12.909 -207.33
## - x12   1   195.196 197.939  101.16
## 
## Step:  AIC=-380.74
## y ~ x5 + x6 + x7 + x10 + x12 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x7    1     0.041   2.824 -383.81
## - x5    1     0.055   2.838 -383.25
## <none>                2.782 -380.74
## + x1    1     0.039   2.743 -377.62
## + x2    1     0.030   2.753 -377.22
## + x15   1     0.022   2.760 -376.92
## + x13   1     0.008   2.774 -376.35
## + x11   1     0.008   2.774 -376.35
## + x16   1     0.008   2.774 -376.34
## + x4    1     0.005   2.778 -376.20
## + x3    1     0.004   2.778 -376.19
## + x17   1     0.003   2.779 -376.14
## + x9    1     0.003   2.780 -376.13
## + x8    1     0.001   2.782 -376.04
## - x18   1     3.931   6.714 -285.93
## - x6    1     4.026   6.808 -284.35
## - x14   1     4.847   7.629 -271.49
## - x10   1    10.240  13.023 -211.06
## - x12   1   197.697 200.479   97.88
## 
## Step:  AIC=-383.81
## y ~ x5 + x6 + x10 + x12 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x5    1     0.042   2.865 -386.88
## <none>                2.824 -383.81
## + x7    1     0.041   2.782 -380.74
## + x1    1     0.040   2.783 -380.71
## + x15   1     0.026   2.797 -380.14
## + x2    1     0.023   2.800 -380.02
## + x13   1     0.018   2.806 -379.80
## + x16   1     0.018   2.806 -379.79
## + x11   1     0.007   2.817 -379.36
## + x9    1     0.003   2.820 -379.22
## + x8    1     0.002   2.821 -379.18
## + x17   1     0.002   2.822 -379.14
## + x4    1     0.001   2.822 -379.13
## + x3    1     0.001   2.822 -379.13
## - x6    1     4.651   7.475 -278.52
## - x18   1     6.435   9.258 -254.35
## - x14   1     7.037   9.861 -247.22
## - x10   1    10.446  13.270 -213.67
## - x12   1   206.741 209.565   98.16
## 
## Step:  AIC=-386.88
## y ~ x6 + x10 + x12 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## <none>                2.865 -386.88
## + x5    1     0.042   2.824 -383.81
## + x1    1     0.035   2.830 -383.55
## + x2    1     0.030   2.835 -383.35
## + x7    1     0.028   2.838 -383.25
## + x15   1     0.021   2.845 -382.96
## + x13   1     0.019   2.846 -382.92
## + x16   1     0.019   2.846 -382.92
## + x11   1     0.011   2.854 -382.60
## + x9    1     0.001   2.864 -382.21
## + x17   1     0.001   2.864 -382.19
## + x8    1     0.001   2.865 -382.17
## + x3    1     0.000   2.865 -382.17
## + x4    1     0.000   2.865 -382.15
## - x6    1     4.738   7.603 -281.33
## - x18   1     6.403   9.268 -258.96
## - x14   1     7.114   9.979 -250.60
## - x10   1    10.534  13.400 -217.30
## - x12   1   213.635 216.500   97.11
# CHOOSES THE MODEL:
# y ~ x6 + x10 + x12 + x14 + x18
# Summary information
summary(both_bic)
## 
## Call:
## lm(formula = y ~ x6 + x10 + x12 + x14 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.44914 -0.07025  0.01326  0.06725  0.75342 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.404720   0.200281  -12.01   <2e-16 ***
## x6           0.536888   0.040365   13.30   <2e-16 ***
## x10          1.346157   0.067872   19.83   <2e-16 ***
## x12          0.233623   0.002616   89.32   <2e-16 ***
## x14          1.541982   0.094606   16.30   <2e-16 ***
## x18         -0.506816   0.032777  -15.46   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1636 on 107 degrees of freedom
## Multiple R-squared:  0.9978, Adjusted R-squared:  0.9977 
## F-statistic:  9661 on 5 and 107 DF,  p-value: < 2.2e-16
# 10th Approach: LIKELIHOOD FUNCTIONS COMPARISON (BACKWARD WITH K=0)
# STARTING FROM THE COMPLETE MODEL
back_lik <- step(mq, scope=formula(mq), direction="backward", k=0)
## Start:  AIC=-426.46
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + 
##     x12 + x13 + x14 + x15 + x16 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## <none>                2.594 -426.46
## - x9    1     0.001   2.595 -426.44
## - x8    1     0.001   2.595 -426.44
## - x16   1     0.002   2.596 -426.40
## - x13   1     0.003   2.597 -426.35
## - x17   1     0.004   2.598 -426.30
## - x4    1     0.009   2.604 -426.05
## - x11   1     0.021   2.615 -425.57
## - x6    1     0.023   2.617 -425.47
## - x3    1     0.028   2.622 -425.26
## - x1    1     0.031   2.625 -425.13
## - x15   1     0.032   2.627 -425.07
## - x2    1     0.049   2.643 -424.36
## - x5    1     0.055   2.650 -424.07
## - x7    1     0.069   2.663 -423.52
## - x14   1     0.240   2.834 -416.46
## - x18   1     0.312   2.906 -413.65
## - x10   1     0.326   2.920 -413.09
## - x12   1   146.022 148.616   30.96
# ALWAYS CHOOSES THE COMPLETE MODEL:
# y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + 
# x12 + x13 + x14 + x15 + x16 + x17 + x18
# Summary information
summary(back_lik)
## 
## Call:
## lm(formula = y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + 
##     x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.35240 -0.08275 -0.01367  0.06688  0.70644 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.4932971  4.0122361   0.123  0.90241    
## x1          -0.0001159  0.0001097  -1.056  0.29370    
## x2           0.0008409  0.0006320   1.331  0.18654    
## x3           0.0058477  0.0058386   1.002  0.31913    
## x4          -0.0027320  0.0046645  -0.586  0.55949    
## x5          -0.1743371  0.1230087  -1.417  0.15971    
## x6           0.4107678  0.4499448   0.913  0.36362    
## x7          -0.0277227  0.0175895  -1.576  0.11836    
## x8          -0.0001507  0.0010495  -0.144  0.88616    
## x9          -0.0349403  0.2545558  -0.137  0.89112    
## x10          1.1866765  0.3453261   3.436  0.00088 ***
## x11         -0.3031051  0.3517006  -0.862  0.39098    
## x12          0.2364541  0.0032508  72.736  < 2e-16 ***
## x13         -0.1351995  0.4372948  -0.309  0.75787    
## x14          1.4366685  0.4871607   2.949  0.00402 ** 
## x15          0.5159395  0.4768871   1.082  0.28207    
## x16          0.1026885  0.4341540   0.237  0.81354    
## x17         -0.0029176  0.0080131  -0.364  0.71659    
## x18         -0.5989269  0.1782506  -3.360  0.00113 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1661 on 94 degrees of freedom
## Multiple R-squared:  0.998,  Adjusted R-squared:  0.9976 
## F-statistic:  2604 on 18 and 94 DF,  p-value: < 2.2e-16
# 11th Approach: AIC (BOTH WITH K=2)
back_aic <- step(mq, scope=formula(mq), direction="backward", k=2)
## Start:  AIC=-388.46
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + 
##     x12 + x13 + x14 + x15 + x16 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x9    1     0.001   2.595 -390.44
## - x8    1     0.001   2.595 -390.44
## - x16   1     0.002   2.596 -390.40
## - x13   1     0.003   2.597 -390.35
## - x17   1     0.004   2.598 -390.30
## - x4    1     0.009   2.604 -390.05
## - x11   1     0.021   2.615 -389.57
## - x6    1     0.023   2.617 -389.47
## - x3    1     0.028   2.622 -389.26
## - x1    1     0.031   2.625 -389.13
## - x15   1     0.032   2.627 -389.07
## <none>                2.594 -388.46
## - x2    1     0.049   2.643 -388.36
## - x5    1     0.055   2.650 -388.07
## - x7    1     0.069   2.663 -387.52
## - x14   1     0.240   2.834 -380.46
## - x18   1     0.312   2.906 -377.65
## - x10   1     0.326   2.920 -377.09
## - x12   1   146.022 148.616   66.96
## 
## Step:  AIC=-390.44
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x10 + x11 + x12 + 
##     x13 + x14 + x15 + x16 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x8    1     0.001   2.596 -392.41
## - x16   1     0.002   2.597 -392.37
## - x13   1     0.003   2.598 -392.32
## - x17   1     0.004   2.599 -392.27
## - x4    1     0.009   2.604 -392.04
## - x11   1     0.020   2.615 -391.57
## - x6    1     0.025   2.620 -391.35
## - x3    1     0.027   2.622 -391.25
## - x1    1     0.032   2.627 -391.07
## - x15   1     0.034   2.629 -390.95
## <none>                2.595 -390.44
## - x2    1     0.049   2.644 -390.34
## - x5    1     0.058   2.653 -389.95
## - x7    1     0.068   2.663 -389.50
## - x14   1     0.252   2.847 -381.98
## - x18   1     0.341   2.936 -378.49
## - x10   1     1.551   4.145 -339.51
## - x12   1   150.967 153.562   68.66
## 
## Step:  AIC=-392.41
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x10 + x11 + x12 + x13 + 
##     x14 + x15 + x16 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x16   1     0.002   2.597 -394.34
## - x13   1     0.003   2.598 -394.30
## - x17   1     0.004   2.600 -394.24
## - x4    1     0.011   2.607 -393.94
## - x11   1     0.022   2.618 -393.46
## - x3    1     0.028   2.623 -393.22
## - x6    1     0.028   2.624 -393.20
## - x1    1     0.032   2.628 -393.02
## - x15   1     0.036   2.631 -392.86
## <none>                2.596 -392.41
## - x2    1     0.049   2.645 -392.30
## - x5    1     0.059   2.655 -391.85
## - x7    1     0.070   2.666 -391.41
## - x14   1     0.270   2.866 -383.23
## - x18   1     0.378   2.974 -379.03
## - x10   1     1.588   4.184 -340.46
## - x12   1   167.589 170.184   78.27
## 
## Step:  AIC=-394.34
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x10 + x11 + x12 + x13 + 
##     x14 + x15 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x4    1     0.010   2.608 -395.90
## - x17   1     0.012   2.609 -395.84
## - x11   1     0.021   2.618 -395.44
## - x3    1     0.027   2.624 -395.18
## - x1    1     0.032   2.629 -394.98
## - x15   1     0.034   2.631 -394.86
## - x13   1     0.046   2.643 -394.38
## <none>                2.597 -394.34
## - x2    1     0.050   2.647 -394.21
## - x5    1     0.058   2.655 -393.85
## - x7    1     0.069   2.666 -393.39
## - x14   1     0.273   2.870 -385.05
## - x18   1     0.377   2.974 -381.02
## - x10   1     1.611   4.208 -341.81
## - x6    1     3.133   5.730 -306.93
## - x12   1   167.601 170.198   76.28
## 
## Step:  AIC=-395.9
## y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x11 + x12 + x13 + x14 + 
##     x15 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x17   1     0.009   2.616 -397.52
## - x11   1     0.022   2.629 -396.96
## - x1    1     0.032   2.640 -396.51
## - x15   1     0.034   2.641 -396.43
## - x13   1     0.035   2.643 -396.38
## - x3    1     0.036   2.644 -396.33
## <none>                2.608 -395.90
## - x2    1     0.051   2.658 -395.71
## - x5    1     0.055   2.663 -395.54
## - x7    1     0.069   2.677 -394.93
## - x14   1     0.272   2.880 -386.67
## - x18   1     0.385   2.993 -382.33
## - x10   1     1.614   4.221 -343.45
## - x6    1     3.187   5.795 -307.66
## - x12   1   167.630 170.238   74.31
## 
## Step:  AIC=-397.52
## y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x11 + x12 + x13 + x14 + 
##     x15 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x11   1     0.023   2.639 -398.55
## - x13   1     0.031   2.647 -398.20
## - x3    1     0.032   2.648 -398.14
## - x1    1     0.035   2.651 -398.02
## - x15   1     0.038   2.654 -397.90
## - x2    1     0.045   2.661 -397.60
## <none>                2.616 -397.52
## - x5    1     0.059   2.676 -396.98
## - x7    1     0.064   2.680 -396.80
## - x14   1     0.266   2.882 -388.59
## - x18   1     0.387   3.003 -383.93
## - x10   1     1.606   4.222 -345.44
## - x6    1     3.193   5.809 -309.38
## - x12   1   169.034 171.650   73.24
## 
## Step:  AIC=-398.55
## y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + x15 + 
##     x18
## 
##        Df Sum of Sq     RSS     AIC
## - x15   1     0.019   2.658 -399.74
## - x1    1     0.039   2.677 -398.91
## - x5    1     0.039   2.678 -398.89
## - x13   1     0.040   2.679 -398.84
## - x2    1     0.042   2.680 -398.78
## - x3    1     0.047   2.686 -398.56
## <none>                2.639 -398.55
## - x7    1     0.071   2.710 -397.54
## - x14   1     0.270   2.908 -389.56
## - x18   1     2.891   5.529 -316.96
## - x6    1     3.181   5.820 -311.18
## - x10   1     7.863  10.502 -244.47
## - x12   1   174.820 177.459   75.00
## 
## Step:  AIC=-399.74
## y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x2    1     0.039   2.697 -400.10
## - x1    1     0.044   2.701 -399.90
## - x3    1     0.044   2.702 -399.87
## - x5    1     0.045   2.703 -399.85
## - x13   1     0.045   2.703 -399.84
## <none>                2.658 -399.74
## - x7    1     0.071   2.729 -398.75
## - x18   1     2.937   5.595 -317.63
## - x6    1     3.218   5.876 -312.08
## - x14   1     4.296   6.954 -293.06
## - x10   1     8.152  10.809 -243.21
## - x12   1   175.662 178.320   73.55
## 
## Step:  AIC=-400.1
## y ~ x1 + x3 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x3    1     0.037   2.733 -400.57
## - x1    1     0.039   2.736 -400.46
## - x13   1     0.043   2.740 -400.31
## <none>                2.697 -400.10
## - x5    1     0.053   2.750 -399.90
## - x7    1     0.058   2.755 -399.67
## - x18   1     2.940   5.636 -318.79
## - x6    1     3.201   5.898 -313.67
## - x14   1     4.350   7.047 -293.55
## - x10   1     8.113  10.810 -245.21
## - x12   1   183.729 186.426   76.57
## 
## Step:  AIC=-400.57
## y ~ x1 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x13   1     0.010   2.743 -402.16
## - x7    1     0.030   2.764 -401.33
## - x1    1     0.041   2.774 -400.90
## <none>                2.733 -400.57
## - x5    1     0.057   2.791 -400.23
## - x18   1     2.983   5.717 -319.19
## - x6    1     3.346   6.079 -312.24
## - x14   1     4.601   7.335 -291.03
## - x10   1     8.077  10.810 -247.20
## - x12   1   186.520 189.254   76.27
## 
## Step:  AIC=-402.16
## y ~ x1 + x5 + x6 + x7 + x10 + x12 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x1    1     0.039   2.782 -402.56
## - x7    1     0.040   2.783 -402.52
## <none>                2.743 -402.16
## - x5    1     0.060   2.804 -401.70
## - x18   1     3.819   6.562 -305.61
## - x6    1     3.954   6.697 -303.30
## - x14   1     4.752   7.496 -290.58
## - x10   1    10.165  12.909 -229.15
## - x12   1   195.196 197.939   79.34
## 
## Step:  AIC=-402.56
## y ~ x5 + x6 + x7 + x10 + x12 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x7    1     0.041   2.824 -402.90
## <none>                2.782 -402.56
## - x5    1     0.055   2.838 -402.34
## - x18   1     3.931   6.714 -305.02
## - x6    1     4.026   6.808 -303.45
## - x14   1     4.847   7.629 -290.58
## - x10   1    10.240  13.023 -230.16
## - x12   1   197.697 200.479   78.79
## 
## Step:  AIC=-402.9
## y ~ x5 + x6 + x10 + x12 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x5    1     0.042   2.865 -403.24
## <none>                2.824 -402.90
## - x6    1     4.651   7.475 -294.89
## - x18   1     6.435   9.258 -270.71
## - x14   1     7.037   9.861 -263.59
## - x10   1    10.446  13.270 -230.03
## - x12   1   206.741 209.565   81.79
## 
## Step:  AIC=-403.24
## y ~ x6 + x10 + x12 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## <none>                2.865 -403.24
## - x6    1     4.738   7.603 -294.97
## - x18   1     6.403   9.268 -272.59
## - x14   1     7.114   9.979 -264.24
## - x10   1    10.534  13.400 -230.93
## - x12   1   213.635 216.500   83.47
# CHOOSES THE MODEL:
# y ~ x6 + x10 + x12 + x14 + x18
# Summary information
summary(back_aic)
## 
## Call:
## lm(formula = y ~ x6 + x10 + x12 + x14 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.44914 -0.07025  0.01326  0.06725  0.75342 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.404720   0.200281  -12.01   <2e-16 ***
## x6           0.536888   0.040365   13.30   <2e-16 ***
## x10          1.346157   0.067872   19.83   <2e-16 ***
## x12          0.233623   0.002616   89.32   <2e-16 ***
## x14          1.541982   0.094606   16.30   <2e-16 ***
## x18         -0.506816   0.032777  -15.46   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1636 on 107 degrees of freedom
## Multiple R-squared:  0.9978, Adjusted R-squared:  0.9977 
## F-statistic:  9661 on 5 and 107 DF,  p-value: < 2.2e-16
# 12th Approach: BIC (BOTH WITH K=ln(length(y)))
back_bic <- step(mq, scope=formula(mq), direction="backward", k=log(length(y)))
## Start:  AIC=-336.64
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + 
##     x12 + x13 + x14 + x15 + x16 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x9    1     0.001   2.595 -341.35
## - x8    1     0.001   2.595 -341.35
## - x16   1     0.002   2.596 -341.30
## - x13   1     0.003   2.597 -341.26
## - x17   1     0.004   2.598 -341.21
## - x4    1     0.009   2.604 -340.96
## - x11   1     0.021   2.615 -340.48
## - x6    1     0.023   2.617 -340.37
## - x3    1     0.028   2.622 -340.17
## - x1    1     0.031   2.625 -340.04
## - x15   1     0.032   2.627 -339.97
## - x2    1     0.049   2.643 -339.26
## - x5    1     0.055   2.650 -338.98
## - x7    1     0.069   2.663 -338.42
## <none>                2.594 -336.64
## - x14   1     0.240   2.834 -331.37
## - x18   1     0.312   2.906 -328.55
## - x10   1     0.326   2.920 -328.00
## - x12   1   146.022 148.616  116.05
## 
## Step:  AIC=-341.35
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x10 + x11 + x12 + 
##     x13 + x14 + x15 + x16 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x8    1     0.001   2.596 -346.04
## - x16   1     0.002   2.597 -346.00
## - x13   1     0.003   2.598 -345.95
## - x17   1     0.004   2.599 -345.90
## - x4    1     0.009   2.604 -345.68
## - x11   1     0.020   2.615 -345.21
## - x6    1     0.025   2.620 -344.99
## - x3    1     0.027   2.622 -344.89
## - x1    1     0.032   2.627 -344.71
## - x15   1     0.034   2.629 -344.59
## - x2    1     0.049   2.644 -343.98
## - x5    1     0.058   2.653 -343.58
## - x7    1     0.068   2.663 -343.14
## <none>                2.595 -341.35
## - x14   1     0.252   2.847 -335.61
## - x18   1     0.341   2.936 -332.12
## - x10   1     1.551   4.145 -293.14
## - x12   1   150.967 153.562  115.02
## 
## Step:  AIC=-346.04
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x10 + x11 + x12 + x13 + 
##     x14 + x15 + x16 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x16   1     0.002   2.597 -350.70
## - x13   1     0.003   2.598 -350.66
## - x17   1     0.004   2.600 -350.60
## - x4    1     0.011   2.607 -350.30
## - x11   1     0.022   2.618 -349.82
## - x3    1     0.028   2.623 -349.58
## - x6    1     0.028   2.624 -349.56
## - x1    1     0.032   2.628 -349.38
## - x15   1     0.036   2.631 -349.23
## - x2    1     0.049   2.645 -348.66
## - x5    1     0.059   2.655 -348.22
## - x7    1     0.070   2.666 -347.77
## <none>                2.596 -346.04
## - x14   1     0.270   2.866 -339.59
## - x18   1     0.378   2.974 -335.39
## - x10   1     1.588   4.184 -296.82
## - x12   1   167.589 170.184  121.91
## 
## Step:  AIC=-350.7
## y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x10 + x11 + x12 + x13 + 
##     x14 + x15 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x4    1     0.010   2.608 -354.98
## - x17   1     0.012   2.609 -354.93
## - x11   1     0.021   2.618 -354.53
## - x3    1     0.027   2.624 -354.27
## - x1    1     0.032   2.629 -354.07
## - x15   1     0.034   2.631 -353.95
## - x13   1     0.046   2.643 -353.47
## - x2    1     0.050   2.647 -353.29
## - x5    1     0.058   2.655 -352.94
## - x7    1     0.069   2.666 -352.48
## <none>                2.597 -350.70
## - x14   1     0.273   2.870 -344.14
## - x18   1     0.377   2.974 -340.11
## - x10   1     1.611   4.208 -300.90
## - x6    1     3.133   5.730 -266.02
## - x12   1   167.601 170.198  117.19
## 
## Step:  AIC=-354.98
## y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x11 + x12 + x13 + x14 + 
##     x15 + x17 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x17   1     0.009   2.616 -359.34
## - x11   1     0.022   2.629 -358.78
## - x1    1     0.032   2.640 -358.32
## - x15   1     0.034   2.641 -358.25
## - x13   1     0.035   2.643 -358.19
## - x3    1     0.036   2.644 -358.15
## - x2    1     0.051   2.658 -357.53
## - x5    1     0.055   2.663 -357.35
## - x7    1     0.069   2.677 -356.75
## <none>                2.608 -354.98
## - x14   1     0.272   2.880 -348.48
## - x18   1     0.385   2.993 -344.14
## - x10   1     1.614   4.221 -305.27
## - x6    1     3.187   5.795 -269.47
## - x12   1   167.630 170.238  112.49
## 
## Step:  AIC=-359.34
## y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x11 + x12 + x13 + x14 + 
##     x15 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x11   1     0.023   2.639 -363.09
## - x13   1     0.031   2.647 -362.74
## - x3    1     0.032   2.648 -362.68
## - x1    1     0.035   2.651 -362.56
## - x15   1     0.038   2.654 -362.45
## - x2    1     0.045   2.661 -362.15
## - x5    1     0.059   2.676 -361.52
## - x7    1     0.064   2.680 -361.34
## <none>                2.616 -359.34
## - x14   1     0.266   2.882 -353.13
## - x18   1     0.387   3.003 -348.47
## - x10   1     1.606   4.222 -309.99
## - x6    1     3.193   5.809 -273.92
## - x12   1   169.034 171.650  108.70
## 
## Step:  AIC=-363.09
## y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + x15 + 
##     x18
## 
##        Df Sum of Sq     RSS     AIC
## - x15   1     0.019   2.658 -367.01
## - x1    1     0.039   2.677 -366.18
## - x5    1     0.039   2.678 -366.16
## - x13   1     0.040   2.679 -366.11
## - x2    1     0.042   2.680 -366.05
## - x3    1     0.047   2.686 -365.83
## - x7    1     0.071   2.710 -364.81
## <none>                2.639 -363.09
## - x14   1     0.270   2.908 -356.83
## - x18   1     2.891   5.529 -284.23
## - x6    1     3.181   5.820 -278.45
## - x10   1     7.863  10.502 -211.74
## - x12   1   174.820 177.459  107.73
## 
## Step:  AIC=-367.01
## y ~ x1 + x2 + x3 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x2    1     0.039   2.697 -370.10
## - x1    1     0.044   2.701 -369.90
## - x3    1     0.044   2.702 -369.87
## - x5    1     0.045   2.703 -369.85
## - x13   1     0.045   2.703 -369.84
## - x7    1     0.071   2.729 -368.75
## <none>                2.658 -367.01
## - x18   1     2.937   5.595 -287.63
## - x6    1     3.218   5.876 -282.08
## - x14   1     4.296   6.954 -263.06
## - x10   1     8.152  10.809 -213.21
## - x12   1   175.662 178.320  103.55
## 
## Step:  AIC=-370.1
## y ~ x1 + x3 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x3    1     0.037   2.733 -373.30
## - x1    1     0.039   2.736 -373.18
## - x13   1     0.043   2.740 -373.03
## - x5    1     0.053   2.750 -372.62
## - x7    1     0.058   2.755 -372.40
## <none>                2.697 -370.10
## - x18   1     2.940   5.636 -291.52
## - x6    1     3.201   5.898 -286.40
## - x14   1     4.350   7.047 -266.28
## - x10   1     8.113  10.810 -217.93
## - x12   1   183.729 186.426  103.85
## 
## Step:  AIC=-373.3
## y ~ x1 + x5 + x6 + x7 + x10 + x12 + x13 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x13   1     0.010   2.743 -377.62
## - x7    1     0.030   2.764 -376.78
## - x1    1     0.041   2.774 -376.35
## - x5    1     0.057   2.791 -375.68
## <none>                2.733 -373.30
## - x18   1     2.983   5.717 -294.64
## - x6    1     3.346   6.079 -287.69
## - x14   1     4.601   7.335 -266.48
## - x10   1     8.077  10.810 -222.65
## - x12   1   186.520 189.254  100.82
## 
## Step:  AIC=-377.62
## y ~ x1 + x5 + x6 + x7 + x10 + x12 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x1    1     0.039   2.782 -380.74
## - x7    1     0.040   2.783 -380.71
## - x5    1     0.060   2.804 -379.88
## <none>                2.743 -377.62
## - x18   1     3.819   6.562 -283.79
## - x6    1     3.954   6.697 -281.48
## - x14   1     4.752   7.496 -268.76
## - x10   1    10.165  12.909 -207.33
## - x12   1   195.196 197.939  101.16
## 
## Step:  AIC=-380.74
## y ~ x5 + x6 + x7 + x10 + x12 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x7    1     0.041   2.824 -383.81
## - x5    1     0.055   2.838 -383.25
## <none>                2.782 -380.74
## - x18   1     3.931   6.714 -285.93
## - x6    1     4.026   6.808 -284.35
## - x14   1     4.847   7.629 -271.49
## - x10   1    10.240  13.023 -211.06
## - x12   1   197.697 200.479   97.88
## 
## Step:  AIC=-383.81
## y ~ x5 + x6 + x10 + x12 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## - x5    1     0.042   2.865 -386.88
## <none>                2.824 -383.81
## - x6    1     4.651   7.475 -278.52
## - x18   1     6.435   9.258 -254.35
## - x14   1     7.037   9.861 -247.22
## - x10   1    10.446  13.270 -213.67
## - x12   1   206.741 209.565   98.16
## 
## Step:  AIC=-386.88
## y ~ x6 + x10 + x12 + x14 + x18
## 
##        Df Sum of Sq     RSS     AIC
## <none>                2.865 -386.88
## - x6    1     4.738   7.603 -281.33
## - x18   1     6.403   9.268 -258.96
## - x14   1     7.114   9.979 -250.60
## - x10   1    10.534  13.400 -217.30
## - x12   1   213.635 216.500   97.11
# CHOOSES THE MODEL:
# y ~ x6 + x10 + x12 + x14 + x18
# Summary information
summary(back_bic)
## 
## Call:
## lm(formula = y ~ x6 + x10 + x12 + x14 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.44914 -0.07025  0.01326  0.06725  0.75342 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.404720   0.200281  -12.01   <2e-16 ***
## x6           0.536888   0.040365   13.30   <2e-16 ***
## x10          1.346157   0.067872   19.83   <2e-16 ***
## x12          0.233623   0.002616   89.32   <2e-16 ***
## x14          1.541982   0.094606   16.30   <2e-16 ***
## x18         -0.506816   0.032777  -15.46   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1636 on 107 degrees of freedom
## Multiple R-squared:  0.9978, Adjusted R-squared:  0.9977 
## F-statistic:  9661 on 5 and 107 DF,  p-value: < 2.2e-16
# IDENTIFIED MODELS:
# BACKWARD (p-value): y ~ x6 + x10 + x12 + x14 + x18 [All extremely significant]
# FORWARD (p-value): y ~ x6 + x12 + x9 + x11 + x10 [All extremely significant except x9]
# MIXED (p-value): y ~ x6 + x12 + x11 + x10 [All extremely significant]
# FORWARD (LIKELIHOODS COMPARISON): y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10 + x5 + x15 + x7 + x2 + x1 + x3 + x13 + x4 + x17 + x16 + x8
# FORWARD (AIC): y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10
# FORWARD (BIC): y ~ x12 + x9 + x18 + x14 + x11
# BOTH (LIKELIHOODS COMPARISON): y ~ x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18
# BOTH (AIC): y ~ x6 + x10 + x12 + x14 + x18
# BOTH (BIC): y ~ x6 + x10 + x12 + x14 + x18
# BACKWARD (LIKELIHOODS COMPARISON): y ~ x6 + x10 + x12 + x14 + x18
# BACKWARD (AIC): y ~ x6 + x10 + x12 + x14 + x18
# BACKWARD (BIC): y ~ x6 + x10 + x12 + x14 + x18

# POTENTIALLY VALID MODELS:
# EXCLUDING COMPLETE AND DUPLICATE MODELS:
# A - 6 occurrences: y ~ x6 + x10 + x12 + x14 + x18
# B - 1 occurrence: y ~ x6 + x12 + x9 + x11 + x10
# C - 1 occurrence: y ~ x6 + x12 + x11 + x10
# D - 1 occurrence: y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10
# E - 1 occurrence: y ~ x12 + x9 + x18 + x14 + x11

# A
a <- lm(y ~ x6 + x10 + x12 + x14 + x18)
summary(a)
## 
## Call:
## lm(formula = y ~ x6 + x10 + x12 + x14 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.44914 -0.07025  0.01326  0.06725  0.75342 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.404720   0.200281  -12.01   <2e-16 ***
## x6           0.536888   0.040365   13.30   <2e-16 ***
## x10          1.346157   0.067872   19.83   <2e-16 ***
## x12          0.233623   0.002616   89.32   <2e-16 ***
## x14          1.541982   0.094606   16.30   <2e-16 ***
## x18         -0.506816   0.032777  -15.46   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1636 on 107 degrees of freedom
## Multiple R-squared:  0.9978, Adjusted R-squared:  0.9977 
## F-statistic:  9661 on 5 and 107 DF,  p-value: < 2.2e-16
# B
b <- lm(y ~ x6 + x12 + x9 + x11 + x10)
summary(b)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x9 + x11 + x10)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.51527 -0.06311  0.01123  0.07509  0.76495 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -9.806484   2.941230  -3.334 0.001176 ** 
## x6           0.329184   0.125133   2.631 0.009779 ** 
## x12          0.233187   0.002877  81.041  < 2e-16 ***
## x9          -0.314002   0.239618  -1.310 0.192856    
## x11          0.797302   0.180422   4.419 2.38e-05 ***
## x10          1.257455   0.351987   3.572 0.000532 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1767 on 107 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic:  8279 on 5 and 107 DF,  p-value: < 2.2e-16
# C
c <- lm(y ~ x6 + x12 + x11 + x10)
summary(c)
## 
## Call:
## lm(formula = y ~ x6 + x12 + x11 + x10)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.54633 -0.05866  0.00924  0.07217  0.76854 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -13.514137   0.806207  -16.76   <2e-16 ***
## x6            0.485352   0.038286   12.68   <2e-16 ***
## x12           0.232624   0.002854   81.50   <2e-16 ***
## x11           1.015592   0.069539   14.61   <2e-16 ***
## x10           1.701196   0.096391   17.65   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1773 on 108 degrees of freedom
## Multiple R-squared:  0.9974, Adjusted R-squared:  0.9973 
## F-statistic: 1.028e+04 on 4 and 108 DF,  p-value: < 2.2e-16
# D
d <- lm(y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10)
summary(d)
## 
## Call:
## lm(formula = y ~ x12 + x9 + x18 + x14 + x11 + x6 + x10)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.41987 -0.06391  0.01433  0.07466  0.75100 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.453316   3.649208   0.124 0.901376    
## x12          0.234117   0.002708  86.455  < 2e-16 ***
## x9          -0.103748   0.235824  -0.440 0.660885    
## x18         -0.575286   0.137484  -4.184 5.95e-05 ***
## x14          1.752429   0.431097   4.065 9.30e-05 ***
## x11         -0.221445   0.295084  -0.750 0.454664    
## x6           0.487450   0.123099   3.960 0.000137 ***
## x10          1.135744   0.330636   3.435 0.000850 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1647 on 105 degrees of freedom
## Multiple R-squared:  0.9978, Adjusted R-squared:  0.9977 
## F-statistic:  6811 on 7 and 105 DF,  p-value: < 2.2e-16
# E
e <- lm(y ~ x12 + x9 + x18 + x14 + x11)
summary(e)
## 
## Call:
## lm(formula = y ~ x12 + x9 + x18 + x14 + x11)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.64191 -0.06187  0.02281  0.06056  0.74776 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  6.410137   0.925946   6.923 3.41e-10 ***
## x12          0.234033   0.002577  90.830  < 2e-16 ***
## x9          -0.974535   0.076614 -12.720  < 2e-16 ***
## x18         -0.362493   0.066296  -5.468 3.01e-07 ***
## x14          1.082834   0.224265   4.828 4.61e-06 ***
## x11         -0.428942   0.109931  -3.902 0.000167 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.175 on 107 degrees of freedom
## Multiple R-squared:  0.9975, Adjusted R-squared:  0.9974 
## F-statistic:  8443 on 5 and 107 DF,  p-value: < 2.2e-16
# The most significant models are A and C (based on the p-values)
# CHOSEN FINAL MODEL:
# A with 6 occurrences: y ~ x6 + x10 + x12 + x14 + x18
summary(a)
## 
## Call:
## lm(formula = y ~ x6 + x10 + x12 + x14 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.44914 -0.07025  0.01326  0.06725  0.75342 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.404720   0.200281  -12.01   <2e-16 ***
## x6           0.536888   0.040365   13.30   <2e-16 ***
## x10          1.346157   0.067872   19.83   <2e-16 ***
## x12          0.233623   0.002616   89.32   <2e-16 ***
## x14          1.541982   0.094606   16.30   <2e-16 ***
## x18         -0.506816   0.032777  -15.46   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1636 on 107 degrees of freedom
## Multiple R-squared:  0.9978, Adjusted R-squared:  0.9977 
## F-statistic:  9661 on 5 and 107 DF,  p-value: < 2.2e-16
# DEFINITION OF THE IDENTIFIED MODEL:
mq <- lm(y ~ x6 + x10 + x12 + x14 + x18)
print(summary(mq))
## 
## Call:
## lm(formula = y ~ x6 + x10 + x12 + x14 + x18)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.44914 -0.07025  0.01326  0.06725  0.75342 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.404720   0.200281  -12.01   <2e-16 ***
## x6           0.536888   0.040365   13.30   <2e-16 ***
## x10          1.346157   0.067872   19.83   <2e-16 ***
## x12          0.233623   0.002616   89.32   <2e-16 ***
## x14          1.541982   0.094606   16.30   <2e-16 ***
## x18         -0.506816   0.032777  -15.46   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.1636 on 107 degrees of freedom
## Multiple R-squared:  0.9978, Adjusted R-squared:  0.9977 
## F-statistic:  9661 on 5 and 107 DF,  p-value: < 2.2e-16
# PHASE 5:
# PRELIMINARY ANALYSIS OF THE MODEL AND RESIDUALS:

# LIST OF SIGNIFICANT VARIABLES FOR CENTRAL VELOCITY DISPERSION (Km/s):
# Mv: Absolute magnitude
# log.t: Central relaxation time (years)
# V.esc: Central escape velocity (Km/s)
# E.B.V: Color excess (Magnitude)
# CSBt: Central surface brightness (Magnitude per square arcsecond)

# VARIABLE ANALYSIS:
# ALL VARIABLES ARE EXTREMELY SIGNIFICANT
# EFFECT OF VARIABLES ON CENTRAL VELOCITY DISPERSION:
# Mv: an increase in magnitude of one unit leads to an increase of approximately 0.536888 Km/s
# log.t: one year of central relaxation on a logarithmic scale leads to an increase of 1.346157 Km/s
# V.esc: an increase in escape velocity of 1 Km/s results in an increase of 0.233623 Km/s
# E.B.V: an increase of one unit in the magnitude of color excess results in an increase of 1.541982 Km/s
# CSBt: a one-unit increase in central surface brightness results in a decrease of 0.506816 Km/s

# ANALYSIS OF MODEL RESULTS
# STANDARD ERROR ESTIMATE: 0.1636 with 107 degrees of freedom [being relatively
# small, indicates good precision of the estimates.]
# DETERMINATION COEFFICIENT: 0.9977 [being very high, indicates that the
# model almost completely explains the variance of the dependent variable y.]
# F-TEST: EXTREMELY SIGNIFICANT [9661 out of 5 and 107 DF]
# Residuals are well distributed, with the median close to zero.
# A very high F-value and a very low p-value (as indicated in the
# results provided, p < 2.2e-16) reject the null hypothesis that the model with
# only the intercept term is equally good at explaining the variability
# in the dependent variable.]:
# IN THIS CASE, THE MODEL SHOWS AN EXCELLENT FIT!

# CREATING THE MODEL GRAPH:
plot(mq)

# The residuals appear to have an approximately normal distribution.
# The graph shows the presence of some extreme points
# that potentially interfere with the model (outliers).
# ANALYSIS OF POTENTIAL OUTLIERS:
boxplot(mq$residuals)

# GRAPH ANALYSIS:
# Residuals are centered: The median near zero indicates that the regression model is
# not biased either high or low.
# The concentration of data near the median and symmetry suggest
# that most of the data follows the identified model.
# However, there are potential outliers: Points outside the whiskers (at the extremes)

# Calculation of standardized residuals
std_res <- rstandard(mq)
# Identification of outliers
# The number "2" is a threshold conventionally chosen for the normal
# (or Gaussian) distribution. In a standardized normal distribution:
# About 95% of the data lies within 2 standard deviations from the mean.
outliers <- which(abs(std_res) > 2)
# Removing outliers from the dataset
clean_dat <- dat[-outliers, ]
# Verification of outlier removal
print(nrow(dat))
## [1] 113
print(nrow(clean_dat))
## [1] 108
# Updating the model without outliers
clean_mq <- lm(y ~ x6 + x10 + x12 + x14 + x18, data=clean_dat)
# Graph of residuals with and without outliers
par(mfrow=c(1,2))
plot(mq$fitted.values, mq$residuals, main="With Outliers")
abline(h=0, col="red")
plot(clean_mq$fitted.values, clean_mq$residuals, main="Without Outliers")
abline(h=0, col="blue")

# Resetting graph creation settings
par(mfrow=c(1,1))

# GRAPH ANALYSIS:
# Outliers do not seem to have a significant impact on the model, as the graphs
# are practically identical. This indicates that the model is quite
# robust and has a high tolerance for anomalous values.
# I will keep the model unchanged.

# DATA RESULTING FROM THE USE OF A GLM (Generalized Linear Model)
# DEFINITION OF THE IDENTIFIED MODEL:
mqg <- glm(y ~ x6 + x10 + x12 + x14 + x18)
print(summary(mqg))
## 
## Call:
## glm(formula = y ~ x6 + x10 + x12 + x14 + x18)
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.404720   0.200281  -12.01   <2e-16 ***
## x6           0.536888   0.040365   13.30   <2e-16 ***
## x10          1.346157   0.067872   19.83   <2e-16 ***
## x12          0.233623   0.002616   89.32   <2e-16 ***
## x14          1.541982   0.094606   16.30   <2e-16 ***
## x18         -0.506816   0.032777  -15.46   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 0.02677899)
## 
##     Null deviance: 1296.3894  on 112  degrees of freedom
## Residual deviance:    2.8654  on 107  degrees of freedom
## AIC: -80.561
## 
## Number of Fisher Scoring iterations: 2
# THE IDENTIFIED DISTRIBUTION FAMILY IS GAUSSIAN
# WITH IDENTITY LINK FUNCTION
print(mqg$family)
## 
## Family: gaussian 
## Link function: identity
# The glm model, using the same formula as the linear model (y ~ x6 + x10 + x12 + x14 + x18),
# suggests similar results in terms of variable significance,
# as indicated by the coefficients and p-values. This indicates that all the selected
# variables are statistically significant in the model.
# The main difference lies in the use of glm, which can be adapted to
# model a wider range of residual distributions compared to lm.
# The model behaves similarly to lm for normally distributed data.
# The dispersion parameter and AIC value also indicate good model fit to the data.

# EVALUATION OF THE EFFECT OF INDIVIDUAL VARIABLES ON CENTRAL
# VELOCITY DISPERSION:

# ABSOLUTE MAGNITUDE
mqgx6 <- glm(y ~ x6)
summary(mqgx6)
## 
## Call:
## glm(formula = y ~ x6)
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -10.2611     1.1210  -9.154 3.17e-15 ***
## x6           -2.2190     0.1488 -14.915  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 3.887633)
## 
##     Null deviance: 1296.39  on 112  degrees of freedom
## Residual deviance:  431.53  on 111  degrees of freedom
## AIC: 478.09
## 
## Number of Fisher Scoring iterations: 2
# The variable's high significance is confirmed.
# An increase in magnitude level leads to a reduction in velocity
# dispersion of 2.2190 Km/s

# CENTRAL RELAXATION TIME:
mqgx10 <- glm(y ~ x10)
summary(mqgx10)
## 
## Call:
## glm(formula = y ~ x10)
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  15.0509     3.2848   4.582 1.21e-05 ***
## x10          -1.0902     0.4041  -2.698  0.00806 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 10.96039)
## 
##     Null deviance: 1296.4  on 112  degrees of freedom
## Residual deviance: 1216.6  on 111  degrees of freedom
## AIC: 595.22
## 
## Number of Fisher Scoring iterations: 2
# High significance is confirmed again, albeit slightly
# reduced compared to the model containing all variables.
# Each year of relaxation results in a velocity reduction of 1.0902 Km/s

# CENTRAL ESCAPE VELOCITY:
mqgx12 <- glm(y ~ x12)
summary(mqgx12)
## 
## Call:
## glm(formula = y ~ x12)
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.30958    0.07152   4.329  3.3e-05 ***
## x12          0.23609    0.00248  95.210  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 0.1412813)
## 
##     Null deviance: 1296.389  on 112  degrees of freedom
## Residual deviance:   15.682  on 111  degrees of freedom
## AIC: 103.52
## 
## Number of Fisher Scoring iterations: 2
# High significance is confirmed.
# An increase in escape velocity of 1 Km/s corresponds to an increase in
# velocity dispersion of 0.23609 Km/s

# COLOR EXCESS MAGNITUDE
mqgx14 <- glm(y ~ x14)
summary(mqgx14)
## 
## Call:
## glm(formula = y ~ x14)
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   5.6336     0.4071  13.839   <2e-16 ***
## x14           1.8018     0.7845   2.297   0.0235 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 11.14931)
## 
##     Null deviance: 1296.4  on 112  degrees of freedom
## Residual deviance: 1237.6  on 111  degrees of freedom
## AIC: 597.15
## 
## Number of Fisher Scoring iterations: 2
# Significant, but reduced compared to the model containing
# all variables.
# An increase of one unit in color excess magnitude results in an
# increase in velocity dispersion of 1.80018 Km/s

# CENTRAL SURFACE BRIGHTNESS:
mqgx18 <- glm(y ~ x18)
summary(mqgx18)
## 
## Call:
## glm(formula = y ~ x18)
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  16.6882     1.0316   16.18   <2e-16 ***
## x18          -1.1431     0.1099  -10.40   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 5.915889)
## 
##     Null deviance: 1296.39  on 112  degrees of freedom
## Residual deviance:  656.66  on 111  degrees of freedom
## AIC: 525.54
## 
## Number of Fisher Scoring iterations: 2
# Highly significant.
# An increase in central surface brightness by one unit (magnitude per square arcsecond)
# leads to a reduction in velocity dispersion of 1.1231 Km/s

# PHASE 6:
# CORRELATION ANALYSIS AMONG THE MODEL VARIABLES:

# CREATING CORRELATION GRAPHS AMONG THE MODEL VARIABLES
plot(x6, x10)

plot(x6, x12)

plot(x6, x14)

plot(x6, x18)

plot(x10, x12)

plot(x10, x14)

plot(x10, x18)

plot(x12, x14)

plot(x12, x18)

plot(x14, x18)

# GRAPH ANALYSIS:
# POSSIBLE IDENTIFIED CORRELATIONS:
# x6-x12: x12 decreases as x6 increases, with a negative exponential trend
# x6-x18: Increase linearly
# x10-x18: Increase linearly
# x12-x18: x18 decreases as x12 increases, with a negative exponential trend

# EVALUATION OF MORE COMPLEX REGRESSION MODELS CONSIDERING
# POTENTIAL CORRELATIONS:
mqgx6x12 <- glm(y ~ x6*x12 + x10 + x14 + x18)
summary(mqgx6x12)
## 
## Call:
## glm(formula = y ~ x6 * x12 + x10 + x14 + x18)
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.763692   0.410018  -4.301 3.79e-05 ***
## x6           0.572460   0.044646  12.822  < 2e-16 ***
## x12          0.198314   0.019937   9.947  < 2e-16 ***
## x10          1.382440   0.070192  19.695  < 2e-16 ***
## x14          1.744244   0.146951  11.870  < 2e-16 ***
## x18         -0.561024   0.044428 -12.628  < 2e-16 ***
## x6:x12      -0.003210   0.001797  -1.786   0.0769 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 0.02624184)
## 
##     Null deviance: 1296.3894  on 112  degrees of freedom
## Residual deviance:    2.7816  on 106  degrees of freedom
## AIC: -81.911
## 
## Number of Fisher Scoring iterations: 2
# The p-value for the interaction term is 0.0769, which is above the
# threshold of 0.05. This suggests that while the individual variables are significant,
# the additional effect of their interaction is not statistically
# significant.

# CORRELATION INDEX
cor(x6, x12) # Indicates a strong negative correlation between the two
## [1] -0.8085964
# Mv and CSBt
mqgx6x18 <- glm(y ~ x6*x18 + x10 + x12 + x14)
summary(mqgx6x18)
## 
## Call:
## glm(formula = y ~ x6 * x18 + x10 + x12 + x14)
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.480091   0.647729  -0.741  0.46022    
## x6           0.845940   0.106623   7.934 2.33e-12 ***
## x18         -0.638334   0.052722 -12.108  < 2e-16 ***
## x10          1.279510   0.068698  18.625  < 2e-16 ***
## x12          0.246281   0.004782  51.498  < 2e-16 ***
## x14          1.244678   0.131926   9.435 1.05e-15 ***
## x6:x18      -0.028592   0.009187  -3.112  0.00239 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 0.02476848)
## 
##     Null deviance: 1296.3894  on 112  degrees of freedom
## Residual deviance:    2.6255  on 106  degrees of freedom
## AIC: -88.441
## 
## Number of Fisher Scoring iterations: 2
# The effect of absolute magnitude on velocity dispersion varies based on
# different levels of central surface brightness and vice versa.
# The interaction between these two measures is significant, and an increase in it leads to a
# reduction in velocity dispersion of 0.028592 Km/s

# CORRELATION INDEX:
cor(x6, x18) # confirms a positive correlation
## [1] 0.6554871
# CONFIDENCE INTERVAL:
# With a test statistic (DEV) of 63.453 and a p-value very close to 0,
# a strong dependency between the two variables is highlighted
ci.dumpx6x18 <- ciTest(dat, set=c("Mv", "CSBt"))
print(ci.dumpx6x18)
## Testing Mv _|_ CSBt 
## Statistic (DEV):   63.453 df: 1 p-value: 0.0000 method: CHISQ
# log.t and CSBt
mqgx10x18 <- glm(y ~ x10*x18 + x6 + x12 + x14)
summary(mqgx10x18)
## 
## Call:
## glm(formula = y ~ x10 * x18 + x6 + x12 + x14)
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -5.010253   0.794629  -6.305 6.75e-09 ***
## x10          1.608991   0.101250  15.891  < 2e-16 ***
## x18         -0.174181   0.103318  -1.686  0.09476 .  
## x6           0.517715   0.038949  13.292  < 2e-16 ***
## x12          0.235078   0.002534  92.775  < 2e-16 ***
## x14          1.364585   0.104471  13.062  < 2e-16 ***
## x10:x18     -0.035867   0.010617  -3.378  0.00102 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 0.02440424)
## 
##     Null deviance: 1296.3894  on 112  degrees of freedom
## Residual deviance:    2.5868  on 106  degrees of freedom
## AIC: -90.115
## 
## Number of Fisher Scoring iterations: 2
# With a p-value of 0.00102, there is a significant dependency between central relaxation time and
# central surface brightness in the context of velocity dispersion.
# An increase in the interaction leads to a reduction in velocity dispersion
# of 0.035867 Km/s

# CORRELATION INDEX:
cor(x10, x18) # confirms a positive correlation
## [1] 0.5149092
# CONFIDENCE INTERVAL:
# Shows a test statistic (DEV) of 34.811 with a p-value very close to 0,
# denoting a strong dependency between the two variables
ci.dumpx6x18 <- ciTest(dat, set=c("log.t", "CSBt"))
print(ci.dumpx6x18)
## Testing log.t _|_ CSBt 
## Statistic (DEV):   34.811 df: 1 p-value: 0.0000 method: CHISQ
# V.esc and CSBt
mqgx12x18 <- glm(y ~ x12*x18 + x6 + x10 + x14)
summary(mqgx12x18)
## 
## Call:
## glm(formula = y ~ x12 * x18 + x6 + x10 + x14)
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.786144   0.232251  -7.691 7.92e-12 ***
## x12          0.218292   0.004236  51.527  < 2e-16 ***
## x18         -0.513986   0.030320 -16.952  < 2e-16 ***
## x6           0.608129   0.040641  14.964  < 2e-16 ***
## x10          1.316115   0.063063  20.870  < 2e-16 ***
## x14          1.164030   0.122462   9.505 7.29e-16 ***
## x12:x18      0.003507   0.000796   4.405 2.53e-05 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 0.02284832)
## 
##     Null deviance: 1296.3894  on 112  degrees of freedom
## Residual deviance:    2.4219  on 106  degrees of freedom
## AIC: -97.559
## 
## Number of Fisher Scoring iterations: 2
# With a p-value of 2.53e-05, the interaction between escape velocity and central surface
# brightness is highly significant for velocity dispersion.
# An increase in the interaction leads to an increase in velocity dispersion
# of 0.03507 Km/s

# CORRELATION INDEX:
cor(x12, x18) # confirms a strong negative correlation
## [1] -0.7282425
# CONFIDENCE INTERVAL:
# The test statistic (DEV) is 85.399 and a p-value very close to 0 suggest
# a strong dependency between the two variables
ci.dumpx12x18 <- ciTest(dat, set=c("V.esc", "CSBt"))
print(ci.dumpx12x18)
## Testing V.esc _|_ CSBt 
## Statistic (DEV):   85.399 df: 1 p-value: 0.0000 method: CHISQ
# CORRELATION RESULT ANALYSIS:
# It is evident that central surface brightness is influenced by absolute magnitude,
# central relaxation time, and central escape velocity!

# UPDATING THE MODEL EXPRESSING THE IDENTIFIED INTERACTIONS BETWEEN VARIABLES:
mqgf <- glm(y ~ x6*x18 + x10*x18 + x12*x18 + x14)
print(summary(mqgf))
## 
## Call:
## glm(formula = y ~ x6 * x18 + x10 * x18 + x12 * x18 + x14)
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -2.554126   0.999568  -2.555  0.01206 *  
## x6           0.808217   0.104794   7.712 7.77e-12 ***
## x18         -0.362439   0.114506  -3.165  0.00203 ** 
## x10          1.480536   0.110841  13.357  < 2e-16 ***
## x12          0.238598   0.008667  27.531  < 2e-16 ***
## x14          0.996829   0.137669   7.241 8.00e-11 ***
## x6:x18      -0.023628   0.010148  -2.328  0.02183 *  
## x18:x10     -0.027620   0.012746  -2.167  0.03252 *  
## x18:x12      0.001511   0.001076   1.404  0.16340    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 0.02174587)
## 
##     Null deviance: 1296.3894  on 112  degrees of freedom
## Residual deviance:    2.2616  on 104  degrees of freedom
## AIC: -101.3
## 
## Number of Fisher Scoring iterations: 2
# ANALYSIS OF THE NEW MODEL:
# The previous glm model, which does not include interaction terms, already
# shows good consistency with the data, as indicated by the low AIC and high
# significance of the coefficients.
# However, the addition of interaction terms has led to some improvements,
# as indicated by an even lower AIC in the second model.
# The interaction x12:x18 is not significant!

# PROCEEDING WITH THE REMOVAL OF SUPERFLUOUS INTERACTION
# REMOVING the interaction between x12 and x18
mqgf <- glm(y ~ x6*x18 + x10*x18 + x12 + x14)
print(summary(mqgf))
## 
## Call:
## glm(formula = y ~ x6 * x18 + x10 * x18 + x12 + x14)
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -3.115921   0.920163  -3.386 0.000998 ***
## x6           0.852553   0.100381   8.493 1.43e-13 ***
## x18         -0.291760   0.103315  -2.824 0.005676 ** 
## x10          1.556646   0.097119  16.028  < 2e-16 ***
## x12          0.248964   0.004556  54.645  < 2e-16 ***
## x14          1.027439   0.136557   7.524 1.90e-11 ***
## x6:x18      -0.031114   0.008673  -3.587 0.000509 ***
## x18:x10     -0.038621   0.010098  -3.825 0.000223 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 0.02194682)
## 
##     Null deviance: 1296.3894  on 112  degrees of freedom
## Residual deviance:    2.3044  on 105  degrees of freedom
## AIC: -101.18
## 
## Number of Fisher Scoring iterations: 2
# The resulting model is further improved and the significance of the
# variables and interactions has increased.
# There is better model quality in terms of balance between fit
# and complexity (More balanced)

# CORRELATION GRAPHS BETWEEN VARIABLES AND CENTRAL VELOCITY DISPERSION:
plot(x6, y)

plot(x10, y)

plot(x12, y)

plot(x14, y)

plot(x18, y)

# FROM THESE GRAPHS, IT IS IMMEDIATELY VISIBLE THAT THE CENTRAL ESCAPE VELOCITY
# IS CLOSELY CORRELATED TO THE CENTRAL VELOCITY DISPERSION
# AS THE TWO QUANTITIES INCREASE LINEARLY

# CORRELATION INDEX:
cor(x12, y) # Extreme positive correlation
## [1] 0.9939332
# PHASE 7:
# MULTIVARIATE ANALYSIS BASED ON GRAPHICAL MODELS:

# Searching for a formula for the independent model (BIC Forward), based on the
# general linear model identified as final
mmug <- cmod(~.^1, marginal =c("Mv","log.t", "V.esc","E.B.V", "CSBt"), data = dat, fit = TRUE)
mmug_bic <- stepwise(mmug, direction = "forward", k=log(sum(dat))) # BIC forward
plot(mmug_bic)

print(formula(mmug_bic))
## ~E.B.V * Mv * CSBt * V.esc * log.t
print(ciTest(dat, set = c("Mv","log.t", "V.esc","E.B.V", "CSBt")))
## Testing Mv _|_ log.t | V.esc E.B.V CSBt 
## Statistic (DEV):  127.832 df: 1 p-value: 0.0000 method: CHISQ
set.frame <- data.frame(
  Mv = dat$Mv,
  log.t = dat$log.t,
  V.esc = dat$V.esc,
  E.B.V = dat$E.B.V,
  CSBt = dat$CSBt
)

print(cor(set.frame))
##                Mv       log.t      V.esc       E.B.V       CSBt
## Mv     1.00000000 -0.08430665 -0.8085964  0.05965678  0.6554871
## log.t -0.08430665  1.00000000 -0.3096412 -0.39958765  0.5149092
## V.esc -0.80859641 -0.30964120  1.0000000  0.20965656 -0.7282425
## E.B.V  0.05965678 -0.39958765  0.2096566  1.00000000  0.2083057
## CSBt   0.65548711  0.51490924 -0.7282425  0.20830574  1.0000000
# Based on the correlation matrix, removing less significant dependencies (values close to zero)
# Discarding weak correlations |corr| < 0.5
mmug_bic <- update(mmug_bic, list(dedge=~Mv * E.B.V + log.t * Mv + V.esc * log.t + E.B.V * log.t + V.esc * E.B.V + E.B.V * CSBt))
plot(mmug_bic)

print(formula(mmug_bic))
## ~E.B.V + log.t * CSBt + Mv * CSBt * V.esc
# Found formula:
# ~E.B.V + log.t * CSBt + Mv * CSBt * V.esc

# Creating a Bayesian network
mbn <- hc(set.frame)
plot(mbn)

# In this case too, the same correlations between
# the variables of the final model with their respective directions have been identified.