Problem 2


While both are non-parametric models that use the nearest K points to estimate a value, The KNN classifier is used in classification to classify a categorical or qualitative response variable. The KNN regression uses regression to predict a quantitative response variable.

Problem 9a

library (ISLR)
## Warning: package 'ISLR' was built under R version 4.0.5
names(Auto)
## [1] "mpg"          "cylinders"    "displacement" "horsepower"   "weight"      
## [6] "acceleration" "year"         "origin"       "name"
pairs(Auto)

Problem 9b

cor(Auto [,1:8])
##                     mpg  cylinders displacement horsepower     weight
## mpg           1.0000000 -0.7776175   -0.8051269 -0.7784268 -0.8322442
## cylinders    -0.7776175  1.0000000    0.9508233  0.8429834  0.8975273
## displacement -0.8051269  0.9508233    1.0000000  0.8972570  0.9329944
## horsepower   -0.7784268  0.8429834    0.8972570  1.0000000  0.8645377
## weight       -0.8322442  0.8975273    0.9329944  0.8645377  1.0000000
## acceleration  0.4233285 -0.5046834   -0.5438005 -0.6891955 -0.4168392
## year          0.5805410 -0.3456474   -0.3698552 -0.4163615 -0.3091199
## origin        0.5652088 -0.5689316   -0.6145351 -0.4551715 -0.5850054
##              acceleration       year     origin
## mpg             0.4233285  0.5805410  0.5652088
## cylinders      -0.5046834 -0.3456474 -0.5689316
## displacement   -0.5438005 -0.3698552 -0.6145351
## horsepower     -0.6891955 -0.4163615 -0.4551715
## weight         -0.4168392 -0.3091199 -0.5850054
## acceleration    1.0000000  0.2903161  0.2127458
## year            0.2903161  1.0000000  0.1815277
## origin          0.2127458  0.1815277  1.0000000

Problem 9c

lm_auto1 <- lm(mpg~.-name, data = Auto)
summary(lm_auto1)
## 
## Call:
## lm(formula = mpg ~ . - name, data = Auto)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9.5903 -2.1565 -0.1169  1.8690 13.0604 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -17.218435   4.644294  -3.707  0.00024 ***
## cylinders     -0.493376   0.323282  -1.526  0.12780    
## displacement   0.019896   0.007515   2.647  0.00844 ** 
## horsepower    -0.016951   0.013787  -1.230  0.21963    
## weight        -0.006474   0.000652  -9.929  < 2e-16 ***
## acceleration   0.080576   0.098845   0.815  0.41548    
## year           0.750773   0.050973  14.729  < 2e-16 ***
## origin         1.426141   0.278136   5.127 4.67e-07 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.328 on 384 degrees of freedom
## Multiple R-squared:  0.8215, Adjusted R-squared:  0.8182 
## F-statistic: 252.4 on 7 and 384 DF,  p-value: < 2.2e-16

The p-value for the model is less than 2.2e-16, so there is a significant relationship between at least one of the predictors and the response variable. Looking at the individual t-test results of the model, the significant variables appear to be displacement (p-vaue = 0.00844), weight (p-value < 2e-16), year (p-value < 2e-16), and origin (p-value = 4.67e-07). The coefficient for year is 0.750773. This means that each year, on average, new cars get approximately 0.75 more miles to the gallon as compared to the previous year’s cars when all other variables are held constant. Another way to describe it is that the predicted mpg will be 0.75 higher for each unit year increase when all other variables are held constant.

Problem 9d

par(mfrow = c(2,2))
plot(lm_auto1)

  The residuals plot shows that there is an issues with heteroscedasticity. There is a slight curve to the line which suggests the relationship might not be linear. It shows observations 327 and 394 as outliers in addition to some other unreadable points that will be identified below. The Q-Q plot suggests that there could be an issue with normality at one tail. The leverage plot identifies observation 14 with unusually high leverage.

  Outliers:

rstudent(lm_auto1)[which(rstudent(lm_auto1)>=3)]
##      245      323      326      327 
## 3.390068 4.029537 3.494823 3.690246

Problem 9e

