In: Statistics and Probability
# this code is done
in R statistical software
library(alr4)
data =
ftcollinstemp
####
2.6.1 ####
plot(data$fall,
data$winter)
# plot is in 2.6.2
part
# from
the plot we can see that their is
# no
linear relationship between average fall
tempreature
# and
average winter temprature
####
2.6.2 ####
model
= lm(winter
~
fall,
data
= data)
summary(model)
##
## Call:
## lm(formula = winter ~
fall, data = data)
##
## Residuals:
##
Min 1Q
Median 3Q
Max
## -7.8186 -1.7837 -0.0873
2.1300 7.5896
##
##
Coefficients:
##
Estimate Std. Error t value Pr(>|t|)
## (Intercept)
13.7843 7.5549
1.825 0.0708 .
##
fall
0.3132 0.1528 2.049
0.0428 *
## ---
## Signif. codes: 0 '***'
0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error:
3.179 on 109 degrees of freedom
## Multiple R-squared:
0.0371, Adjusted R-squared: 0.02826
## F-statistic:
4.2 on 1 and 109 DF, p-value: 0.04284
abline(model)
# in the above
summary we can see that the P-value corresponding
to
# fall
is 0.0428 which is not that significant. That is if we take alpha =
0.01
# we
will fail to reject H0 that implies that the predictor fall is not
significant
####
2.6.3 ####
R_square
= summary(model)$r.squared;R_square
## [1] 0.03709854
# the R_square
value is 0.03709854 that implies that approximately
3.7%
# of
the variablity of average winter temprature is explained by
average
# fall
temprature
####
2.6.4 ####
data1
= data[1:90,
]
data2
= data[90:length(data$year),
]
model1
= lm(winter
~
fall,
data
= data1)
summary(model1)
##
## Call:
## lm(formula = winter ~
fall, data = data1)
##
## Residuals:
##
Min 1Q
Median 3Q
Max
## -6.8976 -1.6349 0.0118
2.0079 7.3387
##
##
Coefficients:
##
Estimate Std. Error t value Pr(>|t|)
## (Intercept)
22.7079 8.2600 2.749 0.00725
**
##
fall
0.1209 0.1681 0.719
0.47397
## ---
## Signif. codes: 0 '***'
0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error:
3.057 on 88 degrees of freedom
## Multiple R-squared:
0.005842, Adjusted R-squared: -0.005455
## F-statistic: 0.5171 on 1
and 88 DF, p-value: 0.474
model2 =
lm(winter
~
fall,
data
= data2)
summary(model2)
##
## Call:
## lm(formula = winter ~
fall, data = data2)
##
## Residuals:
##
Min 1Q
Median 3Q
Max
## -5.4731 -1.4740 0.0786
1.9299 4.9411
##
##
Coefficients:
##
Estimate Std. Error t value Pr(>|t|)
## (Intercept)
25.9511 16.9685
1.529 0.142
##
fall
0.1161 0.3341
0.348 0.732
##
## Residual standard error:
2.636 on 20 degrees of freedom
## Multiple R-squared:
0.006004, Adjusted R-squared: -0.0437
## F-statistic: 0.1208 on 1
and 20 DF, p-value: 0.7318
# we can see from
the summary there is not much difference in the R_square
also
# the
variable fall is not significant to explain winter
temprature