0% found this document useful (0 votes)
4 views7 pages

Tutorial 01 Soln

The document provides solutions to various statistical problems involving datasets related to alcohol prices, cirrhosis deaths, and wine prices. It includes analyses using R/Python for linear regression models, scatter plots, and discussions on the relationships between variables. Key findings include the fitted equations for models and the evaluation of model adequacy based on residuals and R-squared values.

Uploaded by

Jaye Lin Yeo
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)
4 views7 pages

Tutorial 01 Soln

The document provides solutions to various statistical problems involving datasets related to alcohol prices, cirrhosis deaths, and wine prices. It includes analyses using R/Python for linear regression models, scatter plots, and discussions on the relationships between variables. Key findings include the fitted equations for models and the evaluation of model adequacy based on residuals and R-squared values.

Uploaded by

Jaye Lin Yeo
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

ST3131

Tutorial 1 Solution

1. We have a dataset [Link] that contains information on seven European countries regarding two
continuous variables:
X = the price of alcohol relative to take-home pay, the explanatory random variable.
Y = cirrhosis deaths per 100,000 of populations, the response variable.
2

Use R/Python to answer these questions.


(a) Plot Y versus X and comment on the relationship, using the scatter plot.
2

(b) Fit a simple linear regression model, and write down the tted equation.
(c) Estimate the mean cirrhosis of deaths for a country with relative price of alcohol equal to 0.05
using the tted model in 1b.
Solution: The solution is provided using R code.
(a) It suggests that there is a decreasing relationship. It appears that an increase in cost of alcohol is
associated with a reduced number of death by liver cirrhosis. It is hard to tell if the relationship is
linear or non-linear in this case, because of the small dataset. Due to the small number of points,
it is also dicult to judge if the variance is constant at all X -values.

Figure 1: Scatteplotof X vs Y 2
(b) From the R output, the tted equation is given by
Ŷ = 38.067 − 358.249X

where X = relative alcohol price.


(c) Ŷ = 38.067 − 358.249 × 0.05 = 20.15.

1
ST3131

2. Consider the 3 datasets contained in three_dataset.csv where X1 is the regressor and Y 1, Y 2, Y 3


are the three possible responses. The scatter plots are given below.
(a) Using R/Python, let Y 1, Y 2, Y 3 be the responses and X1 be the regressor, form the three linear
models, and verify that the three tted models are about the same.
(b) Verify that the three tted model have the same R = 0.667.
2

(c) Produce the scatter plots for these 3 data sets (as given in Figure 2). Would you consider the
above regression models to be equally valid for these datasets?

Solution:
(a) The tted models for the three data are about the same:
Ŷ = 3 + 0.5X

(b) From R output, indeed the R = 0.67 for all 3 tted models.
2

(c) Data set 1: the regression line appears to be ne with the scatter plot.
Data set 2: Scatter plot shows some curvature in X , indicating that probably an X term added
2

to the model might be better.


Data set 3 has a point that looks like it might be an outlier or an inuential point which can pull
the straight line toward it, which needs to be investigated more. Hence the tted model above
may not be a good model for the data set 3.
3. Our dataset [Link] contains y  the prices for vintage bottles of port (a kind of wine)
and x  their age (in years) of each bottle. Use it to answer the questions that follow.
(a) Inspect the scatter plot and comment on the relationship between the response (price) and the
explanatory variable (age).
(b) Consider variable z = ln(y). Create a scatter plot of z against x and give your comments.
(c) Write R code to form two simple linear regression models: Model M1 is y ∼ x, model M2 is z ∼ x.
Write the equation for each tted model.
(d) Report R of each model.
2

2
ST3131

Solution:
(a) The scatter plot is in Figure [Link] appears that there is a positive relationship between price
and age. It suggests that as the age of a bottle of port increases, so too does its price.
The relationship looks close to linear, but once again, we are unable to determine if the
variance is constant due to the small number of points.

Figure 2: Scatterplot of Price against Age


(b) Consider variable z = ln(y). The scatter plot of ln(Price) against Age is given in Figure 3.
There is a positive relationship between ln(Price) and Age where the linearity is clearer compared
to the plot of Price and Age in Figure 2. Besides, the stability in variance of ln(Price) when Age
changes is clearer too.
Compared to Price, it could be better if we t a linear model where ln(Price) be the response.

3
ST3131

Figure 3: Scatterplot of Log(Price) against Age


