Help in R studio task

Hello,
I wonder if it is possible for you to check what I have done here to check for any obvious errors etc., please?
Kind regards

Question 1

  1. An investigator was interested in studying the relation between 𝑦𝑑, π‘₯1𝑑 and π‘₯2𝑑. Use R to estimate the linear regression model
    𝑦𝑑= 𝛽0+𝛽1π‘₯1𝑑+𝛽2π‘₯2𝑑+𝑣𝑑 (1)
    and test the null hypothesis that 𝛽2=1.5. Make sure to show the details of your work.

Given regression model:

Where:
yt = The excess returns on a stock.
And two x variables:
x1t = The change in money supply
x2t = The excess returns on the market

Steps I made:

Estimating the linear regression model
Read the data in the R software
Remove missing data
Assign each column a variable
Estimate linear regression model

Note: Refined data has 180 observations meaning T=180

#Read in the data
assignment_data1 = read.csv("C:/Uv")

#Remove missing data
assignment_data = na.omit(assignment_data1)

#Assigning variables
x1t = assignment_data[,2]
x2t = assignment_data[,3]
yt = assignment_data[,4]

#Estimation of linear regression model
estlrm = lm(yt~x1t+x2t, anscombe)

#Estimation results
summary(estlrm)
Outcome
Call:
lm(formula = yt ~ x1t + x2t, data = anscombe)

Residuals:
Min 1Q Median 3Q Max
-66.681 -3.519 2.178 7.097 23.886

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.7290 1.1138 -1.552 0.1224
x1t -1.7614 0.9433 -1.867 0.0635 .
x2t 1.4441 0.2617 5.518 1.2e-07 ***

Signif. codes: 0 β€˜β€™ 0.001 β€˜β€™ 0.01 β€˜β€™ 0.05 β€˜.’ 0.1 β€˜ ’ 1

Residual standard error: 14.8 on 177 degrees of freedom
Multiple R-squared: 0.1655, Adjusted R-squared: 0.156
F-statistic: 17.55 on 2 and 177 DF, p-value: 1.115e-07

Results

The excess returns on stock is described by:
yt = -1.7290 – 1.7614x1t + 1.444x2t + vt

According to adjusted R-squared, 15.6% of the variation in the excess returns on stock is explained by the fitted model. Changes in money supply, x1t, have a β€˜-1.7614’ negative effect on the excess returns on the stock where the excess returns on the market, x2t, have a β€˜1.444’ positive effect.

Hypothesis Test

The hypotheses are: H0: 𝛽2 = 1.5, H1: 𝛽2 β‰  1.5
The model has 3 coefficients so: k = 3
T = 180
T-statistic:
t-statistic = ((Ξ²_2 ) Μ‚-1.5)/(SE((Ξ²_2 ) Μ‚))= (1.44-1.5)/0.943= -0.06362672~ t180-3

test = (1.44-1.5)/0.943
test
[1] -0.06362672
T_k=180-3
pvalue=pt(test,T_k)+1 -pt(-test, T_k)
pvalue
[1] 0.9493393

Outcome
p-value equal to 0.9493393
p-value > 5%
Null hypothesis rejected
𝛽2 β‰  1.5 at the 5% level
Interpretation: A unit change in money supply will not change the excess returns on a stock by 2 units at the 5% level of significance.

Question 2
The investigator then checked the homoskedasticity in the residuals of model (1). Provide a detailed account of the White’s test for homoskedasticity and use R to illustrate your answer by examining possible homoskedasticity in model (1) at the 1% level of significance.

Unrestricted model

From question 1: yt = -1.7290 – 1.7614x1t + 1.444x2t + vt
Check assumption
π‘―πŸŽ:𝑽(𝒖𝒕)=𝝈𝟐
π‘―πŸ:𝑽( 𝒖𝒕)β‰ πˆπŸ

Calculate the residual series v Μ‚t and v Μ‚t2 

#Residual series
vt=estlrm$residuals
vt2=vtvt
Estimation of secondary regression for the White’s test for homoskedasticity
ΞΌ Μ‚_t^2= Ξ±1 + 𝛼2π‘₯2𝑑+𝛼3π‘₯3𝑑+𝛼4π‘₯2𝑑2+𝛼5π‘₯23𝑑+𝛼6π‘₯2𝑑π‘₯3𝑑+𝑒𝑑
k’ = 6
m = k’ – 1 = 5
srm = lm (yt~x1t
x2t+(x1t^2)+(x2t^2))
summary(srm)
Call:
lm(formula = yt ~ x1t * x2t + (x1t^2) + (x2t^2))
Residuals:
Min 1Q Median 3Q Max
-65.387 -2.861 1.623 6.825 25.571

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.7199 1.1126 -1.546 0.1240
x1t -2.0984 0.9845 -2.131 0.0344 *
x2t 1.5513 0.2767 5.605 7.9e-08 ***
x1t:x2t 0.3002 0.2542 1.181 0.2392

