Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Computer exercises # 3 in R 1. Firstly, you should install following packages that are not included in R by default: Package lmtest car sandwich moments forecast tseries Description Testing Linear Regression Models Companion to Applied Regression Robust Covariance Matrix Estimator Moments, Cumulants, Skewness, Kurtosis and Related Tests Forecasting Function for Time Series and Linear Models Time Series Analysis and Computational Finance These packages provide some functions required for diagnostic checking and significance testing after estimation of a certain econometric model using LS method (post-estimation procedure). You can install one or more packages by commands: install.packages("lmtest") install.packages("car") install.packages("sandwich") install.packages("moments") install.packages("forecast") install.packages("tseries") Installed packages are stored in a library and they should be loaded using commands: library(lmtest) library(car) library(sandwich) library(moments) library(forecast) library(tseries) Data files you want to use should be stored in the current working directory. Current working directory can be located using command: getwd() The working directory can be changed: setwd("C:/...") R is able to read data from many formats. The most common format is a text file with data separated into columns and with a header above each column describing the data. When importing dataframe from the text file make sure that decimal places of the numbers are separated by dots (not commas). 1 2. Download text file economic_indicators.txt from http://www.efzg.unizg.hr (Katedra/Statistika/Članovi/Doc.dr.sc. Josip Arnerić/Econometrics). You can save text file on your desktop (hrv. radna povšina) if desktop is your working directory. Import dataframe into R from text file using command: mydata=read.table(file="economic indicators.txt",header=TRUE) colnames(mydata) Dataframe mydata contains time series from period 2000Q1 to 2014Q3 (59 quarters) with respect to following economic indicators of China: exchange rate (CNY/USD), fdi_capital (FDI, capital used in millions of CNY), gdp_current_price (GDP in current prices, billions of CNY), gdp_growth (in %), ind_production (volume index on industrial production) and m2 (money supply M2 in billions of CNY). 3. Observations should be dated as regular frequency data using command: mydata=ts(mydata,frequency=4,start=c(2000,1)) mydata You can plot any time series using ts.plot command. If you want to plot GDP, only a third column of mydata should be considered. Be aware that each column of mydata can be separated as a single time series by referencing on the certain index in the square brackets [i,j]. Index i stands for the rows, while index j stands for the columns. ts.plot(mydata[,3],ylab="GDP in China",col="red") 4. Decompose time series of GDP in China using additive model. Plot all components. components=decompose(mydata[,"gdp"],type="multiplicative") plot(components) 5. Compute seasonal factors and explain the meaning of these factors for each quarter! components$seasonal Quarter Q1 Q2 Q3 Q4 Seasonal factor % change 2 6. Compute seasonally adjusted values of GDP (blue color) and compare them with actual values (red color) on the single graph. adjusted=mydata[,"gdp"]/components$seasonal ts.plot(mydata[,3],adjusted,gpars=list(col=c("red","blue")),main="Seaso naly adjusted and actual values of GDP)") 7. Estimate ACF coefficients for variable GDP growth up to 10 lags ACF=acf(mydata[,"growth"],lag.max=10,type="correlation",plot=FALSE,dem ean=FALSE) ACF$acf plot(ACF) Lag 1 2 3 4 5 6 7 8 9 10 ACF Note: The autocorrelation coefficients at all lags should be nearly zero if a time-series follows white noise process and all Q-statistics (Ljung-Box) should be insignificant with large p-values 8. Check if GDP growth follows a white noise process using Ljung-Box test for lags 1, 5 and 10. Box.test(mydata[,"growth"],lag=1,type="Ljung-Box") Box.test(mydata[,"growth"],lag=5,type="Ljung-Box") Box.test(mydata[,"growth"],lag=10,type="Ljung-Box") Q1 ___________ Q5 ___________ p value ____________ p value ____________ Q10 ___________ p value ____________ 9. Use the Augmented Dicky Fuller test (ADF) to test whether GDP growth (in the levels) is stationarity or not at 1%, 5% and 10% level of significance. adf.test(mydata[,"growth"],alternative="stationary") 10. Repeat ADF test to test whether GDP growth in the first differences is stationarity or not at 1%, 5% and 10% level of significance. differences=diff(mydata[,"growth"]) adf.test(differences,alternative="stationary") Is there a unit-root? Should data be differenced? 3