R version 2.6.0 (2007-10-03)
Copyright (C) 2007 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> x <- array(list(1178,0,2141,0,2238,0,2685,0,4341,0,5376,0,4478,0,6404,0,4617,0,3024,0,1897,0,2075,0,1351,0,2211,0,2453,0,3042,0,4765,0,4992,1,4601,1,6266,1,4812,1,3159,1,1916,1,2237,1,1595,1,2453,1,2226,1,3597,1,4706,1,4974,1,5756,1,5493,1,5004,1,3225,1,2006,1,2291,1,1588,1,2105,1,2191,1,3591,1,4668,1,4885,1,5822,1,5599,1,5340,1,3082,1,2010,1,2301,1,1514,1,1979,1,2480,1,3499,1,4676,1,5585,1,5610,1,5796,1,6199,1,3030,1,1930,1,2552,1),dim=c(2,60),dimnames=list(c('Huwelijken','Dummy'),1:60))
> y <- array(NA,dim=c(2,60),dimnames=list(c('Huwelijken','Dummy'),1:60))
> for (i in 1:dim(x)[1])
+ {
+ for (j in 1:dim(x)[2])
+ {
+ y[i,j] <- as.numeric(x[i,j])
+ }
+ }
> par3 = 'No Linear Trend'
> par2 = 'Do not include Seasonal Dummies'
> par1 = '1'
> #'GNU S' R Code compiled by R2WASP v. 1.0.44 ()
> #Author: Prof. Dr. P. Wessa
> #To cite this work: AUTHOR(S), (YEAR), YOUR SOFTWARE TITLE (vNUMBER) in Free Statistics Software (v$_version), Office for Research Development and Education, URL http://www.wessa.net/rwasp_YOURPAGE.wasp/
> #Source of accompanying publication: Office for Research, Development, and Education
> #Technical description: Write here your technical program description (don't use hard returns!)
> library(lattice)
> par1 <- as.numeric(par1)
> x <- t(y)
> k <- length(x[1,])
> n <- length(x[,1])
> x1 <- cbind(x[,par1], x[,1:k!=par1])
> mycolnames <- c(colnames(x)[par1], colnames(x)[1:k!=par1])
> colnames(x1) <- mycolnames #colnames(x)[par1]
> x <- x1
> if (par3 == 'First Differences'){
+ x2 <- array(0, dim=c(n-1,k), dimnames=list(1:(n-1), paste('(1-B)',colnames(x),sep='')))
+ for (i in 1:n-1) {
+ for (j in 1:k) {
+ x2[i,j] <- x[i+1,j] - x[i,j]
+ }
+ }
+ x <- x2
+ }
> if (par2 == 'Include Monthly Dummies'){
+ x2 <- array(0, dim=c(n,11), dimnames=list(1:n, paste('M', seq(1:11), sep ='')))
+ for (i in 1:11){
+ x2[seq(i,n,12),i] <- 1
+ }
+ x <- cbind(x, x2)
+ }
> if (par2 == 'Include Quarterly Dummies'){
+ x2 <- array(0, dim=c(n,3), dimnames=list(1:n, paste('Q', seq(1:3), sep ='')))
+ for (i in 1:3){
+ x2[seq(i,n,4),i] <- 1
+ }
+ x <- cbind(x, x2)
+ }
> k <- length(x[1,])
> if (par3 == 'Linear Trend'){
+ x <- cbind(x, c(1:n))
+ colnames(x)[k+1] <- 't'
+ }
> x
Huwelijken Dummy
1 1178 0
2 2141 0
3 2238 0
4 2685 0
5 4341 0
6 5376 0
7 4478 0
8 6404 0
9 4617 0
10 3024 0
11 1897 0
12 2075 0
13 1351 0
14 2211 0
15 2453 0
16 3042 0
17 4765 0
18 4992 1
19 4601 1
20 6266 1
21 4812 1
22 3159 1
23 1916 1
24 2237 1
25 1595 1
26 2453 1
27 2226 1
28 3597 1
29 4706 1
30 4974 1
31 5756 1
32 5493 1
33 5004 1
34 3225 1
35 2006 1
36 2291 1
37 1588 1
38 2105 1
39 2191 1
40 3591 1
41 4668 1
42 4885 1
43 5822 1
44 5599 1
45 5340 1
46 3082 1
47 2010 1
48 2301 1
49 1514 1
50 1979 1
51 2480 1
52 3499 1
53 4676 1
54 5585 1
55 5610 1
56 5796 1
57 6199 1
58 3030 1
59 1930 1
60 2552 1
> k <- length(x[1,])
> df <- as.data.frame(x)
> (mylm <- lm(df))
Call:
lm(formula = df)
Coefficients:
(Intercept) Dummy
3192.7 512.9
> (mysum <- summary(mylm))
Call:
lm(formula = df)
Residuals:
Min 1Q Median 3Q Max
-2191.6 -1407.1 -343.6 1289.4 3211.3
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3192.7 374.5 8.525 8.13e-12 ***
Dummy 512.9 442.4 1.159 0.251
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1544 on 58 degrees of freedom
Multiple R-Squared: 0.02265, Adjusted R-squared: 0.005799
F-statistic: 1.344 on 1 and 58 DF, p-value: 0.2511
> postscript(file="/var/www/html/rcomp/tmp/1zk8b1195403435.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> plot(x[,1], type='l', main='Actuals and Interpolation', ylab='value of Actuals and Interpolation (dots)', xlab='time or index')
> points(x[,1]-mysum$resid)
> grid()
> dev.off()
null device
1
> postscript(file="/var/www/html/rcomp/tmp/21w8k1195403435.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> plot(mysum$resid, type='b', pch=19, main='Residuals', ylab='value of Residuals', xlab='time or index')
> grid()
> dev.off()
null device
1
> postscript(file="/var/www/html/rcomp/tmp/3gjjf1195403435.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> hist(mysum$resid, main='Residual Histogram', xlab='values of Residuals')
> grid()
> dev.off()
null device
1
> postscript(file="/var/www/html/rcomp/tmp/4e1gn1195403435.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> densityplot(~mysum$resid,col='black',main='Residual Density Plot', xlab='values of Residuals')
> dev.off()
null device
1
> postscript(file="/var/www/html/rcomp/tmp/56y6d1195403435.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> qqnorm(mysum$resid, main='Residual Normal Q-Q Plot')
> grid()
> dev.off()
null device
1
> (myerror <- as.ts(mysum$resid))
Time Series:
Start = 1
End = 60
Frequency = 1
1 2 3 4 5 6 7
-2014.7059 -1051.7059 -954.7059 -507.7059 1148.2941 2183.2941 1285.2941
8 9 10 11 12 13 14
3211.2941 1424.2941 -168.7059 -1295.7059 -1117.7059 -1841.7059 -981.7059
15 16 17 18 19 20 21
-739.7059 -150.7059 1572.2941 1286.3953 895.3953 2560.3953 1106.3953
22 23 24 25 26 27 28
-546.6047 -1789.6047 -1468.6047 -2110.6047 -1252.6047 -1479.6047 -108.6047
29 30 31 32 33 34 35
1000.3953 1268.3953 2050.3953 1787.3953 1298.3953 -480.6047 -1699.6047
36 37 38 39 40 41 42
-1414.6047 -2117.6047 -1600.6047 -1514.6047 -114.6047 962.3953 1179.3953
43 44 45 46 47 48 49
2116.3953 1893.3953 1634.3953 -623.6047 -1695.6047 -1404.6047 -2191.6047
50 51 52 53 54 55 56
-1726.6047 -1225.6047 -206.6047 970.3953 1879.3953 1904.3953 2090.3953
57 58 59 60
2493.3953 -675.6047 -1775.6047 -1153.6047
> postscript(file="/var/www/html/rcomp/tmp/62ksb1195403435.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> dum <- cbind(lag(myerror,k=1),myerror)
> dum
Time Series:
Start = 0
End = 60
Frequency = 1
lag(myerror, k = 1) myerror
0 -2014.7059 NA
1 -1051.7059 -2014.7059
2 -954.7059 -1051.7059
3 -507.7059 -954.7059
4 1148.2941 -507.7059
5 2183.2941 1148.2941
6 1285.2941 2183.2941
7 3211.2941 1285.2941
8 1424.2941 3211.2941
9 -168.7059 1424.2941
10 -1295.7059 -168.7059
11 -1117.7059 -1295.7059
12 -1841.7059 -1117.7059
13 -981.7059 -1841.7059
14 -739.7059 -981.7059
15 -150.7059 -739.7059
16 1572.2941 -150.7059
17 1286.3953 1572.2941
18 895.3953 1286.3953
19 2560.3953 895.3953
20 1106.3953 2560.3953
21 -546.6047 1106.3953
22 -1789.6047 -546.6047
23 -1468.6047 -1789.6047
24 -2110.6047 -1468.6047
25 -1252.6047 -2110.6047
26 -1479.6047 -1252.6047
27 -108.6047 -1479.6047
28 1000.3953 -108.6047
29 1268.3953 1000.3953
30 2050.3953 1268.3953
31 1787.3953 2050.3953
32 1298.3953 1787.3953
33 -480.6047 1298.3953
34 -1699.6047 -480.6047
35 -1414.6047 -1699.6047
36 -2117.6047 -1414.6047
37 -1600.6047 -2117.6047
38 -1514.6047 -1600.6047
39 -114.6047 -1514.6047
40 962.3953 -114.6047
41 1179.3953 962.3953
42 2116.3953 1179.3953
43 1893.3953 2116.3953
44 1634.3953 1893.3953
45 -623.6047 1634.3953
46 -1695.6047 -623.6047
47 -1404.6047 -1695.6047
48 -2191.6047 -1404.6047
49 -1726.6047 -2191.6047
50 -1225.6047 -1726.6047
51 -206.6047 -1225.6047
52 970.3953 -206.6047
53 1879.3953 970.3953
54 1904.3953 1879.3953
55 2090.3953 1904.3953
56 2493.3953 2090.3953
57 -675.6047 2493.3953
58 -1775.6047 -675.6047
59 -1153.6047 -1775.6047
60 NA -1153.6047
> dum1 <- dum[2:length(myerror),]
> dum1
lag(myerror, k = 1) myerror
[1,] -1051.7059 -2014.7059
[2,] -954.7059 -1051.7059
[3,] -507.7059 -954.7059
[4,] 1148.2941 -507.7059
[5,] 2183.2941 1148.2941
[6,] 1285.2941 2183.2941
[7,] 3211.2941 1285.2941
[8,] 1424.2941 3211.2941
[9,] -168.7059 1424.2941
[10,] -1295.7059 -168.7059
[11,] -1117.7059 -1295.7059
[12,] -1841.7059 -1117.7059
[13,] -981.7059 -1841.7059
[14,] -739.7059 -981.7059
[15,] -150.7059 -739.7059
[16,] 1572.2941 -150.7059
[17,] 1286.3953 1572.2941
[18,] 895.3953 1286.3953
[19,] 2560.3953 895.3953
[20,] 1106.3953 2560.3953
[21,] -546.6047 1106.3953
[22,] -1789.6047 -546.6047
[23,] -1468.6047 -1789.6047
[24,] -2110.6047 -1468.6047
[25,] -1252.6047 -2110.6047
[26,] -1479.6047 -1252.6047
[27,] -108.6047 -1479.6047
[28,] 1000.3953 -108.6047
[29,] 1268.3953 1000.3953
[30,] 2050.3953 1268.3953
[31,] 1787.3953 2050.3953
[32,] 1298.3953 1787.3953
[33,] -480.6047 1298.3953
[34,] -1699.6047 -480.6047
[35,] -1414.6047 -1699.6047
[36,] -2117.6047 -1414.6047
[37,] -1600.6047 -2117.6047
[38,] -1514.6047 -1600.6047
[39,] -114.6047 -1514.6047
[40,] 962.3953 -114.6047
[41,] 1179.3953 962.3953
[42,] 2116.3953 1179.3953
[43,] 1893.3953 2116.3953
[44,] 1634.3953 1893.3953
[45,] -623.6047 1634.3953
[46,] -1695.6047 -623.6047
[47,] -1404.6047 -1695.6047
[48,] -2191.6047 -1404.6047
[49,] -1726.6047 -2191.6047
[50,] -1225.6047 -1726.6047
[51,] -206.6047 -1225.6047
[52,] 970.3953 -206.6047
[53,] 1879.3953 970.3953
[54,] 1904.3953 1879.3953
[55,] 2090.3953 1904.3953
[56,] 2493.3953 2090.3953
[57,] -675.6047 2493.3953
[58,] -1775.6047 -675.6047
[59,] -1153.6047 -1775.6047
> z <- as.data.frame(dum1)
> z
lag(myerror, k = 1) myerror
1 -1051.7059 -2014.7059
2 -954.7059 -1051.7059
3 -507.7059 -954.7059
4 1148.2941 -507.7059
5 2183.2941 1148.2941
6 1285.2941 2183.2941
7 3211.2941 1285.2941
8 1424.2941 3211.2941
9 -168.7059 1424.2941
10 -1295.7059 -168.7059
11 -1117.7059 -1295.7059
12 -1841.7059 -1117.7059
13 -981.7059 -1841.7059
14 -739.7059 -981.7059
15 -150.7059 -739.7059
16 1572.2941 -150.7059
17 1286.3953 1572.2941
18 895.3953 1286.3953
19 2560.3953 895.3953
20 1106.3953 2560.3953
21 -546.6047 1106.3953
22 -1789.6047 -546.6047
23 -1468.6047 -1789.6047
24 -2110.6047 -1468.6047
25 -1252.6047 -2110.6047
26 -1479.6047 -1252.6047
27 -108.6047 -1479.6047
28 1000.3953 -108.6047
29 1268.3953 1000.3953
30 2050.3953 1268.3953
31 1787.3953 2050.3953
32 1298.3953 1787.3953
33 -480.6047 1298.3953
34 -1699.6047 -480.6047
35 -1414.6047 -1699.6047
36 -2117.6047 -1414.6047
37 -1600.6047 -2117.6047
38 -1514.6047 -1600.6047
39 -114.6047 -1514.6047
40 962.3953 -114.6047
41 1179.3953 962.3953
42 2116.3953 1179.3953
43 1893.3953 2116.3953
44 1634.3953 1893.3953
45 -623.6047 1634.3953
46 -1695.6047 -623.6047
47 -1404.6047 -1695.6047
48 -2191.6047 -1404.6047
49 -1726.6047 -2191.6047
50 -1225.6047 -1726.6047
51 -206.6047 -1225.6047
52 970.3953 -206.6047
53 1879.3953 970.3953
54 1904.3953 1879.3953
55 2090.3953 1904.3953
56 2493.3953 2090.3953
57 -675.6047 2493.3953
58 -1775.6047 -675.6047
59 -1153.6047 -1775.6047
> plot(z,main=paste('Residual Lag plot, lowess, and regression line'), ylab='values of Residuals', xlab='lagged values of Residuals')
> lines(lowess(z))
> abline(lm(z))
> grid()
> dev.off()
null device
1
> postscript(file="/var/www/html/rcomp/tmp/7k88i1195403435.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> acf(mysum$resid, lag.max=length(mysum$resid)/2, main='Residual Autocorrelation Function')
> grid()
> dev.off()
null device
1
> postscript(file="/var/www/html/rcomp/tmp/8etb31195403435.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> pacf(mysum$resid, lag.max=length(mysum$resid)/2, main='Residual Partial Autocorrelation Function')
> grid()
> dev.off()
null device
1
> postscript(file="/var/www/html/rcomp/tmp/9osak1195403435.ps",horizontal=F,pagecentre=F,paper="special",width=8.3333333333333,height=5.5555555555556)
> opar <- par(mfrow = c(2,2), oma = c(0, 0, 1.1, 0))
> plot(mylm, las = 1, sub='Residual Diagnostics')
> par(opar)
> dev.off()
null device
1
> load(file='/var/www/html/rcomp/createtable')
> a<-table.start()
> a<-table.row.start(a)
> a<-table.element(a, 'Multiple Linear Regression - Estimated Regression Equation', 1, TRUE)
> a<-table.row.end(a)
> myeq <- colnames(x)[1]
> myeq <- paste(myeq, '[t] = ', sep='')
> for (i in 1:k){
+ if (mysum$coefficients[i,1] > 0) myeq <- paste(myeq, '+', '')
+ myeq <- paste(myeq, mysum$coefficients[i,1], sep=' ')
+ if (rownames(mysum$coefficients)[i] != '(Intercept)') {
+ myeq <- paste(myeq, rownames(mysum$coefficients)[i], sep='')
+ if (rownames(mysum$coefficients)[i] != 't') myeq <- paste(myeq, '[t]', sep='')
+ }
+ }
> myeq <- paste(myeq, ' + e[t]')
> a<-table.row.start(a)
> a<-table.element(a, myeq)
> a<-table.row.end(a)
> a<-table.end(a)
> table.save(a,file="/var/www/html/rcomp/tmp/103zyl1195403435.tab")
> a<-table.start()
> a<-table.row.start(a)
> a<-table.element(a,hyperlink('http://www.xycoon.com/ols1.htm','Multiple Linear Regression - Ordinary Least Squares',''), 6, TRUE)
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a,'Variable',header=TRUE)
> a<-table.element(a,'Parameter',header=TRUE)
> a<-table.element(a,'S.D.',header=TRUE)
> a<-table.element(a,'T-STAT
H0: parameter = 0',header=TRUE)
> a<-table.element(a,'2-tail p-value',header=TRUE)
> a<-table.element(a,'1-tail p-value',header=TRUE)
> a<-table.row.end(a)
> for (i in 1:k){
+ a<-table.row.start(a)
+ a<-table.element(a,rownames(mysum$coefficients)[i],header=TRUE)
+ a<-table.element(a,mysum$coefficients[i,1])
+ a<-table.element(a, round(mysum$coefficients[i,2],6))
+ a<-table.element(a, round(mysum$coefficients[i,3],4))
+ a<-table.element(a, round(mysum$coefficients[i,4],6))
+ a<-table.element(a, round(mysum$coefficients[i,4]/2,6))
+ a<-table.row.end(a)
+ }
> a<-table.end(a)
> table.save(a,file="/var/www/html/rcomp/tmp/11hnev1195403435.tab")
> a<-table.start()
> a<-table.row.start(a)
> a<-table.element(a, 'Multiple Linear Regression - Regression Statistics', 2, TRUE)
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'Multiple R',1,TRUE)
> a<-table.element(a, sqrt(mysum$r.squared))
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'R-squared',1,TRUE)
> a<-table.element(a, mysum$r.squared)
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'Adjusted R-squared',1,TRUE)
> a<-table.element(a, mysum$adj.r.squared)
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'F-TEST (value)',1,TRUE)
> a<-table.element(a, mysum$fstatistic[1])
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'F-TEST (DF numerator)',1,TRUE)
> a<-table.element(a, mysum$fstatistic[2])
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'F-TEST (DF denominator)',1,TRUE)
> a<-table.element(a, mysum$fstatistic[3])
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'p-value',1,TRUE)
> a<-table.element(a, 1-pf(mysum$fstatistic[1],mysum$fstatistic[2],mysum$fstatistic[3]))
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'Multiple Linear Regression - Residual Statistics', 2, TRUE)
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'Residual Standard Deviation',1,TRUE)
> a<-table.element(a, mysum$sigma)
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'Sum Squared Residuals',1,TRUE)
> a<-table.element(a, sum(myerror*myerror))
> a<-table.row.end(a)
> a<-table.end(a)
> table.save(a,file="/var/www/html/rcomp/tmp/12pufr1195403436.tab")
> a<-table.start()
> a<-table.row.start(a)
> a<-table.element(a, 'Multiple Linear Regression - Actuals, Interpolation, and Residuals', 4, TRUE)
> a<-table.row.end(a)
> a<-table.row.start(a)
> a<-table.element(a, 'Time or Index', 1, TRUE)
> a<-table.element(a, 'Actuals', 1, TRUE)
> a<-table.element(a, 'Interpolation
Forecast', 1, TRUE)
> a<-table.element(a, 'Residuals
Prediction Error', 1, TRUE)
> a<-table.row.end(a)
> for (i in 1:n) {
+ a<-table.row.start(a)
+ a<-table.element(a,i, 1, TRUE)
+ a<-table.element(a,x[i])
+ a<-table.element(a,x[i]-mysum$resid[i])
+ a<-table.element(a,mysum$resid[i])
+ a<-table.row.end(a)
+ }
> a<-table.end(a)
> table.save(a,file="/var/www/html/rcomp/tmp/132dr21195403436.tab")
>
> system("convert tmp/1zk8b1195403435.ps tmp/1zk8b1195403435.png")
> system("convert tmp/21w8k1195403435.ps tmp/21w8k1195403435.png")
> system("convert tmp/3gjjf1195403435.ps tmp/3gjjf1195403435.png")
> system("convert tmp/4e1gn1195403435.ps tmp/4e1gn1195403435.png")
> system("convert tmp/56y6d1195403435.ps tmp/56y6d1195403435.png")
> system("convert tmp/62ksb1195403435.ps tmp/62ksb1195403435.png")
> system("convert tmp/7k88i1195403435.ps tmp/7k88i1195403435.png")
> system("convert tmp/8etb31195403435.ps tmp/8etb31195403435.png")
> system("convert tmp/9osak1195403435.ps tmp/9osak1195403435.png")
>
>
> proc.time()
user system elapsed
2.338 1.514 2.789