> .Random.seed <- c(57,0,3,0,0,0,49,16,0,0,0,0)
> # test simple matrix, vector, ts stuff
> if(all(rev(1:10)==10.:1))"Rev and all seem OK"
[1] "Rev and all seem OK"
> rep(c("a,","b","c"),0:2)
[1] "b" "c" "c"
> rep(3.14159,8)
[1] 3.14159 3.14159 3.14159 3.14159 3.14159 3.14159 3.14159 3.14159
> sort(c(3,1,5,2,4))
[1] 1 2 3 4 5
> split(1:10,c("Odd","Even"))
$Even:
[1]  2  4  6  8 10

$Odd:
[1] 1 3 5 7 9

> match(1:5,c(3,4,4,2))
[1] NA  4  1  2 NA
> rank(c(1,2,3,3,5))
[1] 1.0 2.0 3.5 3.5 5.0
> unique(c(1,2,3,3,1,2,5))
[1] 1 2 3 5
> xmat_matrix(rnorm(60),20,3)
> round(xmat,1)
      [,1] [,2] [,3] 
 [1,]  2.0  0.3  1.0
 [2,]  0.0  0.5 -1.6
 [3,]  0.3 -0.5 -2.2
 [4,] -0.3 -1.4  0.0
 [5,] -0.2  0.9  0.2
 [6,] -0.6 -0.4 -1.2
 [7,] -0.7 -0.1 -1.0
 [8,]  1.5  0.4  1.2
 [9,] -0.2 -0.2 -0.2
[10,] -0.4  0.3  0.3
[11,] -1.6 -1.3  1.8
[12,] -0.3 -1.9 -1.0
[13,]  1.6 -0.1 -0.4
[14,]  0.9 -1.4  2.1
[15,] -1.4  0.2  1.3
[16,]  0.0  1.6 -0.4
[17,]  2.0 -0.6 -0.6
[18,]  2.3  1.1  1.1
[19,] -0.1  0.6 -1.4
[20,] -0.8  1.2  0.0
> t(round(xmat,2))
     [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7] [,8]  [,9] [,10] [,11] [,12] 
[1,] 2.00  0.02  0.28 -0.30 -0.18 -0.65 -0.66 1.47 -0.21 -0.40 -1.63 -0.34
[2,] 0.34  0.52 -0.45 -1.44  0.86 -0.39 -0.09 0.35 -0.24  0.28 -1.33 -1.86
[3,] 1.03 -1.59 -2.17  0.00  0.23 -1.23 -0.97 1.19 -0.22  0.30  1.75 -1.02

     [,13] [,14] [,15] [,16] [,17] [,18] [,19] [,20] 
[1,]  1.63  0.95 -1.44 -0.01  2.01  2.28 -0.11 -0.82
[2,] -0.14 -1.38  0.23  1.59 -0.58  1.05  0.64  1.17
[3,] -0.41  2.07  1.29 -0.42 -0.63  1.11 -1.43  0.04
> xmat_cbind(rbind(xmat,c(1,1,1)),rnorm(21))
> cor(xmat);
           [,1]         [,2]         [,3]        [,4] 
[1,]  1.0000000  0.172420412  0.144427508 -0.38202477
[2,]  0.1724204  1.000000119 -0.005574597 -0.27575341
[3,]  0.1444275 -0.005574597  0.999999940 -0.06398977
[4,] -0.3820248 -0.275753409 -0.063989766  1.00000012
> cor(xmat,trim=.2)
           [,1]      [,2]      [,3]       [,4] 
[1,]  1.0000000 0.1068678 0.4583029 -0.3285165
[2,]  0.1068678 1.0000000 0.4721279  0.2728198
[3,]  0.4583029 0.4721279 1.0000000  0.3130876
[4,] -0.3285165 0.2728198 0.3130876  1.0000000
> yvec_rnorm(21)
> r_regress(xmat,yvec)
                Coef      Std Err   t Value
Intercept   -0.1876899   0.1675683    -1.12
x2           0.00937106  0.1597464     0.06
x3          -0.08409708  0.1828306    -0.46
x4           0.04649424  0.1425279     0.33
x5           0.02949429  0.1494705     0.20

N = 21
Residual Standard Error = 0.73856
Multiple R-Square = 0.0259949
F Value = 0.1067547 on 4, 16 df

