Running S OLD ...
> prefix("basic2.")
> $Random.seed_c(57,0,3,0,0,0,49,16,0,0,0,0)	# to initialize at same spot
> # test simple matrix, vector, ts stuff
> if(all(rev(1:10)==10.:1))"Rev and all seem OK"
      "Rev and all seem OK"
> rep(c("a,","b","c"),0:2)
      "b"  "c"  "c"
> rep(3.14159,8)
      3.14159  3.14159  3.14159  3.14159  3.14159  3.14159  3.14159  3.14159
> sort(c(3,1,5,2,4))
       1   2   3   4   5
> split(1:10,c("Odd","Even"))

 $Even
       2   4   6   8  10
 $Odd
       1   3   5   7   9
> match(1:5,c(3,4,4,2))
Warning in match: Duplicate values in list
      NA   4   1   2  NA
> rank(c(1,2,3,3,5))
      1.0  2.0  3.5  3.5  5.0
> unique(c(1,2,3,3,1,2,5))
       1   2   3   5
> xmat_matrix(rnorm(60),20,3)
> round(xmat,1)

Array:
20 by 3

        [,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))

Array:
3 by 20

       [, 1]  [, 2]  [, 3]  [, 4]  [, 5]  [, 6]  [, 7]  [, 8]  [, 9]  [,10]
[1,]    2.00   0.02   0.28  -0.30  -0.18  -0.65  -0.66   1.47  -0.21  -0.40
[2,]    0.34   0.52  -0.45  -1.44   0.86  -0.39  -0.09   0.35  -0.24   0.28
[3,]    1.03  -1.59  -2.17   0.0    0.23  -1.23  -0.97   1.19  -0.22   0.30

       [,11]  [,12]  [,13]  [,14]  [,15]  [,16]  [,17]  [,18]  [,19]  [,20]
[1,]   -1.63  -0.34   1.63   0.95  -1.44  -0.01   2.01   2.28  -0.11  -0.82
[2,]   -1.33  -1.86  -0.14  -1.38   0.23   1.59  -0.58   1.05   0.64   1.17
[3,]    1.75  -1.02  -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); cor(xmat,trim=.2)

Array:
4 by 4

          [,1]         [,2]         [,3]        [,4]
[1,]    1.000000    0.1724203    0.1444275   -0.3820248
[2,]    0.1724204   1.000000    -0.00557457  -0.2757534
[3,]    0.1444275  -0.00557457   1.000000    -0.0639898
[4,]   -0.3820248  -0.2757534   -0.06398981   1.000000


Array:
4 by 4

          [,1]        [,2]       [,3]       [,4]
[1,]    1.000000   0.1068677  0.4583029  -0.3285165
[2,]    0.1068677  1.000000   0.4721279   0.2728199
[3,]    0.4583029  0.4721279  1.000000    0.3130877
[4,]   -0.3285165  0.2728199  0.3130877   1.000000

> yvec_rnorm(21)
> r_regress(xmat,yvec)
                Coef      Std Err   t Value
Intercept   -0.1876900   0.1675683    -1.12
x2           0.00937105  0.1597464     0.06
x3          -0.08409706  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    0.02807914
x2          -0.006869034   0.02551890
x3          -0.000368600  -0.002317685  0.03342703
x4           0.000734200  -0.003013160  0.000896918  2.03142e-2
x5          -0.004468527   0.008304762  0.006312403  3.69059e-4  0.02234143

Correlation matrix of coefficients:
             Intercept       x2         x3          x4
x2          -0.2566095
x3          -0.01203135  -0.079355
x4           0.03074132  -0.132340  0.03441945
x5          -0.1784091    0.347809  0.2309884   0.01732369

> regprt(r,names=encode("X Variable",1:4))
                   Coef      Std Err   t Value
Intercept      -0.1876900   0.1675683    -1.12
X Variable 1    0.00937105  0.1597464     0.06
X Variable 2   -0.08409706  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       0.02807914
X Variable 1   -0.006869034   0.02551890
X Variable 2   -0.000368600  -0.002317685   0.03342703
X Variable 3    0.000734200  -0.003013160   0.000896918    2.03142e-2
X Variable 4   -0.004468527   0.008304762   0.006312403    3.69059e-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.079355
X Variable 3    0.03074132     -0.132340    0.03441945
X Variable 4   -0.1784091       0.347809    0.2309884     0.01732369

> regsum(r)

 $names
      "Intercept"  "x2"         "x3"         "x4"         "x5"
 $ynames
      "y1"
 $table
Array:
5 by 3

           [,1]        [,2]       [,3]
[1,]   -0.1876900   0.1675683  -1.120080
[2,]    0.00937105  0.1597464   0.0586621
[3,]   -0.08409706  0.1828306  -0.4599725
[4,]    0.04649424  0.1425279   0.3262114
[5,]    0.02949429  0.1494705   0.1973252

 $coef