Signif. codes: 0 β€˜β€™ 0.001 β€˜β€™ 0.01 β€˜β€™ 0.05 β€˜.’ 0.1 β€˜ ’ 1

Residual standard error: 14.79 on 176 degrees of freedom
Multiple R-squared: 0.172, Adjusted R-squared: 0.1579
F-statistic: 12.19 on 3 and 176 DF, p-value: 2.758e-07

Calculate test statistic

R2= 0.172
T= 177 + 3 = 180
T * R2 = 180 * 0.172 = 30.96 ~Xm2
m = 9 , T = 180
p-value = 2.758e-07 > 1%
Do not reject 𝐻0:𝑉(𝑒𝑑)=𝜎2 at 1% level of significance
Meaning: ut is a constant, the assumption of constant variance of ut is satisfied.
Question 3
The investigator also checked whether π‘₯2𝑑 β€œGranger-causes” 𝑦𝑑. Use R to perform the Granger causality test (with order = 4) to complete this task and show the detailed work of your analysis at the 5% level of significance.

Estimated original model from question 1: yt = -1.7290 – 1.7614x1t + 1.444x2t + vt
Unrestricted and restricted models 

Unrestricted model:
𝑦𝑑=βˆ‘_(j=1)^nβ–’βˆj yt-j + βˆ‘_(i=1)^mβ–’Ξ²i zt-i + 𝐷𝑑+πœ€π‘‘
Restricted model:
𝑦𝑑=βˆ‘_(j=1)^nβ–’βˆj yt-j + 𝐷𝑑+πœ€π‘‘
Granger causality test
𝐻0: x2t does not Granger cause 𝑦𝑑
𝐻1: x2t does Granger cause 𝑦𝑑

grangertest(yt~x2t,order=4)
Granger causality test

Model 1: yt ~ Lags(yt, 1:4) + Lags(x2t, 1:4)
Model 2: yt ~ Lags(yt, 1:4)
Res.Df Df F Pr(>F)
1 167
2 171 -4 1.3048 0.2703

Results
Test statistic = 1.3048
p-value = 0.2703 > 5% => not rejected 𝐻0
There is no unidirectional causality from x2t to yt
Meaning: 

Changes in the excess returns on the market does not Granger Cause changes of the excess return on the stock. Past values of the excess returns on the market cannot be used to predict the excess return on the stock.

Question 4
In addition to the methods used in the first three questions, you have also learnt several other methods in this module, which can also be used to analyse the data. Choose one of these methods, provide a detailed account of the selected method, explain why the selected method is suitable for analysing the data, and use software R to illustrate your results. (Note: It is not necessary to use all variables in the data set for this question.)

Method used: DF-GLS test