Covariance matrix of coefficients:
              Intercept        x2            x3           x4          x5
Intercept   2.807914e-2
x2          -6.869034e-3   0.02551890
x3          -3.685999e-4  -0.002317686  0.03342704
x4          7.342006e-4   -0.003013159  0.000896919  2.031421e-2
x5          -4.468528e-3   0.008304762  0.006312405  3.690587e-4  0.02234143

Correlation matrix of coefficients:
             Intercept       x2          x3          x4
x2          -0.2566095
x3          -0.01203135  -0.0793551
x4           0.03074135  -0.1323400  0.03441947
x5          -0.1784091    0.3478089  0.2309885   0.01732367

> regprt(r,names=encode("X Variable",1:4))
                   Coef      Std Err   t Value
Intercept      -0.1876899   0.1675683    -1.12
X Variable 1    0.00937106  0.1597464     0.06
X Variable 2   -0.08409708  0.1828306    -0.46
X Variable 3    0.04649424  0.1425279     0.33
X Variable 4    0.02949429  0.1494705     0.20

N = 21
Residual Standard Error = 0.73856
Multiple R-Square = 0.0259949
F Value = 0.1067547 on 4, 16 df

Covariance matrix of coefficients:
                 Intercept   X Variable 1  X Variable 2  X Variable 3
Intercept      2.807914e-2
X Variable 1   -6.869034e-3   0.02551890
X Variable 2   -3.685999e-4  -0.002317686   0.03342704
X Variable 3   7.342006e-4   -0.003013159   0.000896919   2.031421e-2
X Variable 4   -4.468528e-3   0.008304762   0.006312405   3.690587e-4

               X Variable 4
X Variable 4     0.02234143

Correlation matrix of coefficients:
                Intercept   X Variable 1  X Variable 2  X Variable 3
X Variable 1   -0.2566095
X Variable 2   -0.01203135    -0.0793551
X Variable 3    0.03074135    -0.1323400    0.03441947
X Variable 4   -0.1784091      0.3478089    0.2309885     0.01732367

> regsum(r)
$names:
[1] "Intercept" "x2"        "x3"        "x4"        "x5"       

$ynames:
[1] "y1"

$table:
             [,1]      [,2]       [,3] 
[1,] -0.187689975 0.1675683 -1.1200804
[2,]  0.009371058 0.1597464  0.0586621
[3,] -0.084097065 0.1828306 -0.4599725
[4,]  0.046494238 0.1425279  0.3262114
[5,]  0.029494289 0.1494705  0.1973252

$coef:
             [,1] 
[1,] -0.187689975
[2,]  0.009371058
[3,] -0.084097065
[4,]  0.046494238
[5,]  0.029494289

$stderr:
          [,1] 
[1,] 0.1675683
[2,] 0.1597464
[3,] 0.1828306
[4,] 0.1425279
[5,] 0.1494705

$t:
           [,1] 
[1,] -1.1200804
[2,]  0.0586621
[3,] -0.4599725
[4,]  0.3262114
[5,]  0.1973252

$cor:
            [,1]        [,2]        [,3]        [,4]        [,5] 
[1,]  1.00000000 -0.25660950 -0.01203135  0.03074135 -0.17840914
[2,] -0.25660950  1.00000000 -0.07935506 -0.13233998  0.34780893
[3,] -0.01203135 -0.07935506  1.00000000  0.03441947  0.23098853
[4,]  0.03074135 -0.13233998  0.03441947  1.00000000  0.01732367
[5,] -0.17840914  0.34780893  0.23098853  0.01732367  1.00000000

$cov:
              [,1]         [,2]          [,3]          [,4]          [,5] 
[1,]  0.0280791409 -0.006869034 -0.0003685999  0.0007342006 -0.0044685276
[2,] -0.0068690339  0.025518905 -0.0023176863 -0.0030131591  0.0083047617
[3,] -0.0003685999 -0.002317686  0.0334270410  0.0008969188  0.0063124048
[4,]  0.0007342006 -0.003013159  0.0008969188  0.0203142129  0.0003690587
[5,] -0.0044685276  0.008304762  0.0063124048  0.0003690587  0.0223414265

$rsq:
[1] 0.0259949

