0% found this document useful (0 votes)
9 views10 pages

CS1B CH 11 Exercises V02

The document contains exercises related to linear regression, specifically using baby weight data and growth data. It includes tasks such as fitting models, obtaining parameters, plotting graphs, and performing statistical tests. The exercises are designed to reinforce skills in data analysis using R programming.

Uploaded by

Michael Barasa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

CS1B CH 11 Exercises V02

The document contains exercises related to linear regression, specifically using baby weight data and growth data. It includes tasks such as fitting models, obtaining parameters, plotting graphs, and performing statistical tests. The exercises are designed to reinforce skills in data analysis using R programming.

Uploaded by

Michael Barasa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

CS1B-11: Linear Regression – Exercises Page 1

11
Linear Regression
Exercises

The Actuarial Education Company © IFE: 2019 Examinations


Page 2 CS1B-11: Linear Regression – Exercises

Data requirements
These exercises require the following data file:

• baby weights.txt
• growth.csv

© IFE: 2019 Examinations The Actuarial Education Company


CS1B-11: Linear Regression – Exercises Page 3

Exercise 11.01
There is currently no Exercise 11.01.

However, you may wish to revisit the exercises from the data analysis chapter if it has been a
while since you looked at them. The exercises in this chapter will assume you are able to recall
and use the R code from that chapter.

The Actuarial Education Company © IFE: 2019 Examinations


Page 4 CS1B-11: Linear Regression – Exercises

Exercise 11.02
A new computerised ultrasound scanning technique has enabled doctors to monitor the weights
of unborn babies. The table below shows the estimated weights for one particular baby at
fortnightly intervals during the pregnancy.

Gestation period (weeks) 30 32 34 36 38 40

Estimated baby weight (kg) 1.6 1.7 2.5 2.8 3.2 3.5

This data is contained in the file: ‘baby weights.txt’

(i) (a) Load the data in the file ‘baby weights.txt’, and store it in the data frame baby.

(b) Fit a linear regression model, model1, of weight on gestation period.

(ii) (a) Obtain the slope and intercept parameters.

(b) Plot a labelled scattergraph of the data and add a red dashed regression line onto
your scatterplot.

(iii) Obtain the fitted values:

(a) by extracting them from model1

(b) using the fitted command

(c) using the predict command.

(iv) Add blue points to the scatterplot to show the fitted values.

(v) Obtain the expected baby’s weight at 42 weeks (assuming it hasn’t been born by then):

(a) from first principles by extracting the coefficients from model1

(b) using the predict function.

© IFE: 2019 Examinations The Actuarial Education Company


CS1B-11: Linear Regression – Exercises Page 5

Exercise 11.03
This question uses the ‘baby weights’ linear regression model, model1, of weight on gestation
period, created in an earlier exercise.

(i) Obtain the total sum of squares in the baby weights model together with its split between
the residual sum of squares and the regression sum of squares:

(a) using the ANOVA command

(b) from first principles using the functions sum, mean, fitted and residuals.

(ii) Obtain the coefficient of determination, R2 , from the:

(a) linear regression model, model1

(b) correlation coefficient

(c) by calculation from the values in the ANOVA table.

(iii) Obtain the correlation coefficient from the extracted coefficient of determination.

The Actuarial Education Company © IFE: 2019 Examinations


Page 6 CS1B-11: Linear Regression – Exercises

Exercise 11.04
This question uses the ‘baby weights’ linear regression model, model1, of weight on gestation
period, created in an earlier exercise.

(i) Obtain the statistic and p-value for a test of H0 : β = 0 vs H1 : β ≠ 0 .

(ii) Use confint to:

(a) obtain a 99% confidence interval for the slope parameter

(b) test, at the 5% level, whether β = 0.24 .

(iii) Extract the estimated value of beta, the standard error of beta and the degrees of
freedom and store them in the objects b, se and dof.

(iv) Using the objects created in part (iii), use a first principles approach to:

(a) obtain a 90% confidence interval for the slope parameter.

(b) obtain the statistic and p-value for a test of H0 : β = 0.25 vs H1 : β < 0.25 .

