Lab 3
Toluca Company Example (Section 1.6)
> data<-read.table("/afs/umich.edu/user/k/u/kutsyy/Public/html/classes/ALSM/CH01TA01.DAT")
> y<-data[,1]
> x<-data[,2]
> fit<-lm(y~x)
> summary(fit)

Call: lm(formula = y ~ x)
Residuals:
    Min     1Q Median    3Q   Max
 -30.96 -9.811  2.346 5.337 20.63

Coefficients:
               Value Std. Error  t value Pr(>|t|)
(Intercept)  -1.8583   7.4105    -0.2508   0.8042
          x   0.2301   0.0224    10.2896   0.0000

Residual standard error: 12.4 on 23 degrees of freedom
Multiple R-Squared: 0.8215
F-statistic: 105.9 on 1 and 23 degrees of freedom, the p-value is 4.449e-10

Correlation of Coefficients:
  (Intercept)
x -0.9424
> fit$coef
 (Intercept)         x
   -1.858251 0.2301084
> y-fit$coef[1]-fit$coef[2]*x
 [1]  -9.9550004   4.0151347   1.0042947   5.3374928 -11.2108812  10.3139695
 [7]  -3.7809352   0.8600944  20.6299860  15.7312323   5.0409071  13.8709344
[13]   2.3460836  -4.1439981  11.7610972   5.2127232 -16.9247297  -9.8108000
[19]   5.1073844  14.9826148 -30.9613420 -15.8324800 -14.2881985   3.1611784
[25]  -2.4667620
> e<-fit$res
> e
      1        2        3        4         5        6         7         8
 -9.955 4.015135 1.004295 5.337493 -11.21088 10.31397 -3.780935 0.8600944
        9       10       11       12       13        14      15       16
 20.62999 15.73123 5.040907 13.87093 2.346084 -4.143998 11.7611 5.212723
        17      18       19       20        21        22       23       24
 -16.92473 -9.8108 5.107384 14.98261 -30.96134 -15.83248 -14.2882 3.161178
        25
 -2.466762
> motif()
> boxplot(e)
> plot(e)
> plot(e,type="l")
> plot(x,y)
> abline(fit$coef)
> fit$coef
 (Intercept)         x
   -1.858251 0.2301084
> fit$coef[1]+fit$coef[2]*x
 [1]  89.95500  25.98487  48.99571  84.66251  81.21088  49.68603 123.78094
 [8]  79.13991  79.37001  34.26877  34.95909  56.12907  87.65392  24.14400
[15]  98.23890  94.78728  46.92473  59.81080  84.89262  95.01739  60.96134
[22] 105.83248  54.28820  76.83882  72.46676
> fit$fitted
      1        2        3        4        5        6        7        8
 89.955 25.98487 48.99571 84.66251 81.21088 49.68603 123.7809 79.13991
        9       10       11       12       13     14      15       16       17
 79.37001 34.26877 34.95909 56.12907 87.65392 24.144 98.2389 94.78728 46.92473
      18       19       20       21       22      23       24       25
 59.8108 84.89262 95.01739 60.96134 105.8325 54.2882 76.83882 72.46676
> plot(x,fit$fitted)
> cor(fit$res,fit$fit)
[1] -1.503521e-08
> cor(x,y)^2
[1] 0.8215334
> summary(fit)

Call: lm(formula = y ~ x)
Residuals:
    Min     1Q Median    3Q   Max
 -30.96 -9.811  2.346 5.337 20.63

Coefficients:
               Value Std. Error  t value Pr(>|t|)
(Intercept)  -1.8583   7.4105    -0.2508   0.8042
          x   0.2301   0.0224    10.2896   0.0000

Residual standard error: 12.4 on 23 degrees of freedom
Multiple R-Squared: 0.8215
F-statistic: 105.9 on 1 and 23 degrees of freedom, the p-value is 4.449e-10

Correlation of Coefficients:
  (Intercept)
x -0.9424
> sqrt(var(e))
[1] 12.13404

Problem 1.20
a)
>data<-read.table("/afs/umich.edu/user/k/u/kutsyy/Public/html/classes/ALSM/CH01PR20.DAT")
>data
    V1 V2
 1  97  7
 2  86  6
 3  78  5
 4  10  1
 5  75  5
 6  62  4
 7 101  7
 8  39  3
 9  53  4
10  33  2
11 118  8
12  65  5
13  25  2
14  71  5
15 105  7
16  17  1
17  49  4
18  68  5
> motif()
> fit<-lm(V1~V2, data=data)
> summary(fit)
Call: lm(formula = V1 ~ V2, data = data)
Residuals:
    Min    1Q  Median    3Q   Max
 -7.631 -3.25 -0.2383 4.023 6.631
Coefficients:
               Value Std. Error  t value Pr(>|t|)
(Intercept)  -2.3221   2.5644    -0.9055   0.3786
         V2  14.7383   0.5193    28.3834   0.0000
Residual standard error: 4.482 on 16 degrees of freedom
Multiple R-Squared: 0.9805
F-statistic: 805.6 on 1 and 16 degrees of freedom, the p-value is 4.108e-15
Correlation of Coefficients:
   (Intercept)
V2 -0.9112
b)
> plot(data$V2,data$V1)
> abline(fit$coef)
c)
b0 is intercept
d)
> x0<-c(1,5)
> x0%*%fit$coef
         [,1]
[1,] 71.36913
> fit$coef[1]+fit$coef[2]*5
 (Intercept)
    71.36913