Test statistic: 𝜏=Ξ³ Μ‚/(SE((Ξ³) Μ‚)')
Estimated model: Δ𝑦𝑑𝑑=𝛾𝑦𝑑-1d+Ξ£pi=1 𝛿iΔ𝑦 d π‘‘βˆ’π‘– +πœ€π‘‘
Conduct test on the excess returns on a stock data for possible unit root and non-stationary
DF-GLS test

testyr=ur.ers(yt,model="trend",lag.max=12)
summary(testyr)

###############################################

Elliot, Rothenberg and Stock Unit Root Test

###############################################

Test of type DF-GLS
detrending of series with intercept and trend

Call:
lm(formula = dfgls.form, data = data.dfgls)

Residuals:
Min 1Q Median 3Q Max
-63.544 -6.369 0.601 7.631 25.733

Coefficients:
Estimate Std. Error t value Pr(>|t|)
yd.lag -1.52852 0.42435 -3.602 0.000425 ***
yd.diff.lag1 0.35778 0.40630 0.881 0.379916
yd.diff.lag2 0.28591 0.38231 0.748 0.455691
yd.diff.lag3 0.28585 0.35561 0.804 0.422735
yd.diff.lag4 0.07563 0.32656 0.232 0.817151
yd.diff.lag5 -0.05515 0.30005 -0.184 0.854418
yd.diff.lag6 -0.08919 0.27239 -0.327 0.743775
yd.diff.lag7 -0.05843 0.24162 -0.242 0.809253
yd.diff.lag8 -0.06147 0.20828 -0.295 0.768283
yd.diff.lag9 -0.20371 0.17524 -1.162 0.246855
yd.diff.lag10 -0.19682 0.14889 -1.322 0.188134
yd.diff.lag11 -0.19340 0.11596 -1.668 0.097388 .
yd.diff.lag12 -0.05587 0.07541 -0.741 0.459926

Signif. codes: 0 β€˜β€™ 0.001 β€˜β€™ 0.01 β€˜β€™ 0.05 β€˜.’ 0.1 β€˜ ’ 1

Residual standard error: 15.35 on 154 degrees of freedom
Multiple R-squared: 0.6139, Adjusted R-squared: 0.5813
F-statistic: 18.83 on 13 and 154 DF, p-value: < 2.2e-16

Value of test-statistic is: -3.602

Critical values of DF-GLS are:
1pct 5pct 10pct
critical values -3.46 -2.93 -2.64

Null hypothesis

𝐻0: yt has a unit root, i.e. not stationary
𝐻1: yt does not have a unit root, i.e. stationary
Results
The value of test statistic Ο„ = -3.602
Critical values of DF-GLS test at 5% significance is -2.93
-3.602 > -2.93 therefore Ο„ < -2.93, Ο„ is in the rejection region
The null hypothesis is rejected meaning data of the excess returns on a stock is stationary and does not have a unit root
Differenced data test of the excess returns on stock

dyt=diff(yt)
testdyt=ur.ers(dyt,model = "constant", lag.max=12)
summary(testdyt)

###############################################

Elliot, Rothenberg and Stock Unit Root Test

###############################################

Test of type DF-GLS
detrending of series with intercept

Call:
lm(formula = dfgls.form, data = data.dfgls)

Residuals:
Min 1Q Median 3Q Max
-71.651 -9.224 -3.291 4.059 22.163

Coefficients:
Estimate Std. Error t value Pr(>|t|)
yd.lag -10.50764 1.34161 -7.832 7.46e-13 ***
yd.diff.lag1 8.45162 1.30406 6.481 1.18e-09 ***
yd.diff.lag2 7.42681 1.23377 6.020 1.24e-08 ***
yd.diff.lag3 6.53005 1.14288 5.714 5.60e-08 ***
yd.diff.lag4 5.53392 1.03931 5.325 3.55e-07 ***
yd.diff.lag5 4.56873 0.92527 4.938 2.05e-06 ***
yd.diff.lag6 3.69254 0.79687 4.634 7.63e-06 ***
yd.diff.lag7 2.95325 0.66066 4.470 1.51e-05 ***
yd.diff.lag8 2.30471 0.52597 4.382 2.17e-05 ***
yd.diff.lag9 1.61140 0.40006 4.028 8.84e-05 ***
yd.diff.lag10 1.04724 0.28198 3.714 0.000285 ***
yd.diff.lag11 0.53731 0.16990 3.163 0.001886 **
yd.diff.lag12 0.21746 0.07417 2.932 0.003885 **

Signif. codes: 0 β€˜β€™ 0.001 β€˜β€™ 0.01 β€˜β€™ 0.05 β€˜.’ 0.1 β€˜ ’ 1

Residual standard error: 16.05 on 153 degrees of freedom
Multiple R-squared: 0.864, Adjusted R-squared: 0.8524
F-statistic: 74.74 on 13 and 153 DF, p-value: < 2.2e-16

Value of test-statistic is: -7.8321

Critical values of DF-GLS are:
1pct 5pct 10pct
critical values -2.58 -1.94 -1.62

Null hypothesis

𝐻0: βˆ†yt has a unit root, i.e. not stationary
𝐻1: βˆ†yt does not have a unit root, i.e. stationary
Results
The value of test statistic Ο„ = -7.8321
Critical values of DF-GLS test at 5% significance is -1.94
-1.94 > -7.8321 therefore Ο„ < -1.93
The null hypothesis is rejected meaning data of the differenced excess returns on a stock does not have a unit root and it is stationary.

Please have a look to our homework policy, homework inspired questions are welcome but they should not include verbatim instructions from your course.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.