lm_auto2 <- lm(mpg~year*origin, data = Auto)
summary (lm_auto2)
## 
## Call:
## lm(formula = mpg ~ year * origin, data = Auto)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -11.3141  -3.7120  -0.6513   3.3621  15.5859 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -83.3809    12.0000  -6.948 1.57e-11 ***
## year          1.3089     0.1576   8.305 1.68e-15 ***
## origin       17.3752     6.8325   2.543   0.0114 *  
## year:origin  -0.1663     0.0889  -1.871   0.0621 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 5.199 on 388 degrees of freedom
## Multiple R-squared:  0.5596, Adjusted R-squared:  0.5562 
## F-statistic: 164.4 on 3 and 388 DF,  p-value: < 2.2e-16
lm_auto3 <- lm(mpg~year*weight, data = Auto)
summary (lm_auto3)
## 
## Call:
## lm(formula = mpg ~ year * weight, data = Auto)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.0397 -1.9956 -0.0983  1.6525 12.9896 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -1.105e+02  1.295e+01  -8.531 3.30e-16 ***
## year         2.040e+00  1.718e-01  11.876  < 2e-16 ***
## weight       2.755e-02  4.413e-03   6.242 1.14e-09 ***
## year:weight -4.579e-04  5.907e-05  -7.752 8.02e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.193 on 388 degrees of freedom
## Multiple R-squared:  0.8339, Adjusted R-squared:  0.8326 
## F-statistic: 649.3 on 3 and 388 DF,  p-value: < 2.2e-16
lm_auto4 <- lm(mpg~.-name+year:weight, data = Auto)
summary (lm_auto4)
## 
## Call:
## lm(formula = mpg ~ . - name + year:weight, data = Auto)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -7.9995 -1.8495 -0.1559  1.6061 11.7042 
## 
## Coefficients:
##                Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  -1.186e+02  1.338e+01  -8.864  < 2e-16 ***
## cylinders    -1.218e-01  3.032e-01  -0.402   0.6881    
## displacement  1.293e-02  7.019e-03   1.842   0.0663 .  
## horsepower   -2.877e-02  1.286e-02  -2.236   0.0259 *  
## weight        3.044e-02  4.652e-03   6.543 1.94e-10 ***
## acceleration  1.447e-01  9.196e-02   1.574   0.1164    
## year          2.084e+00  1.732e-01  12.033  < 2e-16 ***
## origin        1.174e+00  2.597e-01   4.519 8.30e-06 ***
## weight:year  -4.879e-04  6.097e-05  -8.002 1.47e-14 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.084 on 383 degrees of freedom
## Multiple R-squared:  0.847,  Adjusted R-squared:  0.8439 
## F-statistic: 265.1 on 8 and 383 DF,  p-value: < 2.2e-16
lm_auto5 <- lm(mpg~.-name+year:horsepower, data = Auto)
summary (lm_auto5)
## 
## Call:
## lm(formula = mpg ~ . - name + year:horsepower, data = Auto)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.6314 -1.8896 -0.0724  1.5781 11.6140 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)     -9.723e+01  1.008e+01  -9.648  < 2e-16 ***
## cylinders        8.146e-02  3.027e-01   0.269    0.788    
## displacement     5.183e-03  7.072e-03   0.733    0.464    
## horsepower       8.070e-01  9.496e-02   8.498 4.33e-16 ***
## weight          -5.288e-03  6.112e-04  -8.651  < 2e-16 ***
## acceleration    -2.894e-02  9.121e-02  -0.317    0.751    
## year             1.830e+00  1.318e-01  13.887  < 2e-16 ***
## origin           1.178e+00  2.558e-01   4.604 5.66e-06 ***
## horsepower:year -1.140e-02  1.302e-03  -8.754  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.042 on 383 degrees of freedom
## Multiple R-squared:  0.8512, Adjusted R-squared:  0.8481 
## F-statistic:   274 on 8 and 383 DF,  p-value: < 2.2e-16
lm_auto6 <- lm(mpg~.-name+acceleration:horsepower, data = Auto)
summary (lm_auto6)
## 
## Call:
## lm(formula = mpg ~ . - name + acceleration:horsepower, data = Auto)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -9.0329 -1.8177 -0.1183  1.7247 12.4870 
## 
## Coefficients:
##                           Estimate Std. Error t value Pr(>|t|)    
## (Intercept)             -32.499820   4.923380  -6.601 1.36e-10 ***
## cylinders                 0.083489   0.316913   0.263 0.792350    
## displacement             -0.007649   0.008161  -0.937 0.349244    
## horsepower                0.127188   0.024746   5.140 4.40e-07 ***
## weight                   -0.003976   0.000716  -5.552 5.27e-08 ***
## acceleration              0.983282   0.161513   6.088 2.78e-09 ***
## year                      0.755919   0.048179  15.690  < 2e-16 ***
## origin                    1.035733   0.268962   3.851 0.000138 ***
## horsepower:acceleration  -0.012139   0.001772  -6.851 2.93e-11 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.145 on 383 degrees of freedom
## Multiple R-squared:  0.841,  Adjusted R-squared:  0.8376 
## F-statistic: 253.2 on 8 and 383 DF,  p-value: < 2.2e-16

