> setwd("C:/teaching/ama") > library(tseries) Loading required package: quadprog 'tseries' version: 0.9-27 'tseries' is a package for time series analysis and computational finance. > da=read.table("T7-4.DAT") % Load data > dim(da) [1] 63 5 > da[1,] V1 V2 V3 V4 V5 1 227 32 30 12 1 > y=da[,1] > x=da[,2:5] > x1=as.matrix(x) > m1=lm(y~x1) % Fit a multiple linear regression (linear model). > summary(m1) lm(formula = y ~ x1) Residuals: Min 1Q Median 3Q Max -36.521 -13.817 -2.781 13.556 35.832 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1.8581 11.5561 0.161 0.87282 x1V2 5.8742 0.2905 20.219 < 2e-16 *** x1V3 1.4052 0.2928 4.799 1.16e-05 *** x1V4 1.3154 0.5787 2.273 0.02675 * x1V5 -15.8571 5.3344 -2.973 0.00429 ** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 18.32 on 58 degrees of freedom Multiple R-Squared: 0.9521, Adjusted R-squared: 0.9488 F-statistic: 288.1 on 4 and 58 DF, p-value: < 2.2e-16 > names(m1) [1] "coefficients" "residuals" "effects" "rank" [5] "fitted.values" "assign" "qr" "df.residual" [9] "xlevels" "call" "terms" "model" > Box.test(m1$residuals,lag=10,type='Ljung') Box-Ljung test data: m1$residuals X-squared = 48.1743, df = 10, p-value = 5.768e-07 > acf(m1$residuals) > pacf(m1$residuals) > m2=arima(y,xreg=x1,order=c(1,0,0),seasonal=list(order=c(1,0,0),period=7)) > m2 Call: arima(x = y, order = c(1, 0, 0), seasonal = list(order = c(1, 0, 0), period = 7), xreg = x1) Coefficients: ar1 sar1 intercept V2 V3 V4 V5 0.5414 0.3753 7.7211 5.7066 1.4087 1.2008 -10.0592 s.e. 0.1067 0.1157 12.5670 0.2195 0.2211 0.3840 6.0951 sigma^2 estimated as 188.2: log likelihood = -255.09, aic = 526.18 > Box.test(m2$residuals,lag=10,type='Ljung') Box-Ljung test data: m2$residuals X-squared = 7.0855, df = 10, p-value = 0.7173 > acf(m2$residuals) > tsdiag(m2)