(c) obtain the statistic and p-value for a test of H0 : β = 0.18 vs H1 : β ≠ 0.18 .

© IFE: 2019 Examinations The Actuarial Education Company


CS1B-11: Linear Regression – Exercises Page 7

Exercise 11.05
This question uses the ‘baby weights’ linear regression model, model1, of weight on gestation
period, created in an earlier exercise.

(i) Obtain the results of an F-test to test the ‘no linear relationship’ hypothesis using the:

(a) anova command

(b) summary command.

(ii) Calculate the F statistic and p-value from first principles by extracting the mean sum of
squares and degrees of freedom from the ANOVA table.

(iii) Obtain a 95% confidence interval for the error variance, σ 2 , from first principles.

The Actuarial Education Company © IFE: 2019 Examinations


Page 8 CS1B-11: Linear Regression – Exercises

Exercise 11.06
This question uses the ‘baby weights’ linear regression model, model1, of weight on gestation
period, created in an earlier exercise.

(i) Estimate the mean weight of a baby at 33 weeks:

(a) from first principles by extracting the coefficients from model1.

(b) using the predict function.

(ii) Obtain a 90% confidence interval for the:

(a) mean weight of a baby at 33 weeks.

(b) weight of an individual baby at 33 weeks.

(iii) Obtain the estimated mean weight of a baby at 0 weeks:

(a) from the model1 parameters

(b) using the predict function,

and comment on the value obtained.

(iv) Obtain a 99% confidence interval for the mean weight of a baby at 0 weeks:

(a) using the confint function

(b) using the predict function.

(v) In one go, use the predict function to obtain:

(a) the mean weights of babies at 20, 21, 22, 23, 24 weeks

(b) 95% confidence intervals for the mean weight of a baby at 20, 21, 22, 23, 24
weeks.

© IFE: 2019 Examinations The Actuarial Education Company


CS1B-11: Linear Regression – Exercises Page 9

Exercise 11.07
This question uses the ‘baby weights’ linear regression model, model1, of weight on gestation
period, created in an earlier exercise.

(i) Obtain the residuals for the regression model:

(a) from first principles using the fitted command

(b) using the residuals function.

(ii) (a) Obtain a plot of the residuals against the fitted values.

(b) Comment on the constancy of the variance and whether a linear model is
appropriate.

(iii) (a) Obtain a Q-Q plot of the residuals.

(b) Comment on the normality assumption.

(iv) Examine the final two graphs obtained by plot(model1) and comment.

The Actuarial Education Company © IFE: 2019 Examinations


Page 10 CS1B-11: Linear Regression – Exercises

Exercise 11.08
Part (i) of this question uses the ‘baby weights’ linear regression model, model1, of weight on
gestation period, created in an earlier exercise.

(i) (a) Obtain a new linear regression model, model2, based on the data without the
second data point (gestation of 32 weeks).

(b) By examining the new value of R2 comment on the fit of model2 compared to
that of model1 which had R2 = 0.9689 .

The table below shows the results from a growth experiment:

x 1 2 3 4 5 6 7 8 9 10

y 0.33 0.51 0.75 1.16 1.90 2.59 5.14 7.39 11.3 17.4

This data is contained in the csv file: ‘growth’

(ii) It is thought that a suitable model is y = aebxi +ei .

(a) Load the csv file and store it in the data frame growth.

(b) Obtain a scatterplot of y vs x and comment whether a linear model is appropriate


for these data.

(c) Obtain a scatterplot of lny vs x and comment whether a linear model is


appropriate for this transformation.

(iii) Fit a linear regression model, model3, of ln yi on x .

(iv) (a) Obtain estimates for the slope and intercept parameters for model3.

(b) Add a red dashed regression line to your scatterplot of lny vs x from part (ii)(c).

(v) (a) Use part (iv)(a) to obtain estimates for a and b .

(b) Re-plot the scatterplot of y vs x and this time add blue points to the scatterplot
to show the fitted values of y using model3.

(c) Add a dashed red regression curve that passes through the fitted points.

(vi) Obtain a 95% confidence interval for the mean value of y when x = 8.5 .

© IFE: 2019 Examinations The Actuarial Education Company

You might also like