There appear to be many significant interactions. Year and weight, year and horsepower, acceleration and horsepower all have significant interaction effects. Year and origin did not have an interaction effect.

Problem 9f

lm_auto7 <- lm(mpg~.-name+log(horsepower), data=Auto)
summary(lm_auto7)
## 
## Call:
## lm(formula = mpg ~ . - name + log(horsepower), data = Auto)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.5777 -1.6623 -0.1213  1.4913 12.0230 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      8.674e+01  1.106e+01   7.839 4.54e-14 ***
## cylinders       -5.530e-02  2.907e-01  -0.190 0.849230    
## displacement    -4.607e-03  7.108e-03  -0.648 0.517291    
## horsepower       1.764e-01  2.269e-02   7.775 7.05e-14 ***
## weight          -3.366e-03  6.561e-04  -5.130 4.62e-07 ***
## acceleration    -3.277e-01  9.670e-02  -3.388 0.000776 ***
## year             7.421e-01  4.534e-02  16.368  < 2e-16 ***
## origin           8.976e-01  2.528e-01   3.551 0.000432 ***
## log(horsepower) -2.685e+01  2.652e+00 -10.127  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.959 on 383 degrees of freedom
## Multiple R-squared:  0.8592, Adjusted R-squared:  0.8562 
## F-statistic: 292.1 on 8 and 383 DF,  p-value: < 2.2e-16

The residual standard error of all previous attempts was over 3. Adding the log of horsepower reduced the RSE to just under 3, a slight improvement of fit.

lm_auto8 <- lm(mpg~.-name+sqrt(horsepower), data=Auto)
summary(lm_auto8)
## 
## Call:
## lm(formula = mpg ~ . - name + sqrt(horsepower), data = Auto)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.5402 -1.6717 -0.0778  1.4861 11.9754 
## 
## Coefficients:
##                    Estimate Std. Error t value Pr(>|t|)    
## (Intercept)       4.299e+01  7.251e+00   5.929 6.82e-09 ***
## cylinders         6.037e-02  2.928e-01   0.206 0.836748    
## displacement     -5.870e-03  7.156e-03  -0.820 0.412560    
## horsepower        4.239e-01  4.532e-02   9.353  < 2e-16 ***
## weight           -3.285e-03  6.604e-04  -4.975 9.87e-07 ***
## acceleration     -3.342e-01  9.705e-02  -3.443 0.000638 ***
## year              7.398e-01  4.536e-02  16.308  < 2e-16 ***
## origin            9.159e-01  2.526e-01   3.626 0.000326 ***
## sqrt(horsepower) -1.050e+01  1.039e+00 -10.104  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.961 on 383 degrees of freedom
## Multiple R-squared:  0.8591, Adjusted R-squared:  0.8561 
## F-statistic: 291.8 on 8 and 383 DF,  p-value: < 2.2e-16

Adding the square root of horsepower did not fit as well as log horsepower, but did improve the fit from the original attempts

lm_auto9 <- lm(mpg~.-name+I(horsepower^2), data=Auto)
summary(lm_auto9)
## 
## Call:
## lm(formula = mpg ~ . - name + I(horsepower^2), data = Auto)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.5497 -1.7311 -0.2236  1.5877 11.9955 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      1.3236564  4.6247696   0.286 0.774872    
## cylinders        0.3489063  0.3048310   1.145 0.253094    
## displacement    -0.0075649  0.0073733  -1.026 0.305550    
## horsepower      -0.3194633  0.0343447  -9.302  < 2e-16 ***
## weight          -0.0032712  0.0006787  -4.820 2.07e-06 ***
## acceleration    -0.3305981  0.0991849  -3.333 0.000942 ***
## year             0.7353414  0.0459918  15.989  < 2e-16 ***
## origin           1.0144130  0.2545545   3.985 8.08e-05 ***
## I(horsepower^2)  0.0010060  0.0001065   9.449  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.001 on 383 degrees of freedom
## Multiple R-squared:  0.8552, Adjusted R-squared:  0.8522 
## F-statistic: 282.8 on 8 and 383 DF,  p-value: < 2.2e-16