(c) Write R code to t 2 models.
> data3<- [Link]("~/Documents/Data/[Link]")
> data3$Z = log(data3$Price)
> M1<- lm(Price~ age, data = data3)
> summary(M1)
Call:
lm(formula = Price ~ age, data = data3)

Residuals:
Min 1Q Median 3Q Max
-5.6221 -2.1159 -0.1214 1.9000 6.5748

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -8.22108 2.14176 -3.838 0.00236 **
age 0.62983 0.05198 12.117 4.34e-08 ***
---
Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1

Residual standard error: 3.797 on 12 degrees of freedom


Multiple R-squared: 0.9244, Adjusted R-squared: 0.9181
F-statistic: 146.8 on 1 and 12 DF, p-value: 4.341e-08

4
ST3131

> ############## M2
> M2<- lm(Z~ age, data = data3)
> summary(M2)
Call:
lm(formula = Z ~ age, data = data3)

Residuals:
Min 1Q Median 3Q Max
-0.32405 -0.08294 0.04127 0.12533 0.27310

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 1.143891 0.113931 10.04 3.43e-07 ***
age 0.034652 0.002765 12.53 2.98e-08 ***
---
Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1

Residual standard error: 0.202 on 12 degrees of freedom


Multiple R-squared: 0.929, Adjusted R-squared: 0.9231
F-statistic: 157 on 1 and 12 DF, p-value: 2.978e-08

The equation of the tted model M1 is:


Price
d ) = −8.221 + 0.629 × Age.

The equation of the tted model M2 is:


price) = 1.144 + 0.0347 × Age.
ln(d

(d) Report R of each model.


2

R of M1 is 0.9244 while R of M2 is 0.929. R of model M2 is slightly larger.


2 2 2

Comments: We have NOT done the steps to check the adequacy of each model, hence, we cannot
comment which model is more adequate/better.
However, if we expect the errors of a linear model to be uncorrelated and to follow a normal
distribution, then model M2 is better. This is because the plot of raw residuals against the tted
values of model M1 seems not as random as that of model M2 which is shown in Figure 3.

5
ST3131

Figure 4: Residualplots for model M1 (left) and M2 (right).

4. A data set is collected with n observations, (x , y ), ..., (x , y ). A simple linear model y = β + β x + ϵ


is tted using the data set above by OLS method. The equation of the tted model is derived as given
1 1 n n 0 1

below
ŷ = β̂0 + β̂1 x

where β̂ and β̂ are the estimators of β and β by OLS method. Prove that:
0 1 0 1

(a) P y = P ŷ , or equivalently P e = 0 where e = y − ŷ , i = 1, ...n.


n
i=1 i
n
i=1 i
n
i=1 i i i i

(b) P x e = 0.
n
i=1 i i

(c) P ŷ e = 0.
n
i=1 i i

Solution:
(a)
n
X n
X n
X n
X
ei = (yi − ŷi ) = yi − ŷi
i=1 i=1 i=1 i=1
n
X n
X
= yi − (β̂0 + β̂1 xi )
i=1 i=1
Xn n
X
= yi − n β̂0 − β̂1 xi
i=1 i=1

Since β̂ and β̂ are the estimators of β and β by OLS method, they satised the least-squares
normal equations shown in Slide 21/57 of Topic 1 - Description Part. As such, from the rst
0 1 0 1

least-squares normal equations, we have P e = 0. n


i=1 i

6
ST3131

(b)
n
X n
X
xi ei = xi (yi − ŷi )
i=1 i=1
Xn
= xi (yi − β̂0 − β̂1 xi )
i=1
Xn n
X n
X
= xi yi − xi β̂0 − β̂1 x2i
i=1 i=1 i=1
n
X n
X n
X
= xi yi − β̂0 xi − β̂1 x2i
i=1 i=1 i=1

Since β̂ and β̂ are the estimators of β and β by OLS method, they satised the least-squares
normal equations shown in Slide 21/57P of Topic 1 - Description Part. As such, from the second
0 1 0 1

least-squares normal equations, we have x e = 0. n


i=1 i i

(c)
n
X n
X
ŷi ei = (β̂0 + β̂1 xi )ei
i=1 i=1
n
X n
X
= β̂0 ei + β̂1 xi ei
i=1 i=1
n
X n
X
= β̂0 ei + β̂1 xi ei
i=1 i=1
= 0 + 0 = 0.

You might also like