computer science
R studio needed
Problem Set 5
MSDA3055
Linear Regression and Time Series
Due Date: March 29, 202
1
Problem 1
(a) Obtain time series of real GDP and real consumption for a country of your choice. Provide details.
(b) Display time-series plots and a scatterplot (put consumption on the vertical axis).
(c) Convert your series to growth rates in percent, and again display time series plots.
(d) For each series, ,provide summary statistics (e.g., mean, standard deviation, range, skewness, kurtosis,
…).
(e) Run a simple OLS linear regression in R and interpret its coefficient estimates.
(f) Interpret goodness-of-fit metrics for OLS linear regression.
(g) Relate R2 with correlation coefficient.
Problem 2
Monte Carlo experiment: Consider the following model:
Yi = β1 + β2Xi + ui
You are told that β1 = 25,β2 = 0.5,σ
2 = 9, and ui ∼ N(0, 9).
Assume ui ∼ N(0, 9), that is, ui are normally distributed with mean 0 and variance 9. Generate 10 sets of
64 observations on ui from the given normal distribution and use the 64 observations on X given in Table 2
, to generate 100 sets of the estimated β coefficients (each set will have the two estimated parameters). Take
the averages of each of the estimated β coefficients and relate them to the true values of these coefficients
given above. What overall conclusion do you draw?
1
Sheet1
X | ||
37 | ||
22 | ||
16 | ||
65 | ||
76 | ||
26 | ||
45 | ||
2 | 9 | |
11 | ||
55 | ||
87 | ||
93 | ||
31 | ||
77 | ||
80 | ||
30 | ||
69 | ||
43 | ||
47 | ||
17 | ||
35 | ||
58 | ||
81 | ||
63 | ||
49 | ||
84 | ||
23 | ||
50 | ||
62 | ||
66 | ||
88 | ||
12 | ||
19 | ||
85 | ||
78 | ||
33 | ||
21 | ||
79 | ||
83 | ||
28 | ||
95 | ||
41 | ||
67 |
Sheet2
# Set the random seed
set.seed(1234567)
# set sample size and number of simulations
n<-1000; r<-10000
# set true parameters: betas and sd of u
b0<-1; b1<-0.5; su<-2
# initialize b0hat and b1hat to store results later:
b0hat <- numeric(r)
b1hat <- numeric(r)
# Draw a sample of x, fixed over replications:
x <- rnorm(n,4,1)
# repeat r times:
for(j in 1:r) {
# Draw a sample of y:
u <- rnorm(n,0,su)
y <- b0 + b1*x + u
# estimate parameters by OLS and store them in the vectors
bhat <- coefficients( lm(y~x) )
b0hat[j] <- bhat["(Intercept)"]
b1hat[j] <- bhat["x"]
}