Adding the square of horsepower produced a model with a slightly lower fit as compared to the log and square root versions.

lm_auto10 <- lm(mpg~.-name+log(horsepower)+horsepower:year, data=Auto)
summary(lm_auto10)
## 
## Call:
## lm(formula = mpg ~ . - name + log(horsepower) + horsepower:year, 
##     data = Auto)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.2717 -1.5815 -0.1233  1.4498 11.4355 
## 
## Coefficients:
##                   Estimate Std. Error t value Pr(>|t|)    
## (Intercept)      1.280e+01  1.890e+01   0.677 0.498708    
## cylinders        1.715e-01  2.868e-01   0.598 0.550167    
## displacement    -6.998e-03  6.933e-03  -1.009 0.313408    
## horsepower       6.132e-01  9.437e-02   6.498 2.54e-10 ***
## weight          -3.464e-03  6.386e-04  -5.424 1.04e-07 ***
## acceleration    -2.874e-01  9.446e-02  -3.043 0.002503 ** 
## year             1.381e+00  1.413e-01   9.773  < 2e-16 ***
## origin           8.867e-01  2.459e-01   3.605 0.000353 ***
## log(horsepower) -1.996e+01  2.959e+00  -6.745 5.69e-11 ***
## horsepower:year -6.727e-03  1.413e-03  -4.761 2.74e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.879 on 382 degrees of freedom
## Multiple R-squared:  0.8671, Adjusted R-squared:  0.8639 
## F-statistic: 276.9 on 9 and 382 DF,  p-value: < 2.2e-16

Adding the log of horsepower and the interaction of horsepower and year produced the best model so far with a lower RSE of 2.879 and a higher R-squared of 0.8671

Problem 10a

carseats1 <- lm(Sales~Price+Urban+US, data = Carseats)
summary(carseats1)
## 
## Call:
## lm(formula = Sales ~ Price + Urban + US, data = Carseats)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.9206 -1.6220 -0.0564  1.5786  7.0581 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 13.043469   0.651012  20.036  < 2e-16 ***
## Price       -0.054459   0.005242 -10.389  < 2e-16 ***
## UrbanYes    -0.021916   0.271650  -0.081    0.936    
## USYes        1.200573   0.259042   4.635 4.86e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.472 on 396 degrees of freedom
## Multiple R-squared:  0.2393, Adjusted R-squared:  0.2335 
## F-statistic: 41.52 on 3 and 396 DF,  p-value: < 2.2e-16

Problem 10b

The Price coefficient was -0.054459. This suggests that, holding all other predictors constant, as price goes up by one unit, the predicted sales decrease by 0.054459 (54 car seats). The Urban Coefficient was -0.021916 for the yes dummy variable. This suggests that sales in urban areas would be predicted to be 0.021916 units less as compared to non-urban areas. However, the urban predictor was not statistically significant, so the coefficient effectively is 0 and there is no difference between urban and non-urban areas. The US coefficient is 1.200573. This suggests that, holding all other predictors constant, sales in the US would be predicted to be 1.200573 (1200 carseats) higher in the US as compared to not in the US.

Problem 10c

The model in equation form would be Sales = 13.04 - 0.054459 X Price - 0.021916 X Urban {yes:1, no:0} + 0.021916 X US {Yes:1, no:0}

Problem 10d

Out of the above model, the predictors in which the null hypothesis can be rejected are Price (p < 2e-16) and US (p = 4.86e-06)

Problem 10e

carseats2 <- lm(Sales~Price+US, data = Carseats)
summary(carseats2)
## 
## Call:
## lm(formula = Sales ~ Price + US, data = Carseats)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.9269 -1.6286 -0.0574  1.5766  7.0515 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept) 13.03079    0.63098  20.652  < 2e-16 ***
## Price       -0.05448    0.00523 -10.416  < 2e-16 ***
## USYes        1.19964    0.25846   4.641 4.71e-06 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 2.469 on 397 degrees of freedom
## Multiple R-squared:  0.2393, Adjusted R-squared:  0.2354 
## F-statistic: 62.43 on 2 and 397 DF,  p-value: < 2.2e-16