Array:
5 by 1

           [,1]
[1,]   -0.1876900
[2,]    0.00937105
[3,]   -0.08409706
[4,]    0.04649424
[5,]    0.02949429

 $stderr
Array:
5 by 1

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

 $t
Array:
5 by 1

          [,1]
[1,]   -1.120080
[2,]    0.0586621
[3,]   -0.4599725
[4,]    0.3262114
[5,]    0.1973252

 $cor
Array:
5 by 5

           [,1]        [,2]         [,3]         [,4]         [,5]
[1,]    1.000000    -0.2566095  -0.01203135   0.03074132  -0.1784091
[2,]   -0.2566095    1.000000   -0.07935503  -0.1323400    0.3478089
[3,]   -0.01203135  -0.0793550   1.000000     0.03441945   0.2309884
[4,]    0.03074132  -0.1323400   0.03441945   1.000000     0.01732369
[5,]   -0.1784091    0.3478090   0.2309884    0.01732369   1.000000

 $cov
Array:
5 by 5

           [,1]          [,2]          [,3]          [,4]         [,5]
[1,]    0.02807914   -0.006869034  -0.000368600  7.34200e-4   -0.004468527
[2,]   -0.006869034   0.02551890   -0.002317685  -3.01316e-3   0.008304762
[3,]   -0.000368600  -0.002317685   0.03342703   8.96918e-4    0.006312403
[4,]    0.000734200  -0.003013160   0.000896918  2.03142e-2    0.000369059
[5,]   -0.004468527   0.008304762   0.006312403  3.69059e-4    0.02234142

 $rsq
      0.0259949
 $rms
      0.73856
 $fval
      0.1067547
 $df
       4  16
> sum(abs(yvec-r$resid-cbind(1,xmat)%*r$coef))	# should be near zero
      6.10482e-7
> twoway(xmat)->t	# should get warning
Warning: t is a function name. Use    print(t)    to print this dataset
> fit_matrix(t$row,nrow(xmat),ncol(xmat))+matrix(t$col,nrow(xmat),ncol(xmat),byrow=TRUE)+
+ t$grand
> sum(abs(fit+t$resid-xmat))
      4.427275e-6
> timeser_ts(1:20,c(1958,3),12)
> print(start(timeser),end(timeser),nper(timeser))
      1958     3
      1959    10
      12
> print(cbind(time(timeser),cycle(timeser),timeser%mINT),rowlab="")	# no row labels

Array:
20 by 3

     [,1]    [,2]  [,3]
   1958.167     3     1
   1958.250     4     2
   1958.333     5     3
   1958.417     6     4
   1958.500     7     5
   1958.583     8     6
   1958.667     9     7
   1958.750    10     8
   1958.833    11     9
   1958.917    12    10
   1959.000     1    11
   1959.083     2    12
   1959.167     3    13
   1959.250     4    14
   1959.333     5    15
   1959.417     6    16
   1959.500     7    17
   1959.583     8    18
   1959.667     9    19
   1959.750    10    20

> mm_matrix(runif(16),4,4)
> if(any(diag(mm)!=mm[row(mm)==col(mm)]))"We got troubles"
> diag(3);diag(diag(mm))

Array:
3 by 3

       [,1]  [,2]  [,3]
[1,]      1     0     0
[2,]      0     1     0
[3,]      0     0     1


Array:
4 by 4

          [,1]      [,2]       [,3]      [,4]
[1,]   0.4826276  0.0       0.0        0.0
[2,]   0.0        0.814387  0.0        0.0
[3,]   0.0        0.0       0.5399635  0.0
[4,]   0.0        0.0       0.0        0.956938

> mm[1,3]_NA
> replace(mm,3,1,10000000)

Array:
4 by 4

           [,1]        [,2]       [,3]       [,4]
[1,]   4.826276e-1  0.1178895         NA  0.1897214
[2,]   9.950731e-1  0.8143874  0.8290446  0.4919873
[3,]   1.000000e7   0.9797957  0.5399635  0.6738488
[4,]   3.908283e-1  0.5345189  0.1673725  0.9569381

> append(mm,1:5)	#should end in 1:5 and be a vector, not matrix
       0.4826276  0.9950731  0.8679035  0.3908283  0.1178895  0.8143874
[ 7]   0.9797957  0.5345189         NA  0.8290446  0.5399635  0.1673725
[13]   0.1897214  0.4919873  0.6738488  0.9569381  1.000000   2.000000
[19]   3.000000   4.000000   5.000000
> pmin(c(1,3,9),c(2,2,20))
       1   2   9
> pmax(c(1,3,9),c(2,2,20))
       2   3  20
> min(smooth(1:20)==1:20)	# should be 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,nper=1)
> smooth(deposits)