$rms:
[1] 0.7385598

$fval:
[1] 0.1067547

$df:
[1]  4 16

> sum(abs(yvec-r$resid-cbind(1,xmat)%*%r$coef))	# should be near zero
[1] 5.252656e-07
> twoway(xmat)->tt	# should get warning
> fit_matrix(tt$row,nrow(xmat),ncol(xmat))+matrix(tt$col,nrow(xmat),ncol(xmat),byrow=TRUE)+
+ tt$grand
> sum(abs(fit+tt$resid-xmat))
[1] 3.11574e-06
> timeser_ts(1:20,c(1958,3),12)
> start(timeser);
[1] 1958    3
> end(timeser);
[1] 1959   10
> frequency(timeser);
[1] 12
> nper(timeser)
[1] 12
> print(cbind(time(timeser),cycle(timeser),timeser%m%INT))
          [,1] [,2] [,3] 
 [1,] 1958.167    3    1
 [2,] 1958.250    4    2
 [3,] 1958.333    5    3
 [4,] 1958.417    6    4
 [5,] 1958.500    7    5
 [6,] 1958.583    8    6
 [7,] 1958.667    9    7
 [8,] 1958.750   10    8
 [9,] 1958.833   11    9
[10,] 1958.917   12   10
[11,] 1959.000    1   11
[12,] 1959.083    2   12
[13,] 1959.167    3   13
[14,] 1959.250    4   14
[15,] 1959.333    5   15
[16,] 1959.417    6   16
[17,] 1959.500    7   17
[18,] 1959.583    8   18
[19,] 1959.667    9   19
[20,] 1959.750   10   20
> mm_matrix(runif(16),4,4)
> if(any(diag(mm)!=mm[row(mm)==col(mm)]))"We got troubles"
NULL
> diag(3);
     [,1] [,2] [,3] 
[1,]    1    0    0
[2,]    0    1    0
[3,]    0    0    1
> diag(diag(mm))
          [,1]      [,2]      [,3]      [,4] 
[1,] 0.4826276 0.0000000 0.0000000 0.0000000
[2,] 0.0000000 0.8143874 0.0000000 0.0000000
[3,] 0.0000000 0.0000000 0.5399635 0.0000000
[4,] 0.0000000 0.0000000 0.0000000 0.9569381
> mm[1,3]_NA
> replace(mm,3,10000000)
             [,1]      [,2]      [,3]      [,4] 
[1,] 4.826276e-01 0.1178895        NA 0.1897214
[2,] 9.950730e-01 0.8143874 0.8290446 0.4919873
[3,] 1.000000e+07 0.9797956 0.5399635 0.6738487
[4,] 3.908283e-01 0.5345188 0.1673725 0.9569381
> append(mm,1:5)	#should end in 1:5 and be a vector, not matrix
 [1] 0.4826276 0.9950730 0.8679034 0.3908283 0.1178895 0.8143874 0.9797956
 [8] 0.5345188        NA 0.8290446 0.5399635 0.1673725 0.1897214 0.4919873
[15] 0.6738487 0.9569381 1.0000000 2.0000000 3.0000000 4.0000000 5.0000000
> pmin(c(1,3,9),c(2,2,20))
[1] 1 2 9
> pmax(c(1,3,9),c(2,2,20))
[1]  2  3 20
> min(smooth(1:20)==1:20)	# should be 1
[1] 1
> c(229,205,228,233,224,244,229,215,236,293,323,286,
+ 356,158,104,108,108,130,115,154,84,67,43,86,
+ 15,0,0,7,0,2,61,38,166,59,88,111,
+ 114,86,48,95,93,34,139,136,167,23,111)->deposits	# suspended bank deposits
> deposits_ts(deposits,start=1921,frequency=1)
> smooth(deposits)
1921:  228.312500  228.437500  228.687500  229.437500  229.695313  228.656250
1927:  227.296875  230.031250  243.125000  263.281250  279.632813  277.187500
1933:  237.000000  169.562500  118.003906  102.660156  107.269531  114.574219
1939:  116.093750  104.863281   85.257813   69.074219   54.652344   35.023438
1945:   15.285156    3.261719   -1.296875   -2.050781    1.468750   13.957031
1951:   34.609375   54.261719   70.375000   86.500000   97.937500  101.046875
1957:   99.593750   95.890625   92.093750   91.074219   95.277344  108.089844
1963:  126.570801  138.681641  135.921387  121.777344  105.849854
> range(rnorm(1000))
[1] -3.103406  3.010009
> ifelse(runif(10)>.5,"heads","tails")
 [1] "tails" "heads" "heads" "tails" "tails" "tails" "heads" "tails" "tails"