Problem 10f

For model a, the RSE was 2.472 and the R-squared was 0.2393. Therefore, only 23.93% of the variation in the data can be explained by the model. In model e, the RSE went down slightly to 2.469, implying a slight improvement in fit. The R-squared was still 0.2393 - so still not much of the variation in the data is explained by the model. Including more variables would likely improve the fit.

Problem 10g

confint(carseats2)
##                   2.5 %      97.5 %
## (Intercept) 11.79032020 14.27126531
## Price       -0.06475984 -0.04419543
## USYes        0.69151957  1.70776632

Problem 10g

par(mfrow=c(2,2))
plot(carseats2)

There does appear to be one high-leverage point and a few named points that could possibly be outliers.

rstudent(carseats2)[which(rstudent(carseats2)>=3)]
## named numeric(0)
rstudent(carseats2)[order(rstudent(carseats2), decreasing = T)][1:3]
##      377       69       26 
## 2.891521 2.642364 2.599652

The highest rstduent values are still under 3, meaning that they are likely not outliers.

hatvalues(carseats2)[which(hatvalues(carseats2)>=0.04)]
##         43 
## 0.04333766
hatvalues(carseats2)[order(hatvalues(carseats2), decreasing = T)][1]
##         43 
## 0.04333766

Observation 43 appears to be a high-leverage point.

Problem 12a

The inverse function would still have the same numerator. Therefore, the only way the Y~X and X~Y would be the same is if the denominators were the same. In order for the denominators to be the same, the sum of squares would have to be the same for both x and y.

Problem 12b

set.seed(118899)
x <- rnorm(100)
head(x)
## [1]  0.8603984 -0.9067076 -0.9196529 -1.3193413  0.7636590 -1.0923197
set.seed(998811)
y1 <- 3.4*x + rnorm(100,0,1)
head(y1)
## [1]  2.0556230 -2.5141623 -3.8314505 -5.3120112  0.9522532 -3.4434890
lmy1x <- lm(y1~x)
summary (lmy1x)
## 
## Call:
## lm(formula = y1 ~ x)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.60344 -0.67417  0.03659  0.62670  2.68131 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  0.10978    0.10242   1.072    0.286    
## x            3.28433    0.09939  33.046   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.024 on 98 degrees of freedom
## Multiple R-squared:  0.9176, Adjusted R-squared:  0.9168 
## F-statistic:  1092 on 1 and 98 DF,  p-value: < 2.2e-16
lmxy1<- lm(x~y1)
summary(lmxy1)
## 
## Call:
## lm(formula = x ~ y1)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -0.98527 -0.17722  0.02145  0.16763  0.69975 
## 
## Coefficients:
##              Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -0.031487   0.029878  -1.054    0.295    
## y1           0.279402   0.008455  33.046   <2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 0.2987 on 98 degrees of freedom
## Multiple R-squared:  0.9176, Adjusted R-squared:  0.9168 
## F-statistic:  1092 on 1 and 98 DF,  p-value: < 2.2e-16

Problem 12c

y2 <- sample(x,100)
head(y2)
## [1]  0.01073568 -0.61294029  1.42286511 -1.10156519 -0.07048174 -1.07413785
lmy2x <- lm(y2~x)
summary (lmy2x)
## 
## Call:
## lm(formula = y2 ~ x)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.86658 -0.60622 -0.07885  0.63862  2.70095 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0098744  0.1040965  -0.095    0.925
## x           -0.0004983  0.1010152  -0.005    0.996
## 
## Residual standard error: 1.041 on 98 degrees of freedom
## Multiple R-squared:  2.483e-07,  Adjusted R-squared:  -0.0102 
## F-statistic: 2.434e-05 on 1 and 98 DF,  p-value: 0.9961
lmxy2 <- lm(x~y2)
summary (lmxy2)
## 
## Call:
## lm(formula = x ~ y2)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -2.86634 -0.60607 -0.07908  0.63794  2.70023 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)
## (Intercept) -0.0098744  0.1040965  -0.095    0.925
## y2          -0.0004983  0.1010152  -0.005    0.996
## 
## Residual standard error: 1.041 on 98 degrees of freedom
## Multiple R-squared:  2.483e-07,  Adjusted R-squared:  -0.0102 
## F-statistic: 2.434e-05 on 1 and 98 DF,  p-value: 0.9961