Time-series:
start: 1921   end: 1967   Yearly


 1921    228.3125     228.4375     228.6875     229.4375     229.6953
 1926    228.6562     227.2968     230.0312     243.1250     263.2812
 1931    279.6328     277.1875     237.0000     169.5625     118.0039
 1936    102.6601     107.2695     114.5742     116.0937     104.8632
 1941     85.25781     69.07421     54.65234     35.02343     15.28515
 1946      3.261719    -1.296875    -2.050781     1.468750    13.95703
 1951     34.60937     54.26171     70.37500     86.50000     97.93750
 1956    101.0468      99.59375     95.89062     92.09375     91.07421
 1961     95.27734    108.0898     126.5708     138.6816     135.9213
 1966    121.7773     105.8498

> range(rnorm(1000))
      -3.103406   3.010009
> ifelse(runif(10)>.5,"heads","tails")
       "tails"  "heads"  "heads"  "tails"  "tails"  "tails"  "heads"  "tails"
[ 9]   "tails"  "heads"
> na(c(1,3,NA,4,3/0))
Warning in /: Missing values generated from zero or negative data
      F  F  T  F  T
> print(len(xmat),mode(xmat))
      84
       3
> prod(1:10)==3628800
      T
> l_order(xmat[,1]);print(xmat[l,],rowlab=(1:nrow(xmat))%mCHAR)# first col should be sorted

Array:
21 by 4

         [,1]        [,2]         [,3]        [,4]
1    -1.627426    -1.332798    1.752693     1.964440
2    -1.444328     0.2262369   1.286279    -0.5835849
3    -0.8241963    1.173095    0.03640984   1.139062
4    -0.6597047   -0.0911310  -0.9680680   -0.7391058
5    -0.6468606   -0.3891527  -1.229570    -0.7307574
6    -0.3978563    0.2786774   0.3013620    0.7213556
7    -0.3404882   -1.855024   -1.021658     0.6374954
8    -0.2956213   -1.441778   -0.00246192   2.185944
9    -0.2133813   -0.2383658  -0.2185530   -0.1779123
10   -0.1845264    0.8639906   0.2320923    0.2545508
11   -0.1084012    0.6359047  -1.434693    -0.2442183
12   -0.01028036   1.591098   -0.4189704    1.025279
13    0.02307979   0.5224685  -1.593777     0.7122022
14    0.2837263   -0.4524699  -2.170554     1.102465
15    0.9465387   -1.377914    2.072354     0.5026838
16    1.000000     1.000000    1.000000    -3.022151
17    1.469709     0.3536793   1.188760    -0.0232117
18    1.630031    -0.1430971  -0.4066366   -0.3807903
19    1.997031     0.3351039   1.026755    -1.984609
20    2.010499    -0.5826148  -0.6271965   -0.9497826
21    2.283485     1.053797    1.113559     0.9374829

> dput(xmat,file="tttt"); dget("tttt")

Array:
21 by 4

            [,1]        [,2]         [,3]        [,4]
[ 1,]    1.997030     0.3351040   1.026756    -1.984609
[ 2,]    0.02307980   0.5224685  -1.593778     0.7122020
[ 3,]    0.2837264   -0.4524700  -2.170555     1.102465
[ 4,]   -0.2956213   -1.441777   -0.00246192   2.185944
[ 5,]   -0.1845265    0.8639910   0.2320924    0.2545508
[ 6,]   -0.6468607   -0.3891527  -1.229570    -0.7307570
[ 7,]   -0.6597049   -0.0911310  -0.9680680   -0.7391060
[ 8,]    1.469710     0.3536793   1.188760    -0.0232117
[ 9,]   -0.2133813   -0.2383658  -0.2185530   -0.1779123
[10,]   -0.3978564    0.2786774   0.3013620    0.7213556
[11,]   -1.627427    -1.332798    1.752693     1.964439
[12,]   -0.3404883   -1.855023   -1.021659     0.6374950
[13,]    1.630031    -0.1430970  -0.4066366   -0.3807903
[14,]    0.9465390   -1.377913    2.072355     0.5026840
[15,]   -1.444327     0.2262370   1.286280    -0.5835850
[16,]   -0.01028036   1.591099   -0.4189704    1.025279
[17,]    2.010499    -0.5826150  -0.6271965   -0.9497831
[18,]    2.283484     1.053797    1.113559     0.9374831
[19,]   -0.1084012    0.6359050  -1.434693    -0.2442183
[20,]   -0.8241959    1.173094    0.03640984   1.139063
[21,]    1.000000     1.000000    1.000000    -3.022150

> # try the mail command to give feedback about the test
> !rm tttt
> source()	# should exit the file
> # so that this line isn't executed
3.3u 1.8s 7r 	 /usr/s/cmd/RUN.S