[10] "heads"
> na(print(c(1,3,NA,4,3/0)))
[1]  1  3 NA  4 NA
Warning messages:
  NAs generated in: 3/0
> len(xmat);
[1] 84
> mode(xmat)
[1] "numeric"
> prod(1:10)==3628800
[1] T
> l_order(xmat[,1])
> ttt_xmat[l,]
> dimnames(ttt)_list((1:nrow(xmat))%m%CHAR,NULL)
> ttt
          [,1]        [,2]         [,3]        [,4] 
 1 -1.62742662 -1.33279812  1.752693295  1.96444046
 2 -1.44432819  0.22623688  1.286279440 -0.58358485
 3 -0.82419628  1.17309535  0.036409777  1.13906252
 4 -0.65970474 -0.09113099 -0.968068004 -0.73910576
 5 -0.64686066 -0.38915271 -1.229570866 -0.73075742
 6 -0.39785635  0.27867734  0.301362038  0.72135556
 7 -0.34048831 -1.85502446 -1.021658540  0.63749540
 8 -0.29562140 -1.44177830 -0.002461897  2.18594384
 9 -0.21338126 -0.23836584 -0.218552992 -0.17791232
10 -0.18452650  0.86399066  0.232092351  0.25455073
11 -0.10840119  0.63590473 -1.434693098 -0.24421830
12 -0.01028041  1.59109890 -0.418970525  1.02527940
13  0.02307982  0.52246845 -1.593777537  0.71220219
14  0.28372642 -0.45246986 -2.170554876  1.10246515
15  0.94653869 -1.37791431  2.072354794  0.50268376
16  1.00000000  1.00000000  1.000000000 -3.02215123
17  1.46970928  0.35367924  1.188760757 -0.02321174
18  1.63003206 -0.14309703 -0.406636655 -0.38079011
19  1.99703109  0.33510390  1.026755571 -1.98460972
20  2.01049876 -0.58261472 -0.627196610 -0.94978267
21  2.28348541  1.05379760  1.113558888  0.93748295
> dput(xmat,file="tttt");
> dget("tttt")
             [,1]        [,2]         [,3]        [,4] 
 [1,]  1.99703109  0.33510390  1.026755571 -1.98460972
 [2,]  0.02307982  0.52246845 -1.593777537  0.71220219
 [3,]  0.28372642 -0.45246986 -2.170554876  1.10246515
 [4,] -0.29562140 -1.44177830 -0.002461897  2.18594384
 [5,] -0.18452650  0.86399066  0.232092351  0.25455073
 [6,] -0.64686066 -0.38915271 -1.229570866 -0.73075742
 [7,] -0.65970474 -0.09113099 -0.968068004 -0.73910576
 [8,]  1.46970928  0.35367924  1.188760757 -0.02321174
 [9,] -0.21338126 -0.23836584 -0.218552992 -0.17791232
[10,] -0.39785635  0.27867734  0.301362038  0.72135556
[11,] -1.62742662 -1.33279812  1.752693295  1.96444046
[12,] -0.34048831 -1.85502446 -1.021658540  0.63749540
[13,]  1.63003206 -0.14309703 -0.406636655 -0.38079011
[14,]  0.94653869 -1.37791431  2.072354794  0.50268376
[15,] -1.44432819  0.22623688  1.286279440 -0.58358485
[16,] -0.01028041  1.59109890 -0.418970525  1.02527940
[17,]  2.01049876 -0.58261472 -0.627196610 -0.94978267
[18,]  2.28348541  1.05379760  1.113558888  0.93748295
[19,] -0.10840119  0.63590473 -1.434693098 -0.24421830
[20,] -0.82419628  1.17309535  0.036409777  1.13906252
[21,]  1.00000000  1.00000000  1.000000000 -3.02215123
> !rm tttt
> 12.2u 4.3s 59r 	 /usr/s/cmd/Sqpe
