Simple Linear Regression

Linear regression models are used to show or predict the relationship between two variables or factors which are the dependent variable and independent variable. Simple Linear Regression Analysis is the simplest form of regression analysis which uses one dependent variable and independent variable, and a straight line approximates the reltionship between the dependent variable and independent variable (https://www.thebalancesmb.com/what-is-simple-linear-regression-2296697).

To start with simple linear regression activity, we need to clear the global environment.

rm(list=ls())

We will then set our work directory. This is the directory that contains the input files and will also be the location where output files are saved. getwd() checks to see if we are in the right directory.

setwd("C:/Users/April Mae Tabonda/Documents/MS Marine Science/Biostat/PLP/RMDs/PLP_10 Simple and Multiple Linear Regression")
getwd()
## [1] "C:/Users/April Mae Tabonda/Documents/MS Marine Science/Biostat/PLP/RMDs/PLP_10 Simple and Multiple Linear Regression"
survey<-read.csv("STDNTSURVEY.csv")
names(survey)
##  [1] "PROG"         "FULLPART"     "SEM"          "STAGE"       
##  [5] "GWA"          "FINSUPPORT"   "EMPLOYED"     "SEX"         
##  [9] "CIVILSTATUS"  "RELIGION"     "AGE"          "AVESLEEP"    
## [13] "EXERCISE"     "UNSTRESS"     "STUDYAREA"    "HOURSNET"    
## [17] "SOCIALNET"    "CUPRICELUNCH" "VIANDLUNCH"   "BFASTDRINK"  
## [21] "SOCIALDRINK"  "SMOKER"       "TVSTA"        "MOBILEPROV"  
## [25] "NUMGADGETS"   "WEIGHT"       "HEIGHT"       "WAIST"       
## [29] "PALM"         "LEGLEN"       "ARMLEN"       "ARMSPAN"     
## [33] "SHOULDERWD"   "SHOESIZE"
head(survey)
##   PROG FULLPART SEM STAGE  GWA FINSUPPORT EMPLOYED SEX CIVILSTATUS
## 1    1        1   3     1 1.20          3        2   1           2
## 2    1        1   5     1 1.75          1        2   1           2
## 3    1        2   3     1 1.60          2        1   2           2
## 4    1        1   1     1   NA          1        2   1           2
## 5    1        2   4     2 1.25          2        1   2           1
## 6    2        2   7     1 1.50          2        1   1           2
##   RELIGION AGE AVESLEEP EXERCISE UNSTRESS STUDYAREA HOURSNET SOCIALNET
## 1 Agnostic  23      4.0        1        2         1        5         1
## 2 Catholic  23      6.0        2        3         4        4         1
## 3 Catholic  23      6.0        2        5         1        5         1
## 4 Catholic  21      9.0        2        1         3        4         1
## 5 Catholic  24      6.5        1        3         4       12         1
## 6 Agnostic  29      6.0        1        3         1       12         1
##   CUPRICELUNCH VIANDLUNCH BFASTDRINK SOCIALDRINK SMOKER TVSTA MOBILEPROV
## 1            0          2          1           3      1     5          2
## 2            1          2          1           3      1     1          2
## 3            1          4          3           3      2     1          2
## 4            1          4          2           3      2    NA          2
## 5            1          2          4           3      2    NA          4
## 6            2          2          5           3      1     5          2
##   NUMGADGETS WEIGHT HEIGHT WAIST PALM LEGLEN ARMLEN ARMSPAN SHOULDERWD
## 1          2  155.0   71.0  30.5 3.80   38.0   31.2    71.0       19.0
## 2          2  155.0   64.0  34.0 3.50   34.5   26.4    68.0       18.0
## 3          3  113.2   61.5  26.0 3.00   32.4   26.0    59.5       16.0
## 4          2  184.0   72.0  32.5 3.50   39.0   29.9    72.0       18.0
## 5          3   96.0   59.0  26.5 2.80   29.4   25.0    58.0       14.9
## 6          2  132.0   66.0  31.0 3.45   37.0   28.7    67.0       17.0
##   SHOESIZE
## 1     11.5
## 2      9.0
## 3     10.0
## 4     11.5
## 5      8.5
## 6     11.5

OUTPUT FUNCTION

We were instructed to append/write to file, output also sent to terminal >> split=TRUE. The output was then directed to myfile.txt in specified directory, output was appended to existing file.

SELECTING VARIABLES

selvar1 <-c("WEIGHT","ARMSPAN","HEIGHT","WAIST","HOURSNET","GWA","AVESLEEP")
regvar1 <- survey[selvar1]
head(regvar1)
##   WEIGHT ARMSPAN HEIGHT WAIST HOURSNET  GWA AVESLEEP
## 1  155.0    71.0   71.0  30.5        5 1.20      4.0
## 2  155.0    68.0   64.0  34.0        4 1.75      6.0
## 3  113.2    59.5   61.5  26.0        5 1.60      6.0
## 4  184.0    72.0   72.0  32.5        4   NA      9.0
## 5   96.0    58.0   59.0  26.5       12 1.25      6.5
## 6  132.0    67.0   66.0  31.0       12 1.50      6.0

Fitting the Model-Linear Regression Example (WEIGHT~HEIGHT)

fit1 <-lm(WEIGHT~HEIGHT, data=regvar1)
summary(fit1)
## 
## Call:
## lm(formula = WEIGHT ~ HEIGHT, data = regvar1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -35.197 -14.172  -3.352  10.428 105.663 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -166.5091    38.7081  -4.302 4.55e-05 ***
## HEIGHT         4.7001     0.6088   7.721 2.19e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 21.45 on 84 degrees of freedom
## Multiple R-squared:  0.4151, Adjusted R-squared:  0.4081 
## F-statistic: 59.61 on 1 and 84 DF,  p-value: 2.193e-11
fit1glm <- glm(WEIGHT~HEIGHT, data=regvar1)
summary(fit1glm)
## 
## Call:
## glm(formula = WEIGHT ~ HEIGHT, data = regvar1)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -35.197  -14.172   -3.352   10.428  105.663  
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -166.5091    38.7081  -4.302 4.55e-05 ***
## HEIGHT         4.7001     0.6088   7.721 2.19e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 460.172)
## 
##     Null deviance: 66084  on 85  degrees of freedom
## Residual deviance: 38654  on 84  degrees of freedom
## AIC: 775.35
## 
## Number of Fisher Scoring iterations: 2

Fitting the Model-Linear Regression Example (AVEGRADE~NETHRS)

fit2 <-lm(GWA~HOURSNET, data=regvar1)
summary(fit2)
## 
## Call:
## lm(formula = GWA ~ HOURSNET, data = regvar1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -0.4501 -0.1920 -0.0429  0.1660  0.9861 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.586381   0.063192  25.104   <2e-16 ***
## HOURSNET    -0.007247   0.007327  -0.989    0.326    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.275 on 74 degrees of freedom
##   (10 observations deleted due to missingness)
## Multiple R-squared:  0.01305,    Adjusted R-squared:  -0.0002903 
## F-statistic: 0.9782 on 1 and 74 DF,  p-value: 0.3259
fit2glm <-glm(GWA~HOURSNET, data=regvar1)
summary(fit2glm)
## 
## Call:
## glm(formula = GWA ~ HOURSNET, data = regvar1)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -0.4501  -0.1920  -0.0429   0.1660   0.9861  
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  1.586381   0.063192  25.104   <2e-16 ***
## HOURSNET    -0.007247   0.007327  -0.989    0.326    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 0.0756073)
## 
##     Null deviance: 5.6689  on 75  degrees of freedom
## Residual deviance: 5.5949  on 74  degrees of freedom
##   (10 observations deleted due to missingness)
## AIC: 23.404
## 
## Number of Fisher Scoring iterations: 2

Fitting the Model-Linear Regression Example (WEIGHT~WAISTLINE)

fit3 <-lm(WEIGHT~WAIST, data=regvar1)
summary(fit3)
## 
## Call:
## lm(formula = WEIGHT ~ WAIST, data = regvar1)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -52.582  -8.497  -0.589   9.876  40.010 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -57.4206    14.8372   -3.87 0.000214 ***
## WAIST         6.1973     0.4825   12.84  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 16.29 on 84 degrees of freedom
## Multiple R-squared:  0.6626, Adjusted R-squared:  0.6586 
## F-statistic:   165 on 1 and 84 DF,  p-value: < 2.2e-16
fit3glm <-glm(WEIGHT~WAIST, data=regvar1)
summary(fit3glm)
## 
## Call:
## glm(formula = WEIGHT ~ WAIST, data = regvar1)
## 
## Deviance Residuals: 
##     Min       1Q   Median       3Q      Max  
## -52.582   -8.497   -0.589    9.876   40.010  
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -57.4206    14.8372   -3.87 0.000214 ***
## WAIST         6.1973     0.4825   12.84  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for gaussian family taken to be 265.4369)
## 
##     Null deviance: 66084  on 85  degrees of freedom
## Residual deviance: 22297  on 84  degrees of freedom
## AIC: 728.03
## 
## Number of Fisher Scoring iterations: 2

OTHER USEFUL FUNCTIONS

Model coefficients

coefficients(fit1)
## (Intercept)      HEIGHT 
## -166.509059    4.700091
coefficients(fit2)
##  (Intercept)     HOURSNET 
##  1.586380906 -0.007246565
coefficients(fit3)
## (Intercept)       WAIST 
##  -57.420615    6.197255

ANOVA Table

anova(fit1)
## Analysis of Variance Table
## 
## Response: WEIGHT
##           Df Sum Sq Mean Sq F value    Pr(>F)    
## HEIGHT     1  27429 27429.4  59.607 2.193e-11 ***
## Residuals 84  38654   460.2                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(fit2)
## Analysis of Variance Table
## 
## Response: GWA
##           Df Sum Sq  Mean Sq F value Pr(>F)
## HOURSNET   1 0.0740 0.073961  0.9782 0.3259
## Residuals 74 5.5949 0.075607
anova(fit3)
## Analysis of Variance Table
## 
## Response: WEIGHT
##           Df Sum Sq Mean Sq F value    Pr(>F)    
## WAIST      1  43787   43787  164.96 < 2.2e-16 ***
## Residuals 84  22297     265                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Cls for model parameters

confint(fit1, level=0.95)
##                   2.5 %     97.5 %
## (Intercept) -243.484440 -89.533679
## HEIGHT         3.489471   5.910712
confint(fit2, level=0.95)
##                   2.5 %     97.5 %
## (Intercept)  1.46046770 1.71229411
## HOURSNET    -0.02184544 0.00735231
confint(fit3, level=0.95)
##                 2.5 %     97.5 %
## (Intercept) -86.92606 -27.915173
## WAIST         5.23773   7.156781

Predicted Values

fitted(fit1)
##         1         2         3         4         5         6         7 
## 167.19743 134.29679 122.54656 171.89752 110.79634 143.69698 135.23681 
##         8         9        10        11        12        13        14 
## 129.59670 153.09716 162.96735 143.69698 148.39707 134.29679 138.05687 
##        15        16        17        18        19        20        21 
## 134.29679 110.79634 110.79634 134.29679 110.79634 134.29679 115.49643 
##        22        23        24        25        26        27        28 
## 138.99688 120.19652 109.38631 134.29679 110.79634 160.14730  68.49551 
##        29        30        31        32        33        34        35 
## 113.14638 110.79634 129.59670 106.09624 138.05687 124.89661 124.89661 
##        36        37        38        39        40        41        42 
## 146.04702 129.59670 120.19652 143.69698 134.29679 115.49643 134.29679 
##        43        44        45        46        47        48        49 
## 124.89661 138.99688 115.49643 115.49643 143.69698 143.69698 134.29679 
##        50        51        52        53        54        55        56 
## 136.64684 124.89661 115.49643 167.19743 162.49734 129.59670 153.09716 
##        57        58        59        60        61        62        63 
## 138.99688 142.75696 153.09716 115.49643 138.99688 129.59670 153.09716 
##        64        65        66        67        68        69        70 
## 138.99688 153.09716 106.09624 121.13654 114.55641 115.49643 148.39707 
##        71        72        73        74        75        76        77 
##  91.99597 120.19652 143.69698 110.79634 148.39707 115.49643 134.29679 
##        78        79        80        81        82        83        84 
## 153.09716 153.09716 138.99688 115.49643 115.49643 143.69698 143.69698 
##        85        86 
## 134.29679 136.64684
fitted(fit2)
##        1        2        3        5        6        7        8        9 
## 1.550148 1.557395 1.550148 1.499422 1.499422 1.499422 1.528408 1.528408 
##       10       11       12       15       17       18       19       20 
## 1.477682 1.455943 1.550148 1.499422 1.528408 1.528408 1.528408 1.550148 
##       21       22       23       24       25       26       27       28 
## 1.542902 1.542902 1.579134 1.499422 1.550148 1.557395 1.557395 1.470436 
##       29       30       31       32       33       34       35       36 
## 1.564641 1.513915 1.557395 1.557395 1.528408 1.553771 1.542902 1.513915 
##       37       38       39       40       41       42       43       44 
## 1.528408 1.477682 1.557395 1.550148 1.564641 1.542902 1.550148 1.542902 
##       45       46       47       48       49       50       51       52 
## 1.426956 1.571888 1.542902 1.571888 1.564641 1.499422 1.542902 1.557395 
##       53       54       55       56       57       59       61       62 
## 1.553771 1.513915 1.499422 1.571888 1.528408 1.528408 1.528408 1.528408 
##       63       64       65       68       70       71       72       73 
## 1.542902 1.557395 1.499422 1.528408 1.528408 1.542902 1.550148 1.521162 
##       74       75       76       78       79       80       81       82 
## 1.542902 1.528408 1.550148 1.513915 1.513915 1.542902 1.426956 1.571888 
##       83       84       85       86 
## 1.542902 1.571888 1.564641 1.499422
fitted(fit3)
##         1         2         3         4         5         6         7 
## 131.59567 153.28607 103.70802 143.99018 106.80665 134.69430 209.06137 
##         8         9        10        11        12        13        14 
## 140.89156 153.28607 165.68058 128.49705 147.08881 116.10254 109.90528 
##        15        16        17        18        19        20        21 
## 122.29979 109.90528 116.10254 128.49705  93.79242 140.89156  91.31351 
##        22        23        24        25        26        27        28 
## 116.10254  97.51077 122.29979 162.58195 190.46960 140.89156 128.49705 
##        29        30        31        32        33        34        35 
##  97.51077 109.90528 131.59567 103.70802 122.29979 103.70802 116.10254 
##        36        37        38        39        40        41        42 
## 165.68058 153.28607 116.10254 153.28607 159.48332 128.49705 140.89156 
##        43        44        45        46        47        48        49 
## 109.90528 159.48332 128.49705 140.89156 147.08881 128.49705 128.49705 
##        50        51        52        53        54        55        56 
## 140.89156 122.29979 103.70802 184.27234 147.08881 140.89156 134.69430 
##        57        58        59        60        61        62        63 
## 128.49705 134.69430 159.48332 109.90528 128.49705  91.31351 134.69430 
##        64        65        66        67        68        69        70 
## 128.49705 140.89156 109.90528 103.70802 122.29979 109.90528 140.89156 
##        71        72        73        74        75        76        77 
## 116.10254 103.70802 128.49705 159.48332 128.49705 140.89156  97.51077 
##        78        79        80        81        82        83        84 
## 159.48332 159.48332 159.48332 128.49705 140.89156 147.08881 128.49705 
##        85        86 
## 128.49705 140.89156

Residuals

Residual is the difference between a subject’s predicted score and his/her actual score.

residuals(fit1)
##           1           2           3           4           5           6 
## -12.1974327  20.7032073  -9.3465641  12.1024758 -14.7963355 -11.6969755 
##           7           8           9          10          11          12 
## 105.6631890  -5.5967012 -12.0971584  34.0326496  -0.6969755  16.6029330 
##          13          14          15          16          17          18 
##  -1.9967927  -3.5568658  -1.9967927 -18.1963355 -15.9963355 -12.9967927 
##          19          20          21          22          23          24 
## -13.7963355  25.7032073 -25.4964269   2.0031159 -35.1965184 -17.3863080 
##          25          26          27          28          29          30 
## -24.2967927  54.2036645  -3.1472956  54.7044875 -17.6463812 -31.3963355 
##          31          32          33          34          35          36 
## -15.1967012  -9.0962440 -16.7568658 -34.4966098 -23.4966098  18.9529787 
##          37          38          39          40          41          42 
##  30.4032988  -5.1965184  10.6030245  -2.2967927   5.5035731  -6.3967927 
##          43          44          45          46          47          48 
## -21.8966098   3.0031159  12.5035731  30.5035731 -10.6969755 -22.3969755 
##          49          50          51          52          53          54 
## -14.2967927   8.3531616 -10.2966098 -14.4964269  27.8025673   2.5026587 
##          55          56          57          58          59          60 
##  24.4032988   0.9028416  -3.9968841   2.4430427  12.3028416  -6.3964269 
##          61          62          63          64          65          66 
##  -0.9968841 -10.4967012  -6.0971584 -17.9968841   8.9028416  -3.5962440 
##          67          68          69          70          71          72 
## -11.1365366  -0.5564086  -5.4964269   0.6029330  20.0040303  -0.1965184 
##          73          74          75          76          77          78 
##   6.3030245  11.2036645 -16.3970670  16.5035731 -28.2967927   9.9028416 
##          79          80          81          82          83          84 
##  11.9028416   3.0031159  12.5035731  30.5035731 -10.6969755 -22.3969755 
##          85          86 
## -14.2967927   8.3531616
residuals(fit2)
##             1             2             3             5             6 
## -0.3501480816  0.1926053535  0.0498519184 -0.2494221273  0.0005778727 
##             7             8             9            10            11 
##  0.0005778727  0.2215916131  0.2215916131 -0.2276824326 -0.2059427379 
##            12            15            17            18            19 
## -0.4501480816  0.5005778727  0.4715916131  0.4715916131 -0.2784083869 
##            20            21            22            23            24 
##  0.0123519184 -0.2929015167  0.1570984833  0.1208656588  0.0005778727 
##            25            26            27            28            29 
##  0.4498519184 -0.0573946465 -0.3073946465  0.2795641323  0.6853587886 
##            30            31            32            33            34 
##  0.9860847429  0.1926053535 -0.2573946465 -0.3984083869  0.0462286360 
##            35            36            37            38            39 
## -0.0429015167 -0.1639152571 -0.0284083869  0.2723175674 -0.1873946465 
##            40            41            42            43            44 
## -0.2501480816 -0.1346412114 -0.0429015167 -0.0501480816 -0.0429015167 
##            45            46            47            48            49 
## -0.1769564783 -0.0718877763 -0.2929015167 -0.3218877763 -0.0646412114 
##            50            51            52            53            54 
##  0.0005778727  0.3434984833 -0.3073946465  0.1962286360 -0.2639152571 
##            55            56            57            59            61 
##  0.2505778727  0.4281122237 -0.2784083869 -0.1784083869 -0.2784083869 
##            62            63            64            65            68 
## -0.0284083869  0.4570984833 -0.0873946465  0.0005778727  0.1215916131 
##            70            71            72            73            74 
## -0.1284083869  0.1070984833  0.4498519184 -0.1211618220 -0.1429015167 
##            75            76            78            79            80 
## -0.0284083869  0.1998519184 -0.1139152571 -0.0139152571 -0.0429015167 
##            81            82            83            84            85 
## -0.1769564783 -0.0718877763 -0.2929015167 -0.3218877763 -0.0646412114 
##            86 
##  0.0005778727
residuals(fit3)
##            1            2            3            4            5 
##  23.40432605   1.71393226   9.49197522  40.00981531 -10.80665247 
##            6            7            8            9           10 
##  -2.69430163  31.83863393 -16.89155700 -12.28606774  31.31942152 
##           11           12           13           14           15 
##  14.50295374  17.91118763  16.19746448  24.59471985  10.00020911 
##           16           17           18           19           20 
## -17.30528015 -21.30253552  -7.19704626   3.20758381  19.10844300 
##           21           22           23           24           25 
##  -1.31351404  24.89746448 -12.51076941 -30.29979089 -52.58195080 
##           26           27           28           29           30 
## -25.46959996  16.10844300  -5.29704626  -2.01076941 -30.50528015 
##           31           32           33           34           35 
## -17.19567395  -6.70802478  -0.99979089 -13.30802478 -14.70253552 
##           36           37           38           39           40 
##  -0.68057848   6.71393226  -1.10253552   1.01393226 -27.48332311 
##           41           42           43           44           45 
##  -7.49704626 -12.99155700  -6.90528015 -17.48332311  -0.49704626 
##           46           47           48           49           50 
##   5.10844300 -14.08881237  -7.19704626  -8.49704626   4.10844300 
##           51           52           53           54           55 
##  -7.69979089  -2.70802478  10.72765541  17.91118763  13.10844300 
##           56           57           58           59           60 
##  19.30569837   6.50295374  10.50569837   5.91667689  -0.80528015 
##           61           62           63           64           65 
##   9.50295374  27.78648596  12.30569837  -7.49704626  21.10844300 
##           66           67           68           69           70 
##  -7.40528015   6.29197522  -8.29979089   0.09471985   8.10844300 
##           71           72           73           74           75 
##  -4.10253552  16.29197522  21.50295374 -37.48332311   3.50295374 
##           76           77           78           79           80 
##  -8.89155700   8.48923059   3.51667689   5.51667689 -17.48332311 
##           81           82           83           84           85 
##  -0.49704626   5.10844300 -14.08881237  -7.19704626  -8.49704626 
##           86 
##   4.10844300

Covariance matrix for model parameters

vcov(fit1)
##             (Intercept)      HEIGHT
## (Intercept)  1498.32006 -23.5225255
## HEIGHT        -23.52253   0.3706099
vcov(fit2)
##               (Intercept)      HOURSNET
## (Intercept)  0.0039932540 -4.011972e-04
## HOURSNET    -0.0004011972  5.368131e-05
vcov(fit3)
##             (Intercept)      WAIST
## (Intercept)  220.143145 -7.1087527
## WAIST         -7.108753  0.2328165

Regression diagnostics

influence(fit1)
## $hat
##          1          2          3          4          5          6 
## 0.05729608 0.01185433 0.01475274 0.07023073 0.02771830 0.01678396 
##          7          8          9         10         11         12 
## 0.01205736 0.01180564 0.02815657 0.04703207 0.01678396 0.02166490 
##         13         14         15         16         17         18 
## 0.01185433 0.01305303 0.01185433 0.02771830 0.02771830 0.01185433 
##         19         20         21         22         23         24 
## 0.02771830 0.01185433 0.02132402 0.01351378 0.01654048 0.02995068 
##         25         26         27         28         29         30 
## 0.01185433 0.02771830 0.04091424 0.15775038 0.02431982 0.02771830 
##         31         32         33         34         35         36 
## 0.01180564 0.03572333 0.01305303 0.01336769 0.01336769 0.01902309 
##         37         38         39         40         41         42 
## 0.01180564 0.01654048 0.01678396 0.01185433 0.02132402 0.01185433 
##         43         44         45         46         47         48 
## 0.01336769 0.01351378 0.02132402 0.02132402 0.01678396 0.01678396 
##         49         50         51         52         53         54 
## 0.01185433 0.01248271 0.01336769 0.02132402 0.05729608 0.04597216 
##         55         56         57         58         59         60 
## 0.01180564 0.02815657 0.01351378 0.01600107 0.02815657 0.02132402 
##         61         62         63         64         65         66 
## 0.01351378 0.01180564 0.02815657 0.01351378 0.02815657 0.03572333 
##         67         68         69         70         71         72 
## 0.01577706 0.02247401 0.02132402 0.02166490 0.06940289 0.01654048 
##         73         74         75         76         77         78 
## 0.01678396 0.02771830 0.02166490 0.02132402 0.01185433 0.02815657 
##         79         80         81         82         83         84 
## 0.02815657 0.01351378 0.02132402 0.02132402 0.01678396 0.01678396 
##         85         86 
## 0.01185433 0.01248271 
## 
## $coefficients
##     (Intercept)        HEIGHT
## 1    4.82996072 -0.0784690378
## 2   -0.32424424  0.0089470502
## 3   -1.06548880  0.0150493772
## 4   -5.52439863  0.0894245432
## 5   -3.65400354  0.0547827472
## 6    1.40034861 -0.0242427504
## 7   -2.74860572  0.0628999064
## 8   -0.20185460  0.0021427400
## 9    2.73777310 -0.0454155298
## 10 -11.68821294  0.1906966482
## 11   0.08344112 -0.0014445276
## 12  -2.86508372  0.0482499998
## 13   0.03127286 -0.0008629293
## 14   0.20314988 -0.0038609845
## 15   0.03127286 -0.0008629293
## 16  -4.49364468  0.0673710899
## 17  -3.95034747  0.0592256917
## 18   0.20354987 -0.0056166639
## 19  -3.40705026  0.0510802935
## 20  -0.40255197  0.0111078386
## 21  -4.92359481  0.0728010396
## 22  -0.13522023  0.0025024725
## 23  -4.93431964  0.0711862472
## 24  -4.57833843  0.0688505765
## 25   0.38052534 -0.0105000457
## 26  13.38577260 -0.2006865590
## 27   0.97337027 -0.0159371614
## 28  45.47566623 -0.7045941761
## 29  -3.88039719  0.0578242567
## 30  -7.75342795  0.1162434789
## 31  -0.54809501  0.0058181738
## 32  -2.74719216  0.0415552718
## 33   0.95706600 -0.0181896092
## 34  -3.03339697  0.0413872457
## 35  -2.06613187  0.0281900154
## 36  -2.76800973  0.0471510611
## 37   1.09654695 -0.0116401364
## 38  -0.72851759  0.0105101487
## 39  -1.26938203  0.0219754649
## 40   0.03597132 -0.0009925766
## 41   1.06279064 -0.0157145879
## 42   0.10018366 -0.0027644231
## 43  -1.92543877  0.0262704183
## 44  -0.20272517  0.0037517624
## 45   2.41455510 -0.0357019876
## 46   5.89052084 -0.0870981584
## 47   1.28062975 -0.0221701847
## 48   2.68134044 -0.0464192035
## 49   0.22390988 -0.0061784689
## 50  -0.34709882  0.0070184025
## 51  -0.90541375  0.0123533391
## 52  -2.79939352  0.0413922685
## 53 -11.00930915  0.1788606462
## 54  -0.84515188  0.0137964087
## 55   0.88014669 -0.0093429904
## 56  -0.20432694  0.0033894760
## 57   0.26980944 -0.0049932670
## 58  -0.26686334  0.0046594271
## 59  -2.78432236  0.0461877119
## 60  -1.23520894  0.0182639917
## 61   0.06729461 -0.0012453973
## 62  -0.37858148  0.0040187427
## 63   1.37988077 -0.0228901425
## 64   1.21487865 -0.0224833259
## 65  -2.01485004  0.0334233258
## 66  -1.08611570  0.0164290775
## 67  -1.44438005  0.0206840153
## 68  -0.11339318  0.0016822902
## 69  -1.06141065  0.0156941831
## 70  -0.10404508  0.0017521915
## 71   9.55655173 -0.1466304302
## 72  -0.02755058  0.0003974656
## 73  -0.75459092  0.0130634323
## 74   2.76678167 -0.0414810493
## 75   2.82955846 -0.0476517299
## 76   3.18699193 -0.0471233589
## 77   0.44317153 -0.0122286765
## 78  -2.24116543  0.0371775570
## 79  -2.69379621  0.0446860195
## 80  -0.20272517  0.0037517624
## 81   2.41455510 -0.0357019876
## 82   5.89052084 -0.0870981584
## 83   1.28062975 -0.0221701847
## 84   2.68134044 -0.0464192035
## 85   0.22390988 -0.0061784689
## 86  -0.34709882  0.0070184025
## 
## $sigma
##        1        2        3        4        5        6        7        8 
## 21.53636 21.45904 21.55570 21.53644 21.51751 21.54158 18.15379 21.57161 
##        9       10       11       12       13       14       15       16 
## 21.53839 21.23848 21.58032 21.50166 21.57933 21.57688 21.57933 21.48519 
##       17       18       19       20       21       22       23       24 
## 21.50687 21.53269 21.52574 21.39301 21.39424 21.57933 21.22593 21.49330 
##       25       26       27       28       29       30       31       32 
## 21.41304 20.71978 21.57758 20.56473 21.49118 21.29557 21.51513 21.55649 
##       33       34       35       36       37       38       39       40 
## 21.50090 21.24110 21.42369 21.47800 21.31775 21.57279 21.54852 21.57897 
##       41       42       43       44       45       46       47       48 
## 21.57182 21.56890 21.44438 21.57791 21.53582 21.31341 21.54795 21.43757 
##       49       50       51       52       53       54       55       56 
## 21.52264 21.56073 21.55044 21.52044 21.35034 21.57863 21.41158 21.58023 
##       57       58       59       60       61       62       63       64 
## 21.57594 21.57877 21.53694 21.56879 21.58018 21.54931 21.56978 21.48861 
##       65       66       67       68       69       70       71       72 
## 21.55768 21.57672 21.54526 21.58037 21.57184 21.58036 21.46009 21.58045 
##       73       74       75       76       77       78       79       80 
## 21.56918 21.54439 21.50361 21.50263 21.35307 21.55227 21.53973 21.57791 
##       81       82       83       84       85       86 
## 21.53582 21.31341 21.54795 21.43757 21.52264 21.56073 
## 
## $wt.res
##           1           2           3           4           5           6 
## -12.1974327  20.7032073  -9.3465641  12.1024758 -14.7963355 -11.6969755 
##           7           8           9          10          11          12 
## 105.6631890  -5.5967012 -12.0971584  34.0326496  -0.6969755  16.6029330 
##          13          14          15          16          17          18 
##  -1.9967927  -3.5568658  -1.9967927 -18.1963355 -15.9963355 -12.9967927 
##          19          20          21          22          23          24 
## -13.7963355  25.7032073 -25.4964269   2.0031159 -35.1965184 -17.3863080 
##          25          26          27          28          29          30 
## -24.2967927  54.2036645  -3.1472956  54.7044875 -17.6463812 -31.3963355 
##          31          32          33          34          35          36 
## -15.1967012  -9.0962440 -16.7568658 -34.4966098 -23.4966098  18.9529787 
##          37          38          39          40          41          42 
##  30.4032988  -5.1965184  10.6030245  -2.2967927   5.5035731  -6.3967927 
##          43          44          45          46          47          48 
## -21.8966098   3.0031159  12.5035731  30.5035731 -10.6969755 -22.3969755 
##          49          50          51          52          53          54 
## -14.2967927   8.3531616 -10.2966098 -14.4964269  27.8025673   2.5026587 
##          55          56          57          58          59          60 
##  24.4032988   0.9028416  -3.9968841   2.4430427  12.3028416  -6.3964269 
##          61          62          63          64          65          66 
##  -0.9968841 -10.4967012  -6.0971584 -17.9968841   8.9028416  -3.5962440 
##          67          68          69          70          71          72 
## -11.1365366  -0.5564086  -5.4964269   0.6029330  20.0040303  -0.1965184 
##          73          74          75          76          77          78 
##   6.3030245  11.2036645 -16.3970670  16.5035731 -28.2967927   9.9028416 
##          79          80          81          82          83          84 
##  11.9028416   3.0031159  12.5035731  30.5035731 -10.6969755 -22.3969755 
##          85          86 
## -14.2967927   8.3531616
influence(fit2)
## $hat
##          1          2          3          5          6          7 
## 0.01750248 0.02172512 0.01750248 0.02770408 0.02770408 0.02770408 
##          8          9         10         11         12         15 
## 0.01335457 0.01335457 0.05337624 0.09182844 0.01750248 0.02770408 
##         17         18         19         20         21         22 
## 0.01335457 0.01335457 0.01335457 0.01750248 0.01469984 0.01469984 
##         23         24         25         26         27         28 
## 0.04291306 0.02770408 0.01750248 0.02172512 0.02172512 0.06477364 
##         29         30         31         32         33         34 
## 0.02736776 0.01768932 0.02172512 0.02172512 0.01335457 0.01943630 
##         35         36         37         38         39         40 
## 0.01469984 0.01768932 0.01335457 0.05337624 0.02172512 0.01750248 
##         41         42         43         44         45         46 
## 0.02736776 0.01469984 0.01750248 0.01469984 0.16297808 0.03443041 
##         47         48         49         50         51         52 
## 0.01469984 0.03443041 0.02736776 0.02770408 0.01469984 0.02172512 
##         53         54         55         56         57         59 
## 0.01943630 0.01768932 0.02770408 0.03443041 0.01335457 0.01335457 
##         61         62         63         64         65         68 
## 0.01335457 0.01335457 0.01469984 0.02172512 0.02770408 0.01335457 
##         70         71         72         73         74         75 
## 0.01335457 0.01469984 0.01750248 0.01481194 0.01469984 0.01335457 
##         76         78         79         80         81         82 
## 0.01750248 0.01768932 0.01768932 0.01469984 0.16297808 0.03443041 
##         83         84         85         86 
## 0.01469984 0.03443041 0.02736776 0.02770408 
## 
## $coefficients
##      (Intercept)      HOURSNET
## 1  -9.367269e-03  6.259273e-04
## 2   6.219602e-03 -4.855759e-04
## 3   1.333654e-03 -8.911566e-05
## 5   2.785962e-03 -8.244052e-04
## 6  -6.454647e-06  1.910020e-06
## 7  -6.454647e-06  1.910020e-06
## 8   2.327905e-03  8.392628e-05
## 9   2.327905e-03  8.392628e-05
## 10  6.440949e-03 -1.285269e-03
## 11  9.682513e-03 -1.694784e-03
## 12 -1.204250e-02  8.046881e-04
## 15 -5.591289e-03  1.654541e-03
## 17  4.954252e-03  1.786120e-04
## 18  4.954252e-03  1.786120e-04
## 19 -2.924787e-03 -1.054452e-04
## 20  3.304423e-04 -2.208038e-05
## 21 -6.236083e-03  3.110405e-04
## 22  3.344739e-03 -1.668273e-04
## 23  5.999720e-03 -5.804468e-04
## 24 -6.454647e-06  1.910020e-06
## 25  1.203458e-02 -8.041587e-04
## 26 -1.853385e-03  1.446972e-04
## 27 -9.926373e-03  7.749704e-04
## 28 -9.591224e-03  1.809612e-03
## 29  2.599904e-02 -2.238175e-03
## 30 -2.485175e-04  1.800580e-03
## 31  6.219602e-03 -4.855759e-04
## 32 -8.311775e-03  6.489158e-04
## 33 -4.185434e-03 -1.508944e-04
## 34  1.364245e-03 -9.953813e-05
## 35 -9.134041e-04  4.555834e-05
## 36  4.131066e-05 -2.993074e-04
## 37 -2.984410e-04 -1.075948e-05
## 38 -7.703640e-03  1.537234e-03
## 39 -6.051339e-03  4.724393e-04
## 40 -6.692038e-03  4.471666e-04
## 41 -5.107604e-03  4.396976e-04
## 42 -9.134041e-04  4.555834e-05
## 43 -1.341577e-03  8.964509e-05
## 44 -9.134041e-04  4.555834e-05
## 45  1.351420e-02 -2.180442e-03
## 46 -3.142067e-03  2.893414e-04
## 47 -6.236083e-03  3.110405e-04
## 48 -1.406905e-02  1.295567e-03
## 49 -2.452160e-03  2.110987e-04
## 50 -6.454647e-06  1.910020e-06
## 51  7.313329e-03 -3.647708e-04
## 52 -9.926373e-03  7.749704e-04
## 53  5.790868e-03 -4.225137e-04
## 54  6.651312e-05 -4.819063e-04
## 55 -2.798872e-03  8.282253e-04
## 56  1.871190e-02 -1.723111e-03
## 57 -2.924787e-03 -1.054452e-04
## 59 -1.874249e-03 -6.757094e-05
## 61 -2.924787e-03 -1.054452e-04
## 62 -2.984410e-04 -1.075948e-05
## 63  9.731955e-03 -4.854059e-04
## 64 -2.822144e-03  2.203300e-04
## 65 -6.454647e-06  1.910020e-06
## 68  1.277367e-03  4.605198e-05
## 70 -1.348980e-03 -4.863378e-05
## 71  2.280204e-03 -1.137309e-04
## 72  1.203458e-02 -8.041587e-04
## 73 -6.221440e-04 -1.332755e-04
## 74 -3.042476e-03  1.517512e-04
## 75 -2.984410e-04 -1.075948e-05
## 76  5.346500e-03 -3.572568e-04
## 78  2.870944e-05 -2.080080e-04
## 79  3.506986e-06 -2.540911e-05
## 80 -9.134041e-04  4.555834e-05
## 81  1.351420e-02 -2.180442e-03
## 82 -3.142067e-03  2.893414e-04
## 83 -6.236083e-03  3.110405e-04
## 84 -1.406905e-02  1.295567e-03
## 85 -2.452160e-03  2.110987e-04
## 86 -6.454647e-06  1.910020e-06
## 
## $sigma
##         1         2         3         5         6         7         8 
## 0.2737400 0.2759050 0.2767822 0.2752572 0.2768447 0.2768447 0.2756107 
##         9        10        11        12        15        17        18 
## 0.2756107 0.2754866 0.2756869 0.2716943 0.2703935 0.2712107 0.2712107 
##        19        20        21        22        23        24        25 
## 0.2748943 0.2768409 0.2746821 0.2762244 0.2764669 0.2768447 0.2717011 
##        26        27        28        29        30        31        32 
## 0.2767614 0.2744447 0.2747694 0.2646271 0.2511635 0.2759050 0.2751641 
##        33        34        35        36        37        38        39 
## 0.2728355 0.2767908 0.2767985 0.2761672 0.2768245 0.2748998 0.2759552 
##        40        41        42        43        44        45        46 
## 0.2752645 0.2763832 0.2767985 0.2767814 0.2767985 0.2759176 0.2767123 
##        47        48        49        50        51        52        53 
## 0.2746821 0.2741771 0.2767385 0.2768447 0.2738660 0.2744447 0.2758715 
##        54        55        56        57        59        61        62 
## 0.2750849 0.2752424 0.2721081 0.2748943 0.2760455 0.2748943 0.2768245 
##        63        64        65        68        70        71        72 
## 0.2715477 0.2766515 0.2768447 0.2764738 0.2764310 0.2765566 0.2717011 
##        73        74        75        76        78        79        80 
## 0.2764759 0.2763315 0.2768245 0.2758372 0.2765177 0.2768399 0.2767985 
##        81        82        83        84        85        86 
## 0.2759176 0.2767123 0.2746821 0.2741771 0.2767385 0.2768447 
## 
## $wt.res
##             1             2             3             5             6 
## -0.3501480816  0.1926053535  0.0498519184 -0.2494221273  0.0005778727 
##             7             8             9            10            11 
##  0.0005778727  0.2215916131  0.2215916131 -0.2276824326 -0.2059427379 
##            12            15            17            18            19 
## -0.4501480816  0.5005778727  0.4715916131  0.4715916131 -0.2784083869 
##            20            21            22            23            24 
##  0.0123519184 -0.2929015167  0.1570984833  0.1208656588  0.0005778727 
##            25            26            27            28            29 
##  0.4498519184 -0.0573946465 -0.3073946465  0.2795641323  0.6853587886 
##            30            31            32            33            34 
##  0.9860847429  0.1926053535 -0.2573946465 -0.3984083869  0.0462286360 
##            35            36            37            38            39 
## -0.0429015167 -0.1639152571 -0.0284083869  0.2723175674 -0.1873946465 
##            40            41            42            43            44 
## -0.2501480816 -0.1346412114 -0.0429015167 -0.0501480816 -0.0429015167 
##            45            46            47            48            49 
## -0.1769564783 -0.0718877763 -0.2929015167 -0.3218877763 -0.0646412114 
##            50            51            52            53            54 
##  0.0005778727  0.3434984833 -0.3073946465  0.1962286360 -0.2639152571 
##            55            56            57            59            61 
##  0.2505778727  0.4281122237 -0.2784083869 -0.1784083869 -0.2784083869 
##            62            63            64            65            68 
## -0.0284083869  0.4570984833 -0.0873946465  0.0005778727  0.1215916131 
##            70            71            72            73            74 
## -0.1284083869  0.1070984833  0.4498519184 -0.1211618220 -0.1429015167 
##            75            76            78            79            80 
## -0.0284083869  0.1998519184 -0.1139152571 -0.0139152571 -0.0429015167 
##            81            82            83            84            85 
## -0.1769564783 -0.0718877763 -0.2929015167 -0.3218877763 -0.0646412114 
##            86 
##  0.0005778727
influence(fit3)
## $hat
##          1          2          3          4          5          6 
## 0.01162890 0.02216642 0.02965651 0.01501902 0.02589923 0.01181860 
##          7          8          9         10         11         12 
## 0.14793740 0.01351366 0.02216642 0.03783604 0.01187776 0.01696294 
##         13         14         15         16         17         18 
## 0.01725871 0.02258050 0.01369112 0.02258050 0.01725871 0.01187776 
##         19         20         21         22         23         24 
## 0.04462688 0.01351366 0.04907116 0.01725871 0.03848673 0.01369112 
##         25         26         27         28         29         30 
## 0.03326080 0.09022582 0.01351366 0.01187776 0.03848673 0.02258050 
##         31         32         33         34         35         36 
## 0.01162890 0.02965651 0.01369112 0.02965651 0.01725871 0.03783604 
##         37         38         39         40         41         42 
## 0.02216642 0.01725871 0.02216642 0.02912412 0.01187776 0.01351366 
##         43         44         45         46         47         48 
## 0.02258050 0.02912412 0.01187776 0.01351366 0.01696294 0.01187776 
##         49         50         51         52         53         54 
## 0.01187776 0.01351366 0.01369112 0.02965651 0.07449705 0.01696294 
##         55         56         57         58         59         60 
## 0.01351366 0.01181860 0.01187776 0.01181860 0.02912412 0.02258050 
##         61         62         63         64         65         66 
## 0.01187776 0.04907116 0.01181860 0.01187776 0.01351366 0.02258050 
##         67         68         69         70         71         72 
## 0.02965651 0.01369112 0.02258050 0.01351366 0.01725871 0.02965651 
##         73         74         75         76         77         78 
## 0.01187776 0.02912412 0.01187776 0.01351366 0.03848673 0.02912412 
##         79         80         81         82         83         84 
## 0.02912412 0.02912412 0.01187776 0.01351366 0.01696294 0.01187776 
##         85         86 
## 0.01187776 0.01351366 
## 
## $coefficients
##      (Intercept)         WAIST
## 1    0.296730218 -0.0007003708
## 2   -0.142332568  0.0053289867
## 3    1.301475881 -0.0388989864
## 4   -1.666701406  0.0700545365
## 5   -1.327464536  0.0392505321
## 6    0.002343903 -0.0011150847
## 7  -12.040831256  0.4085753574
## 8    0.473295417 -0.0220215380
## 9    1.020289787 -0.0382000462
## 10  -4.386781437  0.1560661970
## 11   0.380459690 -0.0068708810
## 12  -0.991588746  0.0394138729
## 13   1.310054331 -0.0366284898
## 14   2.673953140 -0.0779911874
## 15   0.534356896 -0.0136393881
## 16  -1.881440751  0.0548759797
## 17  -1.722953550  0.0481729536
## 18  -0.188801953  0.0034096536
## 19   0.590559550 -0.0180626477
## 20  -0.535411774  0.0249116943
## 21  -0.257763119  0.0079158888
## 22   2.013712160 -0.0563024247
## 23  -2.079612631  0.0631536408
## 24  -1.619056365  0.0413261967
## 25   6.601747885 -0.2369250004
## 26   6.771881715 -0.2324450078
## 27  -0.451352842  0.0210005916
## 28  -0.138958768  0.0025095146
## 29  -0.334241750  0.0101502477
## 30  -3.316552908  0.0967338940
## 31  -0.218014228  0.0005145779
## 32  -0.919759298  0.0274901017
## 33  -0.053423399  0.0013636251
## 34  -1.824706963  0.0545375080
## 35  -1.189144163  0.0332478996
## 36   0.095325805 -0.0033913556
## 37  -0.557554838  0.0208750698
## 38  -0.089173305  0.0024932428
## 39  -0.084201451  0.0031525350
## 40   3.056813241 -0.1108929131
## 41  -0.196671929  0.0035517808
## 42   0.364018805 -0.0169371045
## 43  -0.750746325  0.0218970170
## 44   1.944570290 -0.0705437484
## 45  -0.013039142  0.0002354793
## 46  -0.143136755  0.0066598817
## 47   0.779976632 -0.0310026712
## 48  -0.188801953  0.0034096536
## 49  -0.222905185  0.0040255381
## 50  -0.115117111  0.0053561808
## 51  -0.411435032  0.0105018240
## 52  -0.371306167  0.0110977343
## 53  -2.493378570  0.0860740013
## 54  -0.991588746  0.0394138729
## 55  -0.367293909  0.0170894889
## 56  -0.016794955  0.0079900072
## 57   0.170593646 -0.0030808221
## 58  -0.009139412  0.0043479704
## 59  -0.658078216  0.0238732970
## 60  -0.087550556  0.0025535869
## 61   0.249293413 -0.0045020942
## 62   5.452801463 -0.1674551821
## 63  -0.010705319  0.0050929325
## 64  -0.196671929  0.0035517808
## 65  -0.591451063  0.0275190961
## 66  -0.805106634  0.0234825441
## 67   0.862713377 -0.0257850924
## 68  -0.443495776  0.0113201702
## 69   0.010298000 -0.0003003618
## 70  -0.227195688  0.0105709844
## 71  -0.331813935  0.0092773582
## 72   2.233846203 -0.0667660110
## 73   0.564092478 -0.0101871824
## 74   4.169056192 -0.1512420778
## 75   0.091893880 -0.0016595501
## 76   0.249138264 -0.0115919308
## 77   1.411129131 -0.0428531453
## 78  -0.391139908  0.0141894975
## 79  -0.613588498  0.0222593304
## 80   1.944570290 -0.0705437484
## 81  -0.013039142  0.0002354793
## 82  -0.143136755  0.0066598817
## 83   0.779976632 -0.0310026712
## 84  -0.188801953  0.0034096536
## 85  -0.222905185  0.0040255381
## 86  -0.115117111  0.0053561808
## 
## $sigma
##        1        2        3        4        5        6        7        8 
## 16.18511 16.38898 16.35592 15.78145 16.34596 16.38739 15.94682 16.28343 
##        9       10       11       12       13       14       15       16 
## 16.33325 16.01100 16.31166 16.26970 16.29167 16.16102 16.35278 16.27708 
##       17       18       19       20       21       22       23       24 
## 16.21948 16.37081 16.38613 16.25348 16.38942 16.15659 16.33015 16.04432 
##       25       26       27       28       29       30       31       32 
## 15.30285 16.12588 16.29312 16.37965 16.38854 16.03634 16.27976 16.37303 
##       33       34       35       36       37       38       39       40 
## 16.38971 16.32287 16.30904 16.38991 16.37313 16.38963 16.38970 16.10160 
##       41       42       43       44       45       46       47       48 
## 16.36917 16.32708 16.37215 16.27396 16.38999 16.38036 16.31570 16.37081 
##       49       50       51       52       53       54       55       56 
## 16.36321 16.38380 16.36798 16.38731 16.34432 16.26970 16.32594 16.25087 
##       57       58       59       60       61       62       63       64 
## 16.37435 16.34898 16.37683 16.38984 16.35646 16.08890 16.33367 16.36917 
##       65       66       67       68       69       70       71       72 
## 16.22323 16.36945 16.37508 16.36440 16.39008 16.36557 16.38379 16.28924 
##       73       74       75       76       77       78       79       80 
## 16.21719 15.84927 16.38552 16.36060 16.36251 16.38540 16.37856 16.27396 
##       81       82       83       84       85       86 
## 16.38999 16.38036 16.31570 16.37081 16.36321 16.38380 
## 
## $wt.res
##            1            2            3            4            5 
##  23.40432605   1.71393226   9.49197522  40.00981531 -10.80665247 
##            6            7            8            9           10 
##  -2.69430163  31.83863393 -16.89155700 -12.28606774  31.31942152 
##           11           12           13           14           15 
##  14.50295374  17.91118763  16.19746448  24.59471985  10.00020911 
##           16           17           18           19           20 
## -17.30528015 -21.30253552  -7.19704626   3.20758381  19.10844300 
##           21           22           23           24           25 
##  -1.31351404  24.89746448 -12.51076941 -30.29979089 -52.58195080 
##           26           27           28           29           30 
## -25.46959996  16.10844300  -5.29704626  -2.01076941 -30.50528015 
##           31           32           33           34           35 
## -17.19567395  -6.70802478  -0.99979089 -13.30802478 -14.70253552 
##           36           37           38           39           40 
##  -0.68057848   6.71393226  -1.10253552   1.01393226 -27.48332311 
##           41           42           43           44           45 
##  -7.49704626 -12.99155700  -6.90528015 -17.48332311  -0.49704626 
##           46           47           48           49           50 
##   5.10844300 -14.08881237  -7.19704626  -8.49704626   4.10844300 
##           51           52           53           54           55 
##  -7.69979089  -2.70802478  10.72765541  17.91118763  13.10844300 
##           56           57           58           59           60 
##  19.30569837   6.50295374  10.50569837   5.91667689  -0.80528015 
##           61           62           63           64           65 
##   9.50295374  27.78648596  12.30569837  -7.49704626  21.10844300 
##           66           67           68           69           70 
##  -7.40528015   6.29197522  -8.29979089   0.09471985   8.10844300 
##           71           72           73           74           75 
##  -4.10253552  16.29197522  21.50295374 -37.48332311   3.50295374 
##           76           77           78           79           80 
##  -8.89155700   8.48923059   3.51667689   5.51667689 -17.48332311 
##           81           82           83           84           85 
##  -0.49704626   5.10844300 -14.08881237  -7.19704626  -8.49704626 
##           86 
##   4.10844300

Simple Scatterplot

We did the simple scatterplot using the codes below.

attach(survey)
jpeg("scatterplot.jpg")
layout(matrix(c(1,3,2,4),2,2))
plot(WEIGHT, HEIGHT,
     main="1. Scatterplot for Weight vs Height",
     xlab="Weight,lbs",
     ylab="Height,in", pch=19)
abline(lm(HEIGHT~WEIGHT), col="red")

plot(WEIGHT, WAIST,
     main="2. Scatterplot for Weight vs Waistline",
     xlab="Weight,lbs",
     ylab="Waistline,in", pch=19)
abline(lm(GWA~HOURSNET), col="red")

plot(HOURSNET,GWA,
     main="3. Scatterplot for Nethrs vs Avegrade",
     xlab="Net Hours",
     ylab="Ave Grade", pch=19)
abline(lm(GWA~HOURSNET), col="red")


plot(AVESLEEP,GWA,
     main="4. Scatterplot for Hrsleep vs Avegrade",
     xlab="Hours Sleep",
     ylab="Ave Grade", pch=19)
abline(lm(GWA~AVESLEEP), col="red")

dev.off()
## png 
##   2

Diagnostic plots provide checks for heteroscedasticity, normality, and influential observations

jpeg("plotfit1.jpg")
layout(matrix(c(1,2,3,4),2,2))
plot(fit1)
dev.off()
## png 
##   2
jpeg("plotfit2.jpg")
layout(matrix(c(1,2,3,4),2,2))
plot(fit2)
dev.off()
## png 
##   2
jpeg("plotfit3.jpg")
layout(matrix(c(1,2,3,4),2,2))
plot(fit3)
dev.off
## function (which = dev.cur()) 
## {
##     if (which == 1) 
##         stop("cannot shut down device 1 (the null device)")
##     .External(C_devoff, as.integer(which))
##     dev.cur()
## }
## <bytecode: 0x00000000175977b0>
## <environment: namespace:grDevices>

RETURN OUTPUT TO CONSOLE/TERMINAL

sink(type="message")
sink()

CONFIDENCE INTERVAL OUTPUT FROM THE STDNTSURVEY.DATA

Fit1: WEIGHT~HEIGHT

confint(fit1, level=0.95)
##                   2.5 %     97.5 %
## (Intercept) -243.484440 -89.533679
## HEIGHT         3.489471   5.910712

Fit2: GWA~HOURSNET

confint(fit2, level=0.95)
##                   2.5 %     97.5 %
## (Intercept)  1.46046770 1.71229411
## HOURSNET    -0.02184544 0.00735231

Fit3: WEIGHT~WAIST

confint(fit3, level=0.95)
##                 2.5 %     97.5 %
## (Intercept) -86.92606 -27.915173
## WAIST         5.23773   7.156781

Multiple Regression Example

Multiple Regression Analysis has two or more independent variables are used in regression analysis. (https://www.thebalancesmb.com/what-is-simple-linear-regression-2296697).

For this activity, we started by running the codes below to set the directory that has the input files where the output files will be saved.

setwd("C:\\Handouts\\Handout No6")
survey<-read.csv("STDNTSURVEY.csv")
getwd()
## [1] "C:/Handouts/Handout No6"
attach(survey)
## The following objects are masked from survey (pos = 3):
## 
##     AGE, ARMLEN, ARMSPAN, AVESLEEP, BFASTDRINK, CIVILSTATUS,
##     CUPRICELUNCH, EMPLOYED, EXERCISE, FINSUPPORT, FULLPART, GWA,
##     HEIGHT, HOURSNET, LEGLEN, MOBILEPROV, NUMGADGETS, PALM, PROG,
##     RELIGION, SEM, SEX, SHOESIZE, SHOULDERWD, SMOKER, SOCIALDRINK,
##     SOCIALNET, STAGE, STUDYAREA, TVSTA, UNSTRESS, VIANDLUNCH,
##     WAIST, WEIGHT
names(survey)
##  [1] "PROG"         "FULLPART"     "SEM"          "STAGE"       
##  [5] "GWA"          "FINSUPPORT"   "EMPLOYED"     "SEX"         
##  [9] "CIVILSTATUS"  "RELIGION"     "AGE"          "AVESLEEP"    
## [13] "EXERCISE"     "UNSTRESS"     "STUDYAREA"    "HOURSNET"    
## [17] "SOCIALNET"    "CUPRICELUNCH" "VIANDLUNCH"   "BFASTDRINK"  
## [21] "SOCIALDRINK"  "SMOKER"       "TVSTA"        "MOBILEPROV"  
## [25] "NUMGADGETS"   "WEIGHT"       "HEIGHT"       "WAIST"       
## [29] "PALM"         "LEGLEN"       "ARMLEN"       "ARMSPAN"     
## [33] "SHOULDERWD"   "SHOESIZE"
survey
##    PROG FULLPART SEM STAGE    GWA FINSUPPORT EMPLOYED SEX CIVILSTATUS
## 1     1        1   3     1 1.2000          3        2   1           2
## 2     1        1   5     1 1.7500          1        2   1           2
## 3     1        2   3     1 1.6000          2        1   2           2
## 4     1        1   1     1     NA          1        2   1           2
## 5     1        2   4     2 1.2500          2        1   2           1
## 6     2        2   7     1 1.5000          2        1   1           2
## 7     1        2   4     1 1.5000          2        1   2           2
## 8     1        2  13     3 1.7500          2        1   2           2
## 9     2        1  16     4 1.7500          1        2   2           2
## 10    1        2   9     3 1.2500          2        1   1           2
## 11    1        2   3     1 1.2500          2        1   1           2
## 12    1        1   4     4 1.1000          1        2   1           2
## 13    1        2   1     1     NA          2        1   2           2
## 14    1        2   1     1     NA          2        1   1           2
## 15    1        2   3     1 2.0000          2        1   2           2
## 16    1        2   1     1     NA          2        1   2           2
## 17    1        1   3     1 2.0000          2        1   2           3
## 18    1        2   3     1 2.0000          2        1   1           2
## 19    1        2   4     2 1.2500          2        1   2           2
## 20    1        2   5     2 1.5625          2        1   2           2
## 21    1        2   5     2 1.2500          2        1   2           2
## 22    1        2   3     1 1.7000          2        1   2           2
## 23    1        1   3     1 1.7000          3        2   2           2
## 24    1        1   6     2 1.5000          2        1   2           2
## 25    1        2   3     1 2.0000          2        1   2           2
## 26    2        1   3     1 1.5000          1        1   2           1
## 27    2        1   4     2 1.2500          1        1   1           2
## 28    1        2   3     1 1.7500          2        1   2           2
## 29    1        1   2     1 2.2500          1        2   2           2
## 30    1        1   3     1 2.5000          1        2   2           2
## 31    1        1   2     1 1.7500          1        2   2           2
## 32    1        1   2     2 1.3000         NA        2   2           2
## 33    2        1   3     1 1.1300          1        1   1           2
## 34    1        1   3     2 1.6000          1        2   2           2
## 35    1        1   3     4 1.5000          1        2   2           2
## 36    1        1   3     2 1.3500          1        2   1           2
## 37    1        1   3     2 1.5000          1        1   2           1
## 38    1        1   1     1 1.7500          1        2   2           2
## 39    2        1   3     1 1.3700          1        1   1           2
## 40    1        1   3     1 1.3000          1        2   1           2
## 41    1        1   2     2 1.4300          1        2   2           2
## 42    2        1   3     1 1.5000          1        1   2           1
## 43    2        1   3     2 1.5000          1        1   2           2
## 44    1        1   3     1 1.5000          3        2   2           2
## 45    1        1   4     1 1.2500          1        1   2           2
## 46    1        2   3     1 1.5000          2        1   2           2
## 47    1        2   2     1 1.2500          2        1   1           2
## 48    1        2   4     2 1.2500          2        1   1           2
## 49    1        2   6     4 1.5000          2        1   1           2
## 50    1        2   4     1 1.5000          3        1   1           2
## 51    1        1   2     1 1.8864          1        1   2           2
## 52    1        1   2     1 1.2500          3        2   2           2
## 53    1        1   2     1 1.7500          3        2   1           2
## 54    1        2   3     1 1.2500          2        1   1           2
## 55    1        2   2     1 1.7500          3        2   1           2
## 56    1        2   2     1 2.0000          2        1   1           2
## 57    1        2   3     1 1.2500          2        1   1           2
## 58    1        2   0     1     NA          2        1   2           2
## 59    1        2   4     1 1.3500          2        1   1           2
## 60    1        2   0     1     NA          2        1   2           2
## 61    1        2   5     2 1.2500          2        1   2           2
## 62    1        2   6     2 1.5000          2        1   1           2
## 63    1        2   2     1 2.0000          2        1   1           2
## 64    1        2   5     2 1.4700          2        1   1           2
## 65    1        2   5     4 1.5000          2        1   1           2
## 66    1        2   1     1     NA          2        1   2           2
## 67    1        2   1     1     NA          2        1   2           2
## 68    1        2   3     1 1.6500          2        1   2           2
## 69    1        2   1     1     NA          2        1   2           2
## 70    1        2   3     1 1.4000          2        1   1           2
## 71    1        2   2     1 1.6500          2        1   2           2
## 72    1        2   2     1 2.0000          2        1   2           2
## 73    1        2   5     3 1.4000          2        1   1           2
## 74    1        2   3     1 1.4000          2        1   2           2
## 75    1        2   5     2 1.5000          2        1   1           2
## 76    1        2   4     2 1.7500          2        1   2           2
## 77    1        2   1     1     NA          2        1   2           2
## 78    1        2  20     4 1.4000          2        1   1           2
## 79    1        2   9     4 1.5000          2        1   1           2
## 80    1        1   3     1 1.5000          3        2   2           2
## 81    1        1   4     1 1.2500          1        1   2           2
## 82    1        2   3     1 1.5000          2        1   2           2
## 83    1        2   2     1 1.2500          2        1   1           2
## 84    1        2   4     2 1.2500          2        1   1           2
## 85    1        2   6     4 1.5000          2        1   1           2
## 86    1        2   4     1 1.5000          3        1   1           2
##                RELIGION AGE AVESLEEP EXERCISE UNSTRESS STUDYAREA HOURSNET
## 1              Agnostic  23      4.0        1        2         1      5.0
## 2              Catholic  23      6.0        2        3         4      4.0
## 3              Catholic  23      6.0        2        5         1      5.0
## 4              Catholic  21      9.0        2        1         3      4.0
## 5              Catholic  24      6.5        1        3         4     12.0
## 6              Agnostic  29      6.0        1        3         1     12.0
## 7              Catholic  24      7.0        2        4         4     12.0
## 8              Catholic  26      8.0        1        3         3      8.0
## 9              Catholic  30      7.0        1        2         4      8.0
## 10             Catholic  26      4.5        1        3         4     15.0
## 11             Catholic  23      6.0        1        4         4     18.0
## 12              Jehovah  22      6.0        2        4         3      5.0
## 13             Catholic  21      7.0        1        6         4      8.0
## 14             Catholic  22      7.0        1        6         4     12.0
## 15             Catholic  22      6.0        1        3         4     12.0
## 16             Catholic  21      8.0        1        6         1      8.0
## 17             Catholic  23      8.0        1        1         4      8.0
## 18             Catholic  24      7.0        1        4         1      8.0
## 19      NominalCatholic  24      8.0        1        1         4      8.0
## 20             Catholic  25      5.0        1        6         1      5.0
## 21             Catholic  25      9.0        2        1         4      6.0
## 22             Catholic  26      5.0        1        4         4      6.0
## 23      NominalCatholic  22      8.0        1        2         4      1.0
## 24             Catholic  25      4.0        2        3         1     12.0
## 25             Catholic  25      7.0        2        4         3      5.0
## 26             Catholic  34      8.0        2        6         1      4.0
## 27 EvangelicalChristian  40      6.0        1        1         2      4.0
## 28            Methodist  21      4.0        1        2         1     16.0
## 29              Baptist  21      8.0        1        1         4      3.0
## 30             Catholic  25      7.0        2        1         1     10.0
## 31             Catholic  24      7.0        2        3         1      4.0
## 32          Evangelical  23      7.0        1        1         1      4.0
## 33             Catholic  26      6.0        1        1         1      8.0
## 34             Catholic  25      6.0        1        1         4      4.5
## 35              Baptist  21      6.0        1        1         1      6.0
## 36             Catholic  27      6.0        1        3         1     10.0
## 37             Catholic  46      8.0        1        3         1      8.0
## 38             Catholic  23      9.0        1        1         4     15.0
## 39             Catholic  29      6.0        1        2         1      4.0
## 40             Catholic  25      6.0        1        3         4      5.0
## 41   BornAgainChristian  25      6.0        1        1         4      3.0
## 42             Catholic  42      6.0        1        3         1      6.0
## 43             Catholic  41      5.0        1        5         1      5.0
## 44             Catholic  22      6.0        2        4         3      6.0
## 45             Catholic  24      6.0        2        4         2     22.0
## 46              Jehovah  21      2.0        2        1         4      2.0
## 47             Catholic  24      8.0        1        1         4      6.0
## 48             Catholic  24      5.0        1        6         4      2.0
## 49             Catholic  25      5.0        2        3         4      3.0
## 50             Catholic  23      6.0        1        4         3     12.0
## 51            Adventist  28      7.0        1        1         4      6.0
## 52             Catholic  22      7.0        1        2         3      4.0
## 53             Catholic  23      7.5        1        2         1      4.5
## 54              Atheist  23      6.0        1        2         2     10.0
## 55             Catholic  22      6.0        2        1         1     12.0
## 56             Catholic  32      7.0        2        3         1      2.0
## 57             Catholic  25      8.0        1        6         3      8.0
## 58             Catholic  23      7.0        1        2         3     10.0
## 59             Catholic  23     10.0        1        6         4      8.0
## 60             Catholic  25      8.0        1        6         2     10.0
## 61             Catholic  24      8.0        1        1         2      8.0
## 62             Catholic  27      7.5        2        3         4      8.0
## 63             Catholic  22      6.0        1        4         3      6.0
## 64             Catholic  25      6.0        2        6         4      4.0
## 65             Catholic  23      7.0        1        1         2     12.0
## 66             Catholic  25      8.0        2        1         4      8.0
## 67             Catholic  22      5.0        1        1         2      9.0
## 68              Aglipay  24      6.0        2        1         2      8.0
## 69             Catholic  23      8.0        2        3         4      4.0
## 70             Catholic  22      6.0        1        2         4      8.0
## 71             Catholic  22      6.0        2        1         4      6.0
## 72             Catholic  21      6.0        2        4         4      5.0
## 73             Catholic  24      6.0        1        2         4      9.0
## 74             Catholic  21      6.0        1        1         4      6.0
## 75             Catholic  26      6.0        2        1         1      8.0
## 76             Catholic  22      8.0        1        1         4      5.0
## 77             Catholic  21      6.0        1        1         1      7.0
## 78            Adventist  30      8.0        1        4         3     10.0
## 79             Catholic  27      6.0        1        2         3     10.0
## 80             Catholic  22      6.0        2        4         3      6.0
## 81             Catholic  24      6.0        2        4         2     22.0
## 82              Jehovah  21      2.0        2        1         4      2.0
## 83             Catholic  24      8.0        1        1         4      6.0
## 84             Catholic  24      5.0        1        6         4      2.0
## 85             Catholic  25      5.0        2        3         4      3.0
## 86             Catholic  23      6.0        1        4         3     12.0
##    SOCIALNET CUPRICELUNCH VIANDLUNCH BFASTDRINK SOCIALDRINK SMOKER TVSTA
## 1          1            0          2          1           3      1     5
## 2          1            1          2          1           3      1     1
## 3          1            1          4          3           3      2     1
## 4          1            1          4          2           3      2    NA
## 5          1            1          2          4           3      2    NA
## 6          1            2          2          5           3      1     5
## 7          1            1          2          5           3      2     5
## 8          1            1          2          3           1      2     5
## 9          1            1          4          5           1      2     5
## 10         1            1          4          1           4      2     5
## 11         1            1          4          5           2      2     2
## 12         1            2          2          5           1      2     5
## 13         1            1          2          5           3      2     1
## 14         1            1          4          1           3      2     5
## 15         1            1          4          1           2      2     5
## 16         1            1          4          5           3      3     1
## 17         1            1          4          3           1      2     5
## 18         1            2          4          3           3      2     2
## 19         1            2          2          5          NA      2     5
## 20         1            2          4          5           1      2     1
## 21         1            2          1          2           3      3     5
## 22         1            2          2          5           3      2     5
## 23         1            2          4          5           3      2     2
## 24         1            2          2          1           3      2     2
## 25         1            1          4          1           1      2     2
## 26         1            1          4          1           4      2     1
## 27         1            1          2          1           2      2     5
## 28         1            2          4          1           1      2     2
## 29         1            1          4          2           2      2     1
## 30         1            1          2          1           2      3     1
## 31         1            1          2          5           3      2     5
## 32         1            1          2          4           2      2    NA
## 33         1            1          4          1          NA      2     5
## 34         1            1          1          1           3      2     2
## 35         2            1          4          5           2      2     1
## 36         1            1          2          1           2      2     1
## 37         1            1          4          1           2      2     5
## 38         1            1          4          1           2      2     1
## 39         1            1          2          5           3      1     1
## 40         1            1          2          3           3      3     1
## 41         1            1          2          1           3      3     5
## 42         1            1          1          5           1      2     5
## 43         1            1          4          3           2      2     1
## 44         1            1          3          1           2      2     2
## 45         1            1          3          1           3      2     1
## 46         1            1          2          5           3      2     2
## 47         1            2          2          1           3      2     1
## 48         1            2          4          5           2      2     1
## 49         1            1          4          1           3      2     1
## 50         1            0          2          1           2      2     1
## 51         1            1          3          4           2      2    NA
## 52         1            1          2          5           2      2     5
## 53         1            1          2          4           2      2     5
## 54         2            2          4          1           3      2     5
## 55         1            1          4          3           3      1     2
## 56         1            2          4          1           3      3     1
## 57         1            1          2          5           3      2     5
## 58         1            0          4          5           2      2     5
## 59         1            1          2          5           3      1     5
## 60         1            1          4          1           3      2     5
## 61         1            1          4          5           3      3     1
## 62         1            1          4          2           3      2     4
## 63         1            0          4          2           3      2     1
## 64         1            1          2          5           4      2     5
## 65         1            2          4          3           3      2     5
## 66         1            1          2          5           2      2     5
## 67         1            1          2          5           2      2     2
## 68         1            1          4          5           3      2     1
## 69         1            1          4          5           4      2     5
## 70         1            2          2          5           3      2     5
## 71         1            1          2          1           2      2     5
## 72         1            1          2          5           3      2     5
## 73         1            1          4          3           3      3     5
## 74         1            1          4          5           3      3     5
## 75         1            1          2          1           3      2    NA
## 76         1            1          1          5           1      2    NA
## 77         1            1          4          5           3      1     1
## 78         1            1          1          5           2      2     1
## 79         1            1          2          1           3      2     5
## 80         1            1          3          1           2      2     2
## 81         1            1          3          1           3      2     1
## 82         1            1          2          5           3      2     2
## 83         1            2          2          1           3      2     1
## 84         1            2          4          5           2      2     1
## 85         1            1          4          1           3      2     1
## 86         1            0          2          1           2      2     1
##    MOBILEPROV NUMGADGETS WEIGHT HEIGHT WAIST PALM LEGLEN ARMLEN ARMSPAN
## 1           2          2  155.0   71.0  30.5 3.80  38.00  31.20   71.00
## 2           2          2  155.0   64.0  34.0 3.50  34.50  26.40   68.00
## 3           2          3  113.2   61.5  26.0 3.00  32.40  26.00   59.50
## 4           2          2  184.0   72.0  32.5 3.50  39.00  29.90   72.00
## 5           4          3   96.0   59.0  26.5 2.80  29.40  25.00   58.00
## 6           2          2  132.0   66.0  31.0 3.45  37.00  28.70   67.00
## 7           4          4  240.9   64.2  43.0 3.50  35.00  26.50   63.50
## 8           2          3  124.0   63.0  32.0 3.00  36.50  27.50   65.00
## 9           4          3  141.0   68.0  34.0 3.25  38.00  30.50   68.50
## 10          2          2  197.0   70.1  36.0 3.75  36.00  30.00   70.50
## 11          2          2  143.0   66.0  30.0 3.50  35.00  29.00   67.00
## 12          2          2  165.0   67.0  33.0 3.50  35.00  28.00   67.00
## 13          2          1  132.3   64.0  28.0 3.00  30.00  30.00   72.00
## 14          4          2  134.5   64.8  27.0 3.30  32.00  28.00   67.00
## 15          1          2  132.3   64.0  29.0 3.20  32.00  27.00   66.00
## 16          1          2   92.6   59.0  27.0 2.80  25.00  20.00   55.00
## 17          4          2   94.8   59.0  28.0 3.00  24.00  25.50   65.00
## 18          1          2  121.3   64.0  30.0 3.40  36.00  26.00   65.00
## 19          4          3   97.0   59.0  24.4 2.80  34.00  25.80   60.00
## 20          4          3  160.0   64.0  32.0 3.50  33.00  26.00   65.38
## 21          1          3   90.0   60.0  24.0 4.00  38.00  26.00   83.00
## 22          2          3  141.0   65.0  28.0 6.00  37.00  28.50   68.75
## 23          1          4   85.0   61.0  25.0 3.00  36.50  25.00   60.00
## 24          4          3   92.0   58.7  29.0 6.50  34.50  26.00   57.50
## 25          2          3  110.0   64.0  35.5 3.00  36.75  28.50   65.75
## 26          4          3  165.0   59.0  40.0 3.50  32.00  26.00   58.60
## 27          4          3  157.0   69.5  32.0 4.00  40.00  30.00   74.50
## 28          2          3  123.2   50.0  30.0 3.20  35.75  25.50   63.00
## 29          2          2   95.5   59.5  25.0 3.20  35.70  26.00   59.80
## 30          1          2   79.4   59.0  27.0 3.00  34.50  24.00   58.50
## 31          2          3  114.4   63.0  30.5 3.00  37.75  28.50   66.00
## 32          2          3   97.0   58.0  26.0 3.20  32.00  26.00   59.00
## 33          4          6  121.3   64.8  29.0 3.50  35.00  29.00   65.00
## 34          2          2   90.4   62.0  26.0 3.00  33.00  26.00   62.00
## 35          4          2  101.4   62.0  28.0 3.00  30.00  25.00   62.00
## 36          2          3  165.0   66.5  36.0 3.50   4.00  26.00    6.30
## 37          4          3  160.0   63.0  34.0 3.20  35.20  26.70   62.00
## 38          2          3  115.0   61.0  28.0 3.20  33.00  26.00   61.00
## 39          2          3  154.3   66.0  34.0 4.50  27.50  31.00   66.00
## 40          2          4  132.0   64.0  35.0 3.00  33.00  25.00   62.00
## 41          2          2  121.0   60.0  30.0 3.00  35.00  33.00   67.00
## 42          4          4  127.9   64.0  32.0 3.20  38.50  29.00   64.50
## 43          2          3  103.0   62.0  27.0 3.50  36.00  27.00   68.00
## 44          2          4  142.0   65.0  35.0 4.60  23.00  22.00   63.00
## 45          2          3  128.0   60.0  30.0 3.20  32.50  24.00   60.00
## 46          2          1  146.0   60.0  32.0 3.00  33.00  24.00   60.00
## 47          2          4  133.0   66.0  33.0 3.00  19.00  24.00   60.00
## 48          2          4  121.3   66.0  30.0 2.50  30.00  22.00   58.00
## 49          2          4  120.0   64.0  30.0 4.00  32.00  27.00   63.00
## 50          2          5  145.0   64.5  32.0 4.20  34.00  19.50   67.00
## 51          2          2  114.6   62.0  29.0 3.40  36.00  28.80   63.80
## 52          2          2  101.0   60.0  26.0 3.00  33.00  27.00   61.50
## 53          1          2  195.0   71.0  39.0 4.00  41.50  29.50   74.00
## 54          4          2  165.0   70.0  33.0 4.00  38.00  31.50   75.00
## 55          2          2  154.0   63.0  32.0 3.50  35.00  27.00   65.00
## 56          1          1  154.0   68.0  31.0 3.50  36.50  29.00   69.00
## 57          3          3  135.0   65.0  30.0 4.00  29.53  27.95   67.32
## 58          2          3  145.2   65.8  31.0 3.54  31.50  28.35   66.93
## 59          4          3  165.4   68.0  35.0 3.54  32.28  37.00   71.65
## 60          4          2  109.1   60.0  27.0 2.73  28.74  25.59   55.91
## 61          4          3  138.0   65.0  30.0 3.54  38.98  29.92   66.14
## 62          2          2  119.1   63.0  24.0 4.33  29.13  27.95   67.72
## 63          1          2  147.0   68.0  31.0 3.50  37.00  29.00   68.00
## 64          1          3  121.0   65.0  30.0 3.25  37.00  28.00   66.00
## 65          2          3  162.0   68.0  32.0 5.50  36.00  30.00   60.00
## 66          2          2  102.5   58.0  27.0 2.80  36.00  22.00   52.00
## 67          4          1  110.0   61.2  26.0 3.00  30.00  26.00   60.00
## 68          1          2  114.0   59.8  29.0 3.00  35.00  24.00   58.80
## 69          1          2  110.0   60.0  27.0 3.20  34.00  24.00   59.00
## 70          1          2  149.0   67.0  32.0 3.60  36.00  28.00   66.00
## 71          1          2  112.0   55.0  28.0 3.00  34.00  24.00   53.00
## 72          2          2  120.0   61.0  26.0 3.00  35.00  26.00   59.00
## 73          1          2  150.0   66.0  30.0 3.90  37.00  28.00   60.00
## 74          1          2  122.0   59.0  35.0 3.00  32.00  24.50   57.50
## 75          1          2  132.0   67.0  30.0 3.50  37.00  28.00   67.00
## 76          4          2  132.0   60.0  32.0 3.50  35.00  23.50   58.50
## 77          2          2  106.0   64.0  25.0 3.00  36.50  26.50   64.50
## 78          4          2  163.0   68.0  35.0 3.50  39.00  31.00   70.00
## 79          4          2  165.0   68.0  35.0 3.50  36.00  28.50   69.00
## 80          2          4  142.0   65.0  35.0 4.60  23.00  22.00   63.00
## 81          2          3  128.0   60.0  30.0 3.20  32.50  24.00   60.00
## 82          2          1  146.0   60.0  32.0 3.00  33.00  24.00   60.00
## 83          2          4  133.0   66.0  33.0 3.00  19.00  24.00   60.00
## 84          2          4  121.3   66.0  30.0 2.50  30.00  22.00   58.00
## 85          2          4  120.0   64.0  30.0 4.00  32.00  27.00   63.00
## 86          2          5  145.0   64.5  32.0 4.20  34.00  19.50   67.00
##    SHOULDERWD SHOESIZE
## 1       19.00    11.50
## 2       18.00     9.00
## 3       16.00    10.00
## 4       18.00    11.50
## 5       14.90     8.50
## 6       17.00    11.50
## 7       17.00    10.00
## 8       15.00     8.00
## 9       15.00    10.00
## 10      18.00    11.00
## 11      18.00     9.50
## 12      17.50     9.00
## 13      15.00     9.00
## 14      17.00     9.20
## 15      15.00     7.50
## 16      14.50     6.00
## 17      14.50     7.00
## 18      15.00     8.00
## 19      13.00     8.50
## 20      17.00    10.00
## 21      16.00     6.00
## 22      15.75    10.50
## 23      15.00     8.00
## 24      13.00     8.50
## 25      15.50     9.00
## 26      16.20     9.00
## 27      18.00    12.00
## 28      16.00     9.00
## 29      15.00     8.60
## 30      14.00     8.00
## 31      15.00     9.50
## 32       4.00     9.00
## 33      18.00     8.00
## 34      14.00     8.00
## 35      17.00     9.50
## 36      18.00     8.00
## 37      18.50     8.00
## 38      15.50     9.00
## 39      17.00     8.50
## 40      16.00     8.00
## 41       4.00     6.00
## 42      13.00     8.00
## 43      14.00     6.50
## 44      19.00     9.50
## 45      12.00     8.00
## 46      12.00     8.00
## 47      12.00    10.00
## 48      17.00     8.00
## 49      15.00     8.50
## 50      19.00    10.00
## 51      12.00     8.00
## 52      12.00     7.00
## 53      17.00    10.00
## 54      18.00    12.00
## 55      16.00    12.00
## 56      16.00     9.50
## 57      18.90    11.02
## 58      18.11    10.23
## 59      22.04    10.63
## 60      14.96     8.75
## 61      18.90     9.25
## 62      17.72    10.44
## 63      15.00     8.50
## 64      16.00     9.50
## 65      20.00    10.00
## 66      13.50     7.50
## 67      18.00     9.00
## 68      18.00     8.00
## 69      15.00     8.50
## 70      18.00     9.00
## 71      14.00     7.00
## 72      14.00     8.00
## 73      17.00    10.00
## 74      14.50     8.50
## 75      16.50     9.50
## 76      16.50     9.00
## 77      15.50     7.00
## 78      18.50     9.50
## 79      17.00     9.00
## 80      19.00     9.50
## 81      12.00     8.00
## 82      12.00     8.00
## 83      12.00    10.00
## 84      17.00     8.00
## 85      15.00     8.50
## 86      19.00    10.00

Load Library

library(Hmisc)
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## Loading required package: ggplot2
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:base':
## 
##     format.pval, units
library(psych)
## 
## Attaching package: 'psych'
## The following object is masked from 'package:Hmisc':
## 
##     describe
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha

Selecting Variables

We were instructed to select variables (v1, v2, v3) from quick-R.

selvar1<-c("HEIGHT","WEIGHT","WAIST","ARMSPAN")
regvar1<-survey[selvar1]
selvar2<-c("HEIGHT","WEIGHT","WAIST","ARMSPAN","SHOESIZE",
           "SHOULDERWD","LEGLEN")
regvar3<-survey[selvar2]

PAIRS PANEL

jpeg("pairspanel2017.jpg")
pairs.panels(regvar1)
dev.off()
## png 
##   2

FIND CORRELATED VARIABLES

myQs1<-as.matrix(regvar1)
rcorr(myQs1, type="pearson")
##         HEIGHT WEIGHT WAIST ARMSPAN
## HEIGHT    1.00   0.64  0.46    0.33
## WEIGHT    0.64   1.00  0.81    0.18
## WAIST     0.46   0.81  1.00    0.02
## ARMSPAN   0.33   0.18  0.02    1.00
## 
## n= 86 
## 
## 
## P
##         HEIGHT WEIGHT WAIST  ARMSPAN
## HEIGHT         0.0000 0.0000 0.0018 
## WEIGHT  0.0000        0.0000 0.1017 
## WAIST   0.0000 0.0000        0.8480 
## ARMSPAN 0.0018 0.1017 0.8480
myQs3<-as.matrix(regvar3)
rcorr(myQs3, type="pearson")
##            HEIGHT WEIGHT WAIST ARMSPAN SHOESIZE SHOULDERWD LEGLEN
## HEIGHT       1.00   0.64  0.46    0.33     0.58       0.51   0.11
## WEIGHT       0.64   1.00  0.81    0.18     0.56       0.45   0.09
## WAIST        0.46   0.81  1.00    0.02     0.37       0.32  -0.06
## ARMSPAN      0.33   0.18  0.02    1.00     0.31       0.16   0.66
## SHOESIZE     0.58   0.56  0.37    0.31     1.00       0.49   0.14
## SHOULDERWD   0.51   0.45  0.32    0.16     0.49       1.00   0.05
## LEGLEN       0.11   0.09 -0.06    0.66     0.14       0.05   1.00
## 
## n= 86 
## 
## 
## P
##            HEIGHT WEIGHT WAIST  ARMSPAN SHOESIZE SHOULDERWD LEGLEN
## HEIGHT            0.0000 0.0000 0.0018  0.0000   0.0000     0.2998
## WEIGHT     0.0000        0.0000 0.1017  0.0000   0.0000     0.4097
## WAIST      0.0000 0.0000        0.8480  0.0005   0.0026     0.6000
## ARMSPAN    0.0018 0.1017 0.8480         0.0041   0.1423     0.0000
## SHOESIZE   0.0000 0.0000 0.0005 0.0041           0.0000     0.1858
## SHOULDERWD 0.0000 0.0000 0.0026 0.1423  0.0000              0.6743
## LEGLEN     0.2998 0.4097 0.6000 0.0000  0.1858   0.6743

Simple Scatterplot

jpeg("scatterplot2017.jpg")
layout(matrix(c(1,3,2,4),2,2))

plot(HEIGHT,WEIGHT,
     main="1. Scatterplot for HEIGHT vs WEIGHT",
     xlab="Height,in",
     ylab="Weight,lbs", pch=19)
abline(lm(WEIGHT~HEIGHT), col="red")

plot(HEIGHT,WAIST,
     main="2. Scatterplot for Height vs Waistline",
     ylab="Waistline,in",
     xlab="Height,in", pch=19)
abline(lm(WAIST~HEIGHT), col="red")

plot(HEIGHT,ARMSPAN,
     main="3. Scatterplot for Height vs Armspan",
     xlab="Height,in",
     ylab="Armspan,in", pch=19)
abline(lm(ARMSPAN~HEIGHT), col="red")

dev.off()
## png 
##   2

FITTING MULTIPLE LINEAR REGRESSION

var1.mreg<- lm(HEIGHT~WEIGHT+WAIST, data=regvar1)
var2.mreg<- lm(HEIGHT~WEIGHT+WAIST+ARMSPAN, data= regvar1)
var3.mreg<- lm(HEIGHT~WEIGHT+WAIST+ARMSPAN+SHOESIZE+SHOULDERWD+LEGLEN, data=regvar3)

anova(var1.mreg)
## Analysis of Variance Table
## 
## Response: HEIGHT
##           Df Sum Sq Mean Sq F value    Pr(>F)    
## WEIGHT     1 515.38  515.38 60.2127 1.954e-11 ***
## WAIST      1  15.87   15.87  1.8539     0.177    
## Residuals 83 710.42    8.56                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(var2.mreg)
## Analysis of Variance Table
## 
## Response: HEIGHT
##           Df Sum Sq Mean Sq F value   Pr(>F)    
## WEIGHT     1 515.38  515.38 64.0490 6.89e-12 ***
## WAIST      1  15.87   15.87  1.9721  0.16401    
## ARMSPAN    1  50.60   50.60  6.2881  0.01413 *  
## Residuals 82 659.82    8.05                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(var3.mreg)
## Analysis of Variance Table
## 
## Response: HEIGHT
##            Df Sum Sq Mean Sq F value    Pr(>F)    
## WEIGHT      1 515.38  515.38 72.9911 7.583e-13 ***
## WAIST       1  15.87   15.87  2.2474  0.137826    
## ARMSPAN     1  50.60   50.60  7.1660  0.009032 ** 
## SHOESIZE    1  54.59   54.59  7.7318  0.006780 ** 
## SHOULDERWD  1  34.61   34.61  4.9012  0.029721 *  
## LEGLEN      1  12.82   12.82  1.8152  0.181734    
## Residuals  79 557.80    7.06                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
anova(var2.mreg,var1.mreg)
## Analysis of Variance Table
## 
## Model 1: HEIGHT ~ WEIGHT + WAIST + ARMSPAN
## Model 2: HEIGHT ~ WEIGHT + WAIST
##   Res.Df    RSS Df Sum of Sq      F  Pr(>F)  
## 1     82 659.82                              
## 2     83 710.42 -1   -50.598 6.2881 0.01413 *
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Comparing Models (see link http://www.statmethods.net/stats/regression.html). We can compare nested models with the anova() function. The following code provides a simultaneous test that x3 and x4 add to linear prediction above and beyond x1 and x2. Compare models: fit1 <- lm(y~x1 + x2 + x3 + x4, data=mydata), fit2 <- lm(y~x1 + x2).

anova(fit1,fit2)
## Warning in anova.lmlist(object, ...): models with response '"GWA"' removed
## because response differs from model 1
## Analysis of Variance Table
## 
## Response: WEIGHT
##           Df Sum Sq Mean Sq F value    Pr(>F)    
## HEIGHT     1  27429 27429.4  59.607 2.193e-11 ***
## Residuals 84  38654   460.2                      
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

As often, however, our real interest is not whether the additional coefficient is statistically significant at the 5% or any level, but in whether adding the extra term is likely to improve the predictive power of the equation. The Akaike Information Criterion (AIC) is designed to decrease as the estimated predictive power increases.

step(var1.mreg)
## Start:  AIC=187.59
## HEIGHT ~ WEIGHT + WAIST
## 
##          Df Sum of Sq    RSS    AIC
## - WAIST   1    15.868 726.29 187.49
## <none>                710.42 187.59
## - WEIGHT  1   269.920 980.34 213.28
## 
## Step:  AIC=187.49
## HEIGHT ~ WEIGHT
## 
##          Df Sum of Sq     RSS    AIC
## <none>                 726.29 187.49
## - WEIGHT  1    515.38 1241.66 231.61
## 
## Call:
## lm(formula = HEIGHT ~ WEIGHT, data = regvar1)
## 
## Coefficients:
## (Intercept)       WEIGHT  
##    51.82998      0.08831
step(var2.mreg)
## Start:  AIC=183.24
## HEIGHT ~ WEIGHT + WAIST + ARMSPAN
## 
##           Df Sum of Sq    RSS    AIC
## - WAIST    1     5.523 665.34 181.95
## <none>                 659.82 183.24
## - ARMSPAN  1    50.598 710.42 187.59
## - WEIGHT   1   191.016 850.84 203.10
## 
## Step:  AIC=181.95
## HEIGHT ~ WEIGHT + ARMSPAN
## 
##           Df Sum of Sq     RSS    AIC
## <none>                  665.34 181.95
## - ARMSPAN  1     60.94  726.29 187.49
## - WEIGHT   1    439.04 1104.39 223.53
## 
## Call:
## lm(formula = HEIGHT ~ WEIGHT + ARMSPAN, data = regvar1)
## 
## Coefficients:
## (Intercept)       WEIGHT      ARMSPAN  
##    45.85351      0.08283      0.10577
step(var3.mreg)
## Start:  AIC=174.79
## HEIGHT ~ WEIGHT + WAIST + ARMSPAN + SHOESIZE + SHOULDERWD + LEGLEN
## 
##              Df Sum of Sq    RSS    AIC
## - WAIST       1     2.246 560.05 173.14
## - LEGLEN      1    12.817 570.62 174.74
## <none>                    557.80 174.79
## - SHOESIZE    1    25.292 583.09 176.60
## - SHOULDERWD  1    32.144 589.95 177.61
## - ARMSPAN     1    40.192 597.99 178.77
## - WEIGHT      1    68.741 626.54 182.78
## 
## Step:  AIC=173.14
## HEIGHT ~ WEIGHT + ARMSPAN + SHOESIZE + SHOULDERWD + LEGLEN
## 
##              Df Sum of Sq    RSS    AIC
## - LEGLEN      1    11.675 571.72 172.91
## <none>                    560.05 173.14
## - SHOESIZE    1    27.805 587.85 175.30
## - SHOULDERWD  1    32.982 593.03 176.06
## - ARMSPAN     1    41.289 601.34 177.25
## - WEIGHT      1   134.733 694.78 189.68
## 
## Step:  AIC=172.91
## HEIGHT ~ WEIGHT + ARMSPAN + SHOESIZE + SHOULDERWD
## 
##              Df Sum of Sq    RSS    AIC
## <none>                    571.72 172.91
## - SHOESIZE    1    29.949 601.67 175.30
## - ARMSPAN     1    30.791 602.52 175.42
## - SHOULDERWD  1    35.131 606.86 176.04
## - WEIGHT      1   133.098 704.82 188.91
## 
## Call:
## lm(formula = HEIGHT ~ WEIGHT + ARMSPAN + SHOESIZE + SHOULDERWD, 
##     data = regvar3)
## 
## Coefficients:
## (Intercept)       WEIGHT      ARMSPAN     SHOESIZE   SHOULDERWD  
##    41.66515      0.05609      0.07773      0.58597      0.26969

Both R2 and adjusted R2 were included in the output that comes from summary().

Check out R2 and Adj. R2

summary(var1.mreg)
## 
## Call:
## lm(formula = HEIGHT ~ WEIGHT + WAIST, data = regvar1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -12.6314  -1.3416   0.5277   1.7740   4.9713 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 55.16930    2.89213  19.076  < 2e-16 ***
## WEIGHT       0.11003    0.01959   5.616 2.54e-07 ***
## WAIST       -0.20310    0.14917  -1.362    0.177    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.926 on 83 degrees of freedom
## Multiple R-squared:  0.4278, Adjusted R-squared:  0.4141 
## F-statistic: 31.03 on 2 and 83 DF,  p-value: 8.643e-11
summary(var2.mreg)
## 
## Call:
## lm(formula = HEIGHT ~ WEIGHT + WAIST + ARMSPAN, data = regvar1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -12.6734  -1.3795   0.3625   1.6750   6.1343 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 48.27014    3.92848  12.287  < 2e-16 ***
## WEIGHT       0.09632    0.01977   4.872  5.3e-06 ***
## WAIST       -0.12273    0.14814  -0.829   0.4098    
## ARMSPAN      0.09872    0.03937   2.508   0.0141 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.837 on 82 degrees of freedom
## Multiple R-squared:  0.4686, Adjusted R-squared:  0.4492 
## F-statistic:  24.1 on 3 and 82 DF,  p-value: 2.794e-11
summary(var3.mreg)
## 
## Call:
## lm(formula = HEIGHT ~ WEIGHT + WAIST + ARMSPAN + SHOESIZE + SHOULDERWD + 
##     LEGLEN, data = regvar3)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -12.7566  -1.4897   0.3436   1.6478   5.0515 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 44.09828    4.10335  10.747  < 2e-16 ***
## WEIGHT       0.06586    0.02111   3.120  0.00252 ** 
## WAIST       -0.07977    0.14145  -0.564  0.57437    
## ARMSPAN      0.11821    0.04955   2.386  0.01943 *  
## SHOESIZE     0.54409    0.28748   1.893  0.06207 .  
## SHOULDERWD   0.25858    0.12119   2.134  0.03597 *  
## LEGLEN      -0.09912    0.07357  -1.347  0.18173    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.657 on 79 degrees of freedom
## Multiple R-squared:  0.5508, Adjusted R-squared:  0.5166 
## F-statistic: 16.14 on 6 and 79 DF,  p-value: 4.975e-12