Regression analysis For Example 11.6 in notes:

 

> x<-c(38.2, 40.0, 42.5, 43.4, 44.6, 44.9, 45.0, 45.4,46.0,47.3,47.3,48.0,49.1,50.5,51.6)

> y<-c(8.9,13.0,4.7,-2.4,12.5,18.4,6.6,13.5,8.5,15.3,18.9,6.0,10.4, 15.9,17.1)

> plot(y,x)

> cor(y,x)

[1] 0.3832905

> d<-data.frame(cbind(y,x)) %% Creating a data  frame object

> d

      y    x

1   8.9 38.2

2  13.0 40.0

3   4.7 42.5

4  -2.4 43.4

5  12.5 44.6

6  18.4 44.9

7   6.6 45.0

8  13.5 45.4

9   8.5 46.0

10 15.3 47.3

11 18.9 47.3

12  6.0 48.0

13 10.4 49.1

14 15.9 50.5

15 17.1 51.6

> regout=lm(y~1+x,d) %% first part is the formula, second part is the data frame to be used, see more about formulas in page 50 of the R-intro file

> qqnorm(regout$res)

> qqline(regout$res)

> plot(x,regout$fitted)

 

> coef(regout)   %%%%%%%%%%%%% more operations on the fitted model in more about formulas in page 53 of the R-intro file

(Intercept)           x

-16.9910445   0.6173818

> beta<-coef(regout)

> beta

(Intercept)           x

-16.9910445   0.6173818

> deviance(regout) %%gives RSS

[1] 412.6025

> formula(regout)

y ~ 1 + x

> plot(regout)

Hit <Return> to see next plot:

Hit <Return> to see next plot:

Hit <Return> to see next plot:

Hit <Return> to see next plot:

> reg.aov<-aov(y~x,d)

> summary(reg.aov)

                        Df        Sum Sq            Mean Sq          F value             Pr(>F)

x                      1          71.05               71.05               2.2387             0.1585

Residuals          13        412.60             31.74              

> summary(regout)

 

Call:

lm(formula = y ~ 1 + x, data = d)

 

Residuals:

    Min      1Q  Median      3Q     Max

-12.203  -3.557   1.956   2.775   7.671

 

Coefficients:

                        Estimate           Std. Error         t value              Pr(>|t|)

(Intercept)        -16.9910          18.8662           -0.901              0.384

x                      0.6174              0.4126            1.496               0.158

 

Residual standard error: 5.634 on 13 degrees of freedom

Multiple R-Squared: 0.1469,     Adjusted R-squared: 0.08129

F-statistic: 2.239 on 1 and 13 DF,  p-value: 0.1585

 

>