reg-tests-2.Rout.save 207 KB
Newer Older
1

2 3
R version 3.5.0 alpha (2018-03-27 r74478)
Copyright (C) 2018 The R Foundation for Statistical Computing
4
Platform: x86_64-pc-linux-gnu (64-bit)
5 6 7

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
8
Type 'license()' or 'licence()' for distribution details.
9 10

R is a collaborative project with many contributors.
11 12
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
13

14
Type 'demo()' for some demos, 'help()' for on-line help, or
15
'help.start()' for an HTML browser interface to help.
16
Type 'q()' to quit R.
17

18 19 20
> ## Regression tests for which the printed output is the issue
> ### _and_ must work (no Recommended packages, please)
> 
21
> pdf("reg-tests-2.pdf", encoding = "ISOLatin1.enc")
22
> 
23 24
> ## force standard handling for data frames
> options(stringsAsFactors=TRUE)
25
> options(useFancyQuotes=FALSE)
26
> 
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
> ### moved from various .Rd files
> ## abbreviate
> for(m in 1:5) {
+   cat("\n",m,":\n")
+   print(as.vector(abbreviate(state.name, minl=m)))
+ }

 1 :
 [1] "Alb"  "Als"  "Arz"  "Ark"  "Clf"  "Clr"  "Cn"   "D"    "F"    "G"   
[11] "H"    "Id"   "Il"   "In"   "Iw"   "Kns"  "Knt"  "L"    "Man"  "Mr"  
[21] "Mssc" "Mc"   "Mnn"  "Msss" "Mssr" "Mnt"  "Nb"   "Nv"   "NH"   "NJ"  
[31] "NM"   "NY"   "NC"   "ND"   "Oh"   "Ok"   "Or"   "P"    "RI"   "SC"  
[41] "SD"   "Tn"   "Tx"   "U"    "Vrm"  "Vrg"  "Wsh"  "WV"   "Wsc"  "Wy"  

 2 :
 [1] "Alb"  "Als"  "Arz"  "Ark"  "Clf"  "Clr"  "Cn"   "Dl"   "Fl"   "Gr"  
[11] "Hw"   "Id"   "Il"   "In"   "Iw"   "Kns"  "Knt"  "Ls"   "Man"  "Mr"  
[21] "Mssc" "Mc"   "Mnn"  "Msss" "Mssr" "Mnt"  "Nb"   "Nv"   "NH"   "NJ"  
[31] "NM"   "NY"   "NC"   "ND"   "Oh"   "Ok"   "Or"   "Pn"   "RI"   "SC"  
[41] "SD"   "Tn"   "Tx"   "Ut"   "Vrm"  "Vrg"  "Wsh"  "WV"   "Wsc"  "Wy"  

 3 :
 [1] "Alb"  "Als"  "Arz"  "Ark"  "Clf"  "Clr"  "Cnn"  "Dlw"  "Flr"  "Grg" 
[11] "Haw"  "Idh"  "Ill"  "Ind"  "Iow"  "Kns"  "Knt"  "Lsn"  "Man"  "Mry" 
[21] "Mssc" "Mch"  "Mnn"  "Msss" "Mssr" "Mnt"  "Nbr"  "Nvd"  "NwH"  "NwJ" 
[31] "NwM"  "NwY"  "NrC"  "NrD"  "Ohi"  "Okl"  "Org"  "Pnn"  "RhI"  "StC" 
[41] "StD"  "Tnn"  "Txs"  "Uth"  "Vrm"  "Vrg"  "Wsh"  "WsV"  "Wsc"  "Wym" 

 4 :
 [1] "Albm" "Alsk" "Arzn" "Arkn" "Clfr" "Clrd" "Cnnc" "Dlwr" "Flrd" "Gerg"
[11] "Hawa" "Idah" "Illn" "Indn" "Iowa" "Knss" "Kntc" "Losn" "Main" "Mryl"
[21] "Mssc" "Mchg" "Mnns" "Msss" "Mssr" "Mntn" "Nbrs" "Nevd" "NwHm" "NwJr"
[31] "NwMx" "NwYr" "NrtC" "NrtD" "Ohio" "Oklh" "Orgn" "Pnns" "RhdI" "SthC"
[41] "SthD" "Tnns" "Texs" "Utah" "Vrmn" "Vrgn" "Wshn" "WstV" "Wscn" "Wymn"

 5 :
 [1] "Alabm" "Alask" "Arizn" "Arkns" "Clfrn" "Colrd" "Cnnct" "Delwr" "Flord"
[10] "Georg" "Hawai" "Idaho" "Illns" "Indin" "Iowa"  "Kanss" "Kntck" "Lousn"
[19] "Maine" "Mryln" "Mssch" "Mchgn" "Mnnst" "Mssss" "Missr" "Montn" "Nbrsk"
[28] "Nevad" "NwHmp" "NwJrs" "NwMxc" "NwYrk" "NrthC" "NrthD" "Ohio"  "Oklhm"
[37] "Oregn" "Pnnsy" "RhdIs" "SthCr" "SthDk" "Tnnss" "Texas" "Utah"  "Vrmnt"
[46] "Virgn" "Wshng" "WstVr" "Wscns" "Wymng"
> 
> ## apply
> x <- cbind(x1 = 3, x2 = c(4:1, 2:5))
> dimnames(x)[[1]] <- letters[1:8]
> apply(x,  2, summary) # 6 x n matrix
        x1 x2
Min.     3  1
1st Qu.  3  2
Median   3  3
Mean     3  3
3rd Qu.  3  4
Max.     3  5
> apply(x,  1, quantile)# 5 x n matrix
        a b    c   d    e f    g   h
0%   3.00 3 2.00 1.0 2.00 3 3.00 3.0
25%  3.25 3 2.25 1.5 2.25 3 3.25 3.5
50%  3.50 3 2.50 2.0 2.50 3 3.50 4.0
75%  3.75 3 2.75 2.5 2.75 3 3.75 4.5
100% 4.00 3 3.00 3.0 3.00 3 4.00 5.0
> 
> d.arr <- 2:5
> arr <- array(1:prod(d.arr), d.arr,
+          list(NULL,letters[1:d.arr[2]],NULL,paste("V",4+1:d.arr[4],sep="")))
> aa <- array(1:20,c(2,2,5))
> str(apply(aa[FALSE,,,drop=FALSE], 1, dim))# empty integer, `incorrect' dim.
94
 int(0) 
95 96 97 98
> stopifnot(
+        apply(arr, 1:2, sum) == t(apply(arr, 2:1, sum)),
+        aa == apply(aa,2:3,function(x) x),
+        all.equal(apply(apply(aa,2:3, sum),2,sum),
99
+                  10+16*0:4, tolerance = 4*.Machine$double.eps)
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
+ )
> marg <- list(1:2, 2:3, c(2,4), c(1,3), 2:4, 1:3, 1:4)
> for(m in marg) print(apply(arr, print(m), sum))
[1] 1 2
        a    b    c
[1,] 1160 1200 1240
[2,] 1180 1220 1260
[1] 2 3
  [,1] [,2] [,3] [,4]
a  495  555  615  675
b  515  575  635  695
c  535  595  655  715
[1] 2 4
   V5  V6  V7  V8  V9
a  84 276 468 660 852
b 100 292 484 676 868
c 116 308 500 692 884
[1] 1 3
     [,1] [,2] [,3] [,4]
[1,]  765  855  945 1035
[2,]  780  870  960 1050
[1] 2 3 4
, , V5

  [,1] [,2] [,3] [,4]
a    3   15   27   39
b    7   19   31   43
c   11   23   35   47

, , V6

  [,1] [,2] [,3] [,4]
a   51   63   75   87
b   55   67   79   91
c   59   71   83   95

, , V7

  [,1] [,2] [,3] [,4]
a   99  111  123  135
b  103  115  127  139
c  107  119  131  143

, , V8

  [,1] [,2] [,3] [,4]
a  147  159  171  183
b  151  163  175  187
c  155  167  179  191

, , V9

  [,1] [,2] [,3] [,4]
a  195  207  219  231
b  199  211  223  235
c  203  215  227  239

[1] 1 2 3
, , 1

       a   b   c
[1,] 245 255 265
[2,] 250 260 270

, , 2

       a   b   c
[1,] 275 285 295
[2,] 280 290 300

, , 3

       a   b   c
[1,] 305 315 325
[2,] 310 320 330

, , 4

       a   b   c
[1,] 335 345 355
[2,] 340 350 360

[1] 1 2 3 4
, , 1, V5

     a b c
[1,] 1 3 5
[2,] 2 4 6

, , 2, V5

     a  b  c
[1,] 7  9 11
[2,] 8 10 12

, , 3, V5

      a  b  c
[1,] 13 15 17
[2,] 14 16 18

, , 4, V5

      a  b  c
[1,] 19 21 23
[2,] 20 22 24

, , 1, V6

      a  b  c
[1,] 25 27 29
[2,] 26 28 30

, , 2, V6

      a  b  c
[1,] 31 33 35
[2,] 32 34 36

, , 3, V6

      a  b  c
[1,] 37 39 41
[2,] 38 40 42

, , 4, V6

      a  b  c
[1,] 43 45 47
[2,] 44 46 48

, , 1, V7

      a  b  c
[1,] 49 51 53
[2,] 50 52 54

, , 2, V7

      a  b  c
[1,] 55 57 59
[2,] 56 58 60

, , 3, V7

      a  b  c
[1,] 61 63 65
[2,] 62 64 66

, , 4, V7

      a  b  c
[1,] 67 69 71
[2,] 68 70 72

, , 1, V8

      a  b  c
[1,] 73 75 77
[2,] 74 76 78

, , 2, V8

      a  b  c
[1,] 79 81 83
[2,] 80 82 84

, , 3, V8

      a  b  c
[1,] 85 87 89
[2,] 86 88 90

, , 4, V8

      a  b  c
[1,] 91 93 95
[2,] 92 94 96

, , 1, V9

      a   b   c
[1,] 97  99 101
[2,] 98 100 102

, , 2, V9

       a   b   c
[1,] 103 105 107
[2,] 104 106 108

, , 3, V9

       a   b   c
[1,] 109 111 113
[2,] 110 112 114

, , 4, V9

       a   b   c
[1,] 115 117 119
[2,] 116 118 120

> for(m in marg) ## 75% of the time here was spent on the names
+   print(dim(apply(arr, print(m), quantile, names=FALSE)) == c(5,d.arr[m]))
[1] 1 2
[1] TRUE TRUE TRUE
[1] 2 3
[1] TRUE TRUE TRUE
[1] 2 4
[1] TRUE TRUE TRUE
[1] 1 3
[1] TRUE TRUE TRUE
[1] 2 3 4
[1] TRUE TRUE TRUE TRUE
[1] 1 2 3
[1] TRUE TRUE TRUE TRUE
[1] 1 2 3 4
[1] TRUE TRUE TRUE TRUE TRUE
> 
> ## Bessel
> nus <- c(0:5,10,20)
> 
> x0 <- 2^(-20:10)
> plot(x0,x0, log='xy', ylab="", ylim=c(.1,1e60),type='n',
+      main = "Bessel Functions -Y_nu(x)  near 0\n log - log  scale")
> for(nu in sort(c(nus,nus+.5))) lines(x0, -besselY(x0,nu=nu), col = nu+2)
> legend(3,1e50, leg=paste("nu=", paste(nus,nus+.5, sep=",")), col=nus+2, lwd=1)
> 
> x <- seq(3,500);yl <- c(-.3, .2)
> plot(x,x, ylim = yl, ylab="",type='n', main = "Bessel Functions  Y_nu(x)")
> for(nu in nus){xx <- x[x > .6*nu]; lines(xx,besselY(xx,nu=nu), col = nu+2)}
> legend(300,-.08, leg=paste("nu=",nus), col = nus+2, lwd=1)
> 
> x <- seq(10,50000,by=10);yl <- c(-.1, .1)
> plot(x,x, ylim = yl, ylab="",type='n', main = "Bessel Functions  Y_nu(x)")
> for(nu in nus){xx <- x[x > .6*nu]; lines(xx,besselY(xx,nu=nu), col = nu+2)}
> summary(bY <- besselY(2,nu = nu <- seq(0,100,len=501)))
       Min.     1st Qu.      Median        Mean     3rd Qu.        Max. 
339
-3.001e+155 -1.067e+107  -1.976e+62 -9.961e+152  -2.059e+23   1.000e+00 
340 341 342 343
> which(bY >= 0)
[1] 1 2 3 4 5
> summary(bY <- besselY(2,nu = nu <- seq(3,300,len=51)))
       Min.     1st Qu.      Median        Mean     3rd Qu.        Max. 
344
       -Inf        -Inf -2.248e+263        -Inf -3.777e+116  -1.000e+00 
345 346 347 348 349 350 351 352 353
There were 22 warnings (use warnings() to see them)
> summary(bI <- besselI(x = x <- 10:700, 1))
      Min.    1st Qu.     Median       Mean    3rd Qu.       Max. 
 2.671e+03  6.026e+77 3.161e+152 3.501e+299 2.409e+227 1.529e+302 
> ## end of moved from Bessel.Rd
> 
> ## data.frame
> set.seed(123)
> L3 <- LETTERS[1:3]
354 355
> d <- data.frame(cbind(x=1, y=1:10), fac = sample(L3, 10, replace=TRUE))
> str(d)
356
'data.frame':	10 obs. of  3 variables:
357 358
 $ x  : num  1 1 1 1 1 1 1 1 1 1
 $ y  : num  1 2 3 4 5 6 7 8 9 10
359
 $ fac: Factor w/ 3 levels "A","B","C": 1 3 2 3 3 1 2 3 2 2
360
> (d0  <- d[, FALSE]) # NULL dataframe with 10 rows
361
data frame with 0 columns and 10 rows
362 363 364
> (d.0 <- d[FALSE, ]) # <0 rows> dataframe  (3 cols)
[1] x   y   fac
<0 rows> (or 0-length row.names)
365
> (d00 <- d0[FALSE,]) # NULL dataframe with 0 rows
366
data frame with 0 columns and 0 rows
367
> stopifnot(identical(d, cbind(d, d0)),
368 369
+           identical(d, cbind(d0, d)))
> stopifnot(identical(d, rbind(d,d.0)),
370 371
+           identical(d, rbind(d.0,d)),
+           identical(d, rbind(d00,d)),
372
+           identical(d, rbind(d,d00)))
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
> ## Comments: failed before ver. 1.4.0
> 
> ## diag
> diag(array(1:4, dim=5))
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    0    0    0    0
[2,]    0    2    0    0    0
[3,]    0    0    3    0    0
[4,]    0    0    0    4    0
[5,]    0    0    0    0    1
> ## test behaviour with 0 rows or columns
> diag(0)
<0 x 0 matrix>
> z <- matrix(0, 0, 4)
> diag(z)
numeric(0)
> diag(z) <- numeric(0)
> z
     [,1] [,2] [,3] [,4]
> ## end of moved from diag.Rd
> 
> ## format
> ## handling of quotes
> zz <- data.frame(a=I("abc"), b=I("def\"gh"))
> format(zz)
    a      b
1 abc def"gh
> ## " (E fontification)
> 
> ## printing more than 16 is platform-dependent
> for(i in c(1:5,10,15,16)) cat(i,":\t",format(pi,digits=i),"\n")
1 :	 3 
2 :	 3.1 
3 :	 3.14 
4 :	 3.142 
5 :	 3.1416 
10 :	 3.141592654 
15 :	 3.14159265358979 
16 :	 3.141592653589793 
> 
> p <- c(47,13,2,.1,.023,.0045, 1e-100)/1000
> format.pval(p)
[1] "0.0470"  "0.0130"  "0.0020"  "0.0001"  "2.3e-05" "4.5e-06" "< 2e-16"
> format.pval(p / 0.9)
[1] "0.05222222" "0.01444444" "0.00222222" "0.00011111" "2.5556e-05"
[6] "5.0000e-06" "< 2.22e-16"
> format.pval(p / 0.9, dig=3)
[1] "0.052222" "0.014444" "0.002222" "0.000111" "2.56e-05" "5.00e-06" "< 2e-16" 
> ## end of moved from format.Rd
> 
> 
> ## is.finite
> x <- c(100,-1e-13,Inf,-Inf, NaN, pi, NA)
> x #  1.000000 -3.000000       Inf      -Inf        NA  3.141593        NA
[1]  1.000000e+02 -1.000000e-13           Inf          -Inf           NaN
[6]  3.141593e+00            NA
> names(x) <- formatC(x, dig=3)
> is.finite(x)
   100 -1e-13    Inf   -Inf    NaN   3.14     NA 
  TRUE   TRUE  FALSE  FALSE  FALSE   TRUE  FALSE 
> ##-   100 -1e-13 Inf -Inf NaN 3.14 NA
> ##-     T      T   .    .   .    T  .
> is.na(x)
   100 -1e-13    Inf   -Inf    NaN   3.14     NA 
 FALSE  FALSE  FALSE  FALSE   TRUE  FALSE   TRUE 
> ##-   100 -1e-13 Inf -Inf NaN 3.14 NA
> ##-     .      .   .    .   T    .  T
> which(is.na(x) & !is.nan(x))# only 'NA': 7
  NA 
   7 
> 
> is.na(x) | is.finite(x)
   100 -1e-13    Inf   -Inf    NaN   3.14     NA 
  TRUE   TRUE  FALSE  FALSE   TRUE   TRUE   TRUE 
> ##-   100 -1e-13 Inf -Inf NaN 3.14 NA
> ##-     T      T   .    .   T    T  T
> is.infinite(x)
   100 -1e-13    Inf   -Inf    NaN   3.14     NA 
 FALSE  FALSE   TRUE   TRUE  FALSE  FALSE  FALSE 
> ##-   100 -1e-13 Inf -Inf NaN 3.14 NA
> ##-     .      .   T    T   .    .  .
> 
> ##-- either  finite or infinite  or  NA:
> all(is.na(x) != is.finite(x) | is.infinite(x)) # TRUE
[1] TRUE
> all(is.nan(x) != is.finite(x) | is.infinite(x)) # FALSE: have 'real' NA
[1] FALSE
> 
> ##--- Integer
> (ix <- structure(as.integer(x),names= names(x)))
   100 -1e-13    Inf   -Inf    NaN   3.14     NA 
   100      0     NA     NA     NA      3     NA 
465
Warning message:
466 467
In structure(as.integer(x), names = names(x)) :
  NAs introduced by coercion to integer range
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
> ##-   100 -1e-13    Inf   -Inf    NaN   3.14     NA
> ##-   100      0     NA     NA     NA      3     NA
> all(is.na(ix) != is.finite(ix) | is.infinite(ix)) # TRUE (still)
[1] TRUE
> 
> storage.mode(ii <- -3:5)
[1] "integer"
> storage.mode(zm <- outer(ii,ii, FUN="*"))# integer
[1] "double"
> storage.mode(zd <- outer(ii,ii, FUN="/"))# double
[1] "double"
> range(zd, na.rm=TRUE)# -Inf  Inf
[1] -Inf  Inf
> zd[,ii==0]
[1] -Inf -Inf -Inf  NaN  Inf  Inf  Inf  Inf  Inf
> 
> (storage.mode(print(1:1 / 0:0)))# Inf "double"
[1] Inf
[1] "double"
> (storage.mode(print(1:1 / 1:1)))# 1 "double"
[1] 1
[1] "double"
> (storage.mode(print(1:1 + 1:1)))# 2 "integer"
[1] 2
[1] "integer"
> (storage.mode(print(2:2 * 2:2)))# 4 "integer"
[1] 4
[1] "integer"
> ## end of moved from is.finite.Rd
> 
> 
> ## kronecker
> fred <- matrix(1:12, 3, 4, dimnames=list(LETTERS[1:3], LETTERS[4:7]))
> bill <- c("happy" = 100, "sad" = 1000)
> kronecker(fred, bill, make.dimnames = TRUE)
          D:   E:   F:    G:
A:happy  100  400  700  1000
A:sad   1000 4000 7000 10000
B:happy  200  500  800  1100
B:sad   2000 5000 8000 11000
C:happy  300  600  900  1200
C:sad   3000 6000 9000 12000
> 
> bill <- outer(bill, c("cat"=3, "dog"=4))
> kronecker(fred, bill, make.dimnames = TRUE)
        D:cat D:dog E:cat E:dog F:cat F:dog G:cat G:dog
A:happy   300   400  1200  1600  2100  2800  3000  4000
A:sad    3000  4000 12000 16000 21000 28000 30000 40000
B:happy   600   800  1500  2000  2400  3200  3300  4400
B:sad    6000  8000 15000 20000 24000 32000 33000 44000
C:happy   900  1200  1800  2400  2700  3600  3600  4800
C:sad    9000 12000 18000 24000 27000 36000 36000 48000
> 
> # dimnames are hard work: let's test them thoroughly
> 
> dimnames(bill) <- NULL
> kronecker(fred, bill, make=TRUE)
     D:    D:    E:    E:    F:    F:    G:    G:
A:  300   400  1200  1600  2100  2800  3000  4000
A: 3000  4000 12000 16000 21000 28000 30000 40000
B:  600   800  1500  2000  2400  3200  3300  4400
B: 6000  8000 15000 20000 24000 32000 33000 44000
C:  900  1200  1800  2400  2700  3600  3600  4800
C: 9000 12000 18000 24000 27000 36000 36000 48000
> kronecker(bill, fred, make=TRUE)
     :D    :E    :F    :G    :D    :E    :F    :G
:A  300  1200  2100  3000   400  1600  2800  4000
:B  600  1500  2400  3300   800  2000  3200  4400
:C  900  1800  2700  3600  1200  2400  3600  4800
:A 3000 12000 21000 30000  4000 16000 28000 40000
:B 6000 15000 24000 33000  8000 20000 32000 44000
:C 9000 18000 27000 36000 12000 24000 36000 48000
> 
> dim(bill) <- c(2, 2, 1)
> dimnames(bill) <- list(c("happy", "sad"), NULL, "")
> kronecker(fred, bill, make=TRUE)
, , :

          D:    D:    E:    E:    F:    F:    G:    G:
A:happy  300   400  1200  1600  2100  2800  3000  4000
A:sad   3000  4000 12000 16000 21000 28000 30000 40000
B:happy  600   800  1500  2000  2400  3200  3300  4400
B:sad   6000  8000 15000 20000 24000 32000 33000 44000
C:happy  900  1200  1800  2400  2700  3600  3600  4800
C:sad   9000 12000 18000 24000 27000 36000 36000 48000

> 
> bill <- array(1:24, c(3, 4, 2))
> dimnames(bill) <- list(NULL, NULL, c("happy", "sad"))
> kronecker(bill, fred, make=TRUE)
, , happy:

   :D :E :F :G :D :E :F :G :D :E :F  :G :D :E  :F  :G
:A  1  4  7 10  4 16 28 40  7 28 49  70 10 40  70 100
:B  2  5  8 11  8 20 32 44 14 35 56  77 20 50  80 110
:C  3  6  9 12 12 24 36 48 21 42 63  84 30 60  90 120
:A  2  8 14 20  5 20 35 50  8 32 56  80 11 44  77 110
:B  4 10 16 22 10 25 40 55 16 40 64  88 22 55  88 121
:C  6 12 18 24 15 30 45 60 24 48 72  96 33 66  99 132
:A  3 12 21 30  6 24 42 60  9 36 63  90 12 48  84 120
:B  6 15 24 33 12 30 48 66 18 45 72  99 24 60  96 132
:C  9 18 27 36 18 36 54 72 27 54 81 108 36 72 108 144

, , sad:

   :D :E  :F  :G :D  :E  :F  :G :D  :E  :F  :G :D  :E  :F  :G
:A 13 52  91 130 16  64 112 160 19  76 133 190 22  88 154 220
:B 26 65 104 143 32  80 128 176 38  95 152 209 44 110 176 242
:C 39 78 117 156 48  96 144 192 57 114 171 228 66 132 198 264
:A 14 56  98 140 17  68 119 170 20  80 140 200 23  92 161 230
:B 28 70 112 154 34  85 136 187 40 100 160 220 46 115 184 253
:C 42 84 126 168 51 102 153 204 60 120 180 240 69 138 207 276
:A 15 60 105 150 18  72 126 180 21  84 147 210 24  96 168 240
:B 30 75 120 165 36  90 144 198 42 105 168 231 48 120 192 264
:C 45 90 135 180 54 108 162 216 63 126 189 252 72 144 216 288

> kronecker(fred, bill, make=TRUE)
, , :happy

   D: D: D: D: E: E: E: E: F: F: F:  F: G: G:  G:  G:
A:  1  4  7 10  4 16 28 40  7 28 49  70 10 40  70 100
A:  2  5  8 11  8 20 32 44 14 35 56  77 20 50  80 110
A:  3  6  9 12 12 24 36 48 21 42 63  84 30 60  90 120
B:  2  8 14 20  5 20 35 50  8 32 56  80 11 44  77 110
B:  4 10 16 22 10 25 40 55 16 40 64  88 22 55  88 121
B:  6 12 18 24 15 30 45 60 24 48 72  96 33 66  99 132
C:  3 12 21 30  6 24 42 60  9 36 63  90 12 48  84 120
C:  6 15 24 33 12 30 48 66 18 45 72  99 24 60  96 132
C:  9 18 27 36 18 36 54 72 27 54 81 108 36 72 108 144

, , :sad

   D: D: D: D: E:  E:  E:  E:  F:  F:  F:  F:  G:  G:  G:  G:
A: 13 16 19 22 52  64  76  88  91 112 133 154 130 160 190 220
A: 14 17 20 23 56  68  80  92  98 119 140 161 140 170 200 230
A: 15 18 21 24 60  72  84  96 105 126 147 168 150 180 210 240
B: 26 32 38 44 65  80  95 110 104 128 152 176 143 176 209 242
B: 28 34 40 46 70  85 100 115 112 136 160 184 154 187 220 253
B: 30 36 42 48 75  90 105 120 120 144 168 192 165 198 231 264
C: 39 48 57 66 78  96 114 132 117 144 171 198 156 192 228 264
C: 42 51 60 69 84 102 120 138 126 153 180 207 168 204 240 276
C: 45 54 63 72 90 108 126 144 135 162 189 216 180 216 252 288

> 
> fred <- outer(fred, c("frequentist"=4, "bayesian"=4000))
> kronecker(fred, bill, make=TRUE)
, , frequentist:happy

   D: D:  D:  D: E:  E:  E:  E:  F:  F:  F:  F:  G:  G:  G:  G:
A:  4 16  28  40 16  64 112 160  28 112 196 280  40 160 280 400
A:  8 20  32  44 32  80 128 176  56 140 224 308  80 200 320 440
A: 12 24  36  48 48  96 144 192  84 168 252 336 120 240 360 480
B:  8 32  56  80 20  80 140 200  32 128 224 320  44 176 308 440
B: 16 40  64  88 40 100 160 220  64 160 256 352  88 220 352 484
B: 24 48  72  96 60 120 180 240  96 192 288 384 132 264 396 528
C: 12 48  84 120 24  96 168 240  36 144 252 360  48 192 336 480
C: 24 60  96 132 48 120 192 264  72 180 288 396  96 240 384 528
C: 36 72 108 144 72 144 216 288 108 216 324 432 144 288 432 576

, , frequentist:sad

    D:  D:  D:  D:  E:  E:  E:  E:  F:  F:  F:  F:  G:  G:   G:   G:
A:  52  64  76  88 208 256 304 352 364 448 532 616 520 640  760  880
A:  56  68  80  92 224 272 320 368 392 476 560 644 560 680  800  920
A:  60  72  84  96 240 288 336 384 420 504 588 672 600 720  840  960
B: 104 128 152 176 260 320 380 440 416 512 608 704 572 704  836  968
B: 112 136 160 184 280 340 400 460 448 544 640 736 616 748  880 1012
B: 120 144 168 192 300 360 420 480 480 576 672 768 660 792  924 1056
C: 156 192 228 264 312 384 456 528 468 576 684 792 624 768  912 1056
C: 168 204 240 276 336 408 480 552 504 612 720 828 672 816  960 1104
C: 180 216 252 288 360 432 504 576 540 648 756 864 720 864 1008 1152

, , bayesian:happy

      D:    D:     D:     D:    E:     E:     E:     E:     F:     F:     F:
A:  4000 16000  28000  40000 16000  64000 112000 160000  28000 112000 196000
A:  8000 20000  32000  44000 32000  80000 128000 176000  56000 140000 224000
A: 12000 24000  36000  48000 48000  96000 144000 192000  84000 168000 252000
B:  8000 32000  56000  80000 20000  80000 140000 200000  32000 128000 224000
B: 16000 40000  64000  88000 40000 100000 160000 220000  64000 160000 256000
B: 24000 48000  72000  96000 60000 120000 180000 240000  96000 192000 288000
C: 12000 48000  84000 120000 24000  96000 168000 240000  36000 144000 252000
C: 24000 60000  96000 132000 48000 120000 192000 264000  72000 180000 288000
C: 36000 72000 108000 144000 72000 144000 216000 288000 108000 216000 324000
       F:     G:     G:     G:     G:
A: 280000  40000 160000 280000 400000
A: 308000  80000 200000 320000 440000
A: 336000 120000 240000 360000 480000
B: 320000  44000 176000 308000 440000
B: 352000  88000 220000 352000 484000
B: 384000 132000 264000 396000 528000
C: 360000  48000 192000 336000 480000
C: 396000  96000 240000 384000 528000
C: 432000 144000 288000 432000 576000

, , bayesian:sad

       D:     D:     D:     D:     E:     E:     E:     E:     F:     F:     F:
A:  52000  64000  76000  88000 208000 256000 304000 352000 364000 448000 532000
A:  56000  68000  80000  92000 224000 272000 320000 368000 392000 476000 560000
A:  60000  72000  84000  96000 240000 288000 336000 384000 420000 504000 588000
B: 104000 128000 152000 176000 260000 320000 380000 440000 416000 512000 608000
B: 112000 136000 160000 184000 280000 340000 400000 460000 448000 544000 640000
B: 120000 144000 168000 192000 300000 360000 420000 480000 480000 576000 672000
C: 156000 192000 228000 264000 312000 384000 456000 528000 468000 576000 684000
C: 168000 204000 240000 276000 336000 408000 480000 552000 504000 612000 720000
C: 180000 216000 252000 288000 360000 432000 504000 576000 540000 648000 756000
       F:     G:     G:      G:      G:
A: 616000 520000 640000  760000  880000
A: 644000 560000 680000  800000  920000
A: 672000 600000 720000  840000  960000
B: 704000 572000 704000  836000  968000
B: 736000 616000 748000  880000 1012000
B: 768000 660000 792000  924000 1056000
C: 792000 624000 768000  912000 1056000
C: 828000 672000 816000  960000 1104000
C: 864000 720000 864000 1008000 1152000

> ## end of moved from kronecker.Rd
> 
> ## merge
> authors <- data.frame(
+     surname = c("Tukey", "Venables", "Tierney", "Ripley", "McNeil"),
+     nationality = c("US", "Australia", "US", "UK", "Australia"),
+     deceased = c("yes", rep("no", 4)))
> books <- data.frame(
+     name = c("Tukey", "Venables", "Tierney",
+              "Ripley", "Ripley", "McNeil", "R Core"),
+     title = c("Exploratory Data Analysis",
+               "Modern Applied Statistics ...",
+               "LISP-STAT",
+               "Spatial Statistics", "Stochastic Simulation",
+               "Interactive Data Analysis",
+               "An Introduction to R"),
+     other.author = c(NA, "Ripley", NA, NA, NA, NA,
+                      "Venables & Smith"))
> b2 <- books; names(b2)[1] <- names(authors)[1]
> 
> merge(authors, b2, all.x = TRUE)
   surname nationality deceased                         title other.author
1   McNeil   Australia       no     Interactive Data Analysis         <NA>
2   Ripley          UK       no            Spatial Statistics         <NA>
3   Ripley          UK       no         Stochastic Simulation         <NA>
4  Tierney          US       no                     LISP-STAT         <NA>
5    Tukey          US      yes     Exploratory Data Analysis         <NA>
6 Venables   Australia       no Modern Applied Statistics ...       Ripley
> merge(authors, b2, all.y = TRUE)
   surname nationality deceased                         title     other.author
1   McNeil   Australia       no     Interactive Data Analysis             <NA>
2   Ripley          UK       no            Spatial Statistics             <NA>
3   Ripley          UK       no         Stochastic Simulation             <NA>
4  Tierney          US       no                     LISP-STAT             <NA>
5    Tukey          US      yes     Exploratory Data Analysis             <NA>
6 Venables   Australia       no Modern Applied Statistics ...           Ripley
7   R Core        <NA>     <NA>          An Introduction to R Venables & Smith
> 
> ## empty d.f. :
> merge(authors, b2[7,])
[1] surname      nationality  deceased     title        other.author
<0 rows> (or 0-length row.names)
> 
> merge(authors, b2[7,], all.y = TRUE)
  surname nationality deceased                title     other.author
1  R Core        <NA>     <NA> An Introduction to R Venables & Smith
> merge(authors, b2[7,], all.x = TRUE)
   surname nationality deceased title other.author
1   McNeil   Australia       no  <NA>         <NA>
2   Ripley          UK       no  <NA>         <NA>
3  Tierney          US       no  <NA>         <NA>
4    Tukey          US      yes  <NA>         <NA>
5 Venables   Australia       no  <NA>         <NA>
> ## end of moved from merge.Rd
> 
> ## NA
> is.na(c(1,NA))
[1] FALSE  TRUE
> is.na(paste(c(1,NA)))
[1] FALSE FALSE
> is.na(list())# logical(0)
logical(0)
> ll <- list(pi,"C",NaN,Inf, 1:3, c(0,NA), NA)
> is.na (ll)
[1] FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772
> lapply(ll, is.nan)  # is.nan no longer works on lists
[[1]]
[1] FALSE

[[2]]
[1] FALSE

[[3]]
[1] TRUE

[[4]]
[1] FALSE

[[5]]
[1] FALSE FALSE FALSE

[[6]]
[1] FALSE FALSE

[[7]]
[1] FALSE

773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830
> ## end of moved from NA.Rd
> 
> ## is.na was returning unset values on nested lists
> ll <- list(list(1))
> for (i in 1:5) print(as.integer(is.na(ll)))
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
> 
> ## scale
> ## test out NA handling
> tm <- matrix(c(2,1,0,1,0,NA,NA,NA,0), nrow=3)
> scale(tm, , FALSE)
     [,1] [,2] [,3]
[1,]    1  0.5   NA
[2,]    0 -0.5   NA
[3,]   -1   NA    0
attr(,"scaled:center")
[1] 1.0 0.5 0.0
> scale(tm)
     [,1]       [,2] [,3]
[1,]    1  0.7071068   NA
[2,]    0 -0.7071068   NA
[3,]   -1         NA  NaN
attr(,"scaled:center")
[1] 1.0 0.5 0.0
attr(,"scaled:scale")
[1] 1.0000000 0.7071068 0.0000000
> ## end of moved from scale.Rd
> 
> ## tabulate
> tabulate(numeric(0))
[1] 0
> ## end of moved from tabulate.Rd
> 
> ## ts
> # Ensure working arithmetic for `ts' objects :
> stopifnot(z == z)
> stopifnot(z-z == 0)
> 
> ts(1:5, start=2, end=4) # truncate
Time Series:
Start = 2 
End = 4 
Frequency = 1 
[1] 1 2 3
> ts(1:5, start=3, end=17)# repeat
Time Series:
Start = 3 
End = 17 
Frequency = 1 
 [1] 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
> ## end of moved from ts.Rd
> 
> ### end of moved
> 
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
> 
> ## PR 715 (Printing list elements w/attributes)
> ##
> l <- list(a=10)
> attr(l$a, "xx") <- 23
> l
$a
[1] 10
attr(,"xx")
[1] 23

> ## Comments:
> ## should print as
> # $a:
> # [1] 10
> # attr($a, "xx"):
> # [1] 23
> 
> ## On the other hand
> m <- matrix(c(1, 2, 3, 0, 10, NA), 3, 2)
> na.omit(m)
     [,1] [,2]
[1,]    1    0
[2,]    2   10
attr(,"na.action")
[1] 3
857
attr(,"class")
858 859 860 861 862 863 864
[1] "omit"
> ## should print as
> #      [,1] [,2]
> # [1,]    1    0
> # [2,]    2   10
> # attr(,"na.action")
> # [1] 3
865
> # attr(,"na.action")
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965
> # [1] "omit"
> 
> ## and
> x <- 1
> attr(x, "foo") <- list(a="a")
> x
[1] 1
attr(,"foo")
attr(,"foo")$a
[1] "a"

> ## should print as
> # [1] 1
> # attr(,"foo")
> # attr(,"foo")$a
> # [1] "a"
> 
> 
> ## PR 746 (printing of lists)
> ##
> test.list <- list(A = list(formula=Y~X, subset=TRUE),
+                   B = list(formula=Y~X, subset=TRUE))
> 
> test.list
$A
$A$formula
Y ~ X

$A$subset
[1] TRUE


$B
$B$formula
Y ~ X

$B$subset
[1] TRUE


> ## Comments:
> ## should print as
> # $A
> # $A$formula
> # Y ~ X
> #
> # $A$subset
> # [1] TRUE
> #
> #
> # $B
> # $B$formula
> # Y ~ X
> #
> # $B$subset
> # [1] TRUE
> 
> ## Marc Feldesman 2001-Feb-01.  Precision in summary.data.frame & *.matrix
> summary(attenu)
     event            mag           station         dist       
 Min.   : 1.00   Min.   :5.000   117    :  5   Min.   :  0.50  
 1st Qu.: 9.00   1st Qu.:5.300   1028   :  4   1st Qu.: 11.32  
 Median :18.00   Median :6.100   113    :  4   Median : 23.40  
 Mean   :14.74   Mean   :6.084   112    :  3   Mean   : 45.60  
 3rd Qu.:20.00   3rd Qu.:6.600   135    :  3   3rd Qu.: 47.55  
 Max.   :23.00   Max.   :7.700   (Other):147   Max.   :370.00  
                                 NA's   : 16                   
     accel        
 Min.   :0.00300  
 1st Qu.:0.04425  
 Median :0.11300  
 Mean   :0.15422  
 3rd Qu.:0.21925  
 Max.   :0.81000  
                  
> summary(attenu, digits = 5)
     event             mag            station         dist        
 Min.   : 1.000   Min.   :5.0000   117    :  5   Min.   :  0.500  
 1st Qu.: 9.000   1st Qu.:5.3000   1028   :  4   1st Qu.: 11.325  
 Median :18.000   Median :6.1000   113    :  4   Median : 23.400  
 Mean   :14.742   Mean   :6.0841   112    :  3   Mean   : 45.603  
 3rd Qu.:20.000   3rd Qu.:6.6000   135    :  3   3rd Qu.: 47.550  
 Max.   :23.000   Max.   :7.7000   (Other):147   Max.   :370.000  
                                   NA's   : 16                    
     accel        
 Min.   :0.00300  
 1st Qu.:0.04425  
 Median :0.11300  
 Mean   :0.15422  
 3rd Qu.:0.21925  
 Max.   :0.81000  
                  
> summary(data.matrix(attenu), digits = 5)# the same for matrix
     event             mag            station             dist        
 Min.   : 1.000   Min.   :5.0000   Min.   :  1.000   Min.   :  0.500  
 1st Qu.: 9.000   1st Qu.:5.3000   1st Qu.: 24.250   1st Qu.: 11.325  
 Median :18.000   Median :6.1000   Median : 56.500   Median : 23.400  
 Mean   :14.742   Mean   :6.0841   Mean   : 56.928   Mean   : 45.603  
 3rd Qu.:20.000   3rd Qu.:6.6000   3rd Qu.: 86.750   3rd Qu.: 47.550  
 Max.   :23.000   Max.   :7.7000   Max.   :117.000   Max.   :370.000  
966
                                   NA's   :16                         
967 968 969 970 971 972 973 974 975 976 977 978 979 980
     accel        
 Min.   :0.00300  
 1st Qu.:0.04425  
 Median :0.11300  
 Mean   :0.15422  
 3rd Qu.:0.21925  
 Max.   :0.81000  
                  
> ## Comments:
> ## No difference between these in 1.2.1 and earlier
> set.seed(1)
> x <- c(round(runif(10), 2), 10000)
> summary(x)
     Min.   1st Qu.    Median      Mean   3rd Qu.      Max. 
981
    0.060     0.320     0.630   909.592     0.905 10000.000 
982 983
> summary(data.frame(x))
       x            
984 985 986 987 988
 Min.   :    0.060  
 1st Qu.:    0.320  
 Median :    0.630  
 Mean   :  909.592  
 3rd Qu.:    0.905  
989 990 991 992 993
 Max.   :10000.000  
> ## Comments:
> ## All entries show all 3 digits after the decimal point now.
> 
> ## Chong Gu 2001-Feb-16.  step on binomials
994 995 996 997 998 999 1000 1001
> detg1 <-
+ structure(list(Temp = structure(c(2L, 1L, 2L, 1L, 2L, 1L, 2L,
+     1L, 2L, 1L, 2L, 1L), .Label = c("High", "Low"), class = "factor"),
+     M.user = structure(c(1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L,
+     1L, 2L, 2L), .Label = c("N", "Y"), class = "factor"),
+     Soft = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L),
+     .Label = c("Hard", "Medium", "Soft"), class = "factor"),
+     M = c(42, 30, 52, 43,
1002 1003 1004 1005 1006 1007 1008
+     50, 23, 55, 47, 53, 27, 49, 29), X = c(68, 42, 37, 24, 66,
+     33, 47, 23, 63, 29, 57, 19)), .Names = c("Temp", "M.user",
+ "Soft", "M", "X"), class = "data.frame", row.names = c("1", "3",
+ "5", "7", "9", "11", "13", "15", "17", "19", "21", "23"))
> detg1.m0 <- glm(cbind(X,M)~1,binomial,detg1)
> detg1.m0

1009
Call:  glm(formula = cbind(X, M) ~ 1, family = binomial, data = detg1)
1010 1011 1012 1013 1014 1015 1016

Coefficients:
(Intercept)  
    0.01587  

Degrees of Freedom: 11 Total (i.e. Null);  11 Residual
Null Deviance:	    32.83 
1017
Residual Deviance: 32.83 	AIC: 92.52
1018
> step(detg1.m0,scope=list(upper=~M.user*Temp*Soft))
1019 1020
Start:  AIC=92.52
cbind(X, M) ~ 1
1021 1022 1023 1024 1025 1026 1027

         Df Deviance    AIC
+ M.user  1   12.244 73.942
+ Temp    1   28.464 90.162
<none>        32.826 92.524
+ Soft    2   32.430 96.128

1028 1029
Step:  AIC=73.94
cbind(X, M) ~ M.user
1030 1031 1032 1033 1034 1035 1036

         Df Deviance    AIC
+ Temp    1    8.444 72.142
<none>        12.244 73.942
+ Soft    2   11.967 77.665
- M.user  1   32.826 92.524

1037 1038
Step:  AIC=72.14
cbind(X, M) ~ M.user + Temp
1039 1040 1041 1042 1043 1044 1045 1046

              Df Deviance    AIC
+ M.user:Temp  1    5.656 71.354
<none>              8.444 72.142
- Temp         1   12.244 73.942
+ Soft         2    8.228 75.926
- M.user       1   28.464 90.162

1047 1048
Step:  AIC=71.35
cbind(X, M) ~ M.user + Temp + M.user:Temp
1049 1050

              Df Deviance    AIC
1051 1052 1053
<none>             5.6560 71.354
- M.user:Temp  1   8.4440 72.142
+ Soft         2   5.4952 75.193
1054

1055 1056
Call:  glm(formula = cbind(X, M) ~ M.user + Temp + M.user:Temp, family = binomial, 
    data = detg1)
1057 1058 1059 1060 1061 1062 1063

Coefficients:
    (Intercept)          M.userY          TempLow  M.userY:TempLow  
        0.26236         -0.85183          0.04411          0.44427  

Degrees of Freedom: 11 Total (i.e. Null);  8 Residual
Null Deviance:	    32.83 
1064
Residual Deviance: 5.656 	AIC: 71.35
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
> 
> ## PR 829 (empty values in all.vars)
> ## This example by Uwe Ligges <ligges@statistik.uni-dortmund.de>
> 
> temp <- matrix(1:4, 2)
> all.vars(temp ~ 3) # OK
[1] "temp"
> all.vars(temp[1, ] ~ 3) # wrong in 1.2.1
[1] "temp"
> 
> ## 2001-Feb-22 from David Scott.
> ## rank-deficient residuals in a manova model.
> gofX.df<-
+   structure(list(A = c(0.696706709347165, 0.362357754476673,
+ -0.0291995223012888,
+ 0.696706709347165, 0.696706709347165, -0.0291995223012888, 0.696706709347165,
+ -0.0291995223012888, 0.362357754476673, 0.696706709347165, -0.0291995223012888,
+ 0.362357754476673, -0.416146836547142, 0.362357754476673, 0.696706709347165,
+ 0.696706709347165, 0.362357754476673, -0.416146836547142, -0.0291995223012888,
+ -0.416146836547142, 0.696706709347165, -0.416146836547142, 0.362357754476673,
+ -0.0291995223012888), B = c(0.717356090899523, 0.932039085967226,
+ 0.999573603041505, 0.717356090899523, 0.717356090899523, 0.999573603041505,
+ 0.717356090899523, 0.999573603041505, 0.932039085967226, 0.717356090899523,
+ 0.999573603041505, 0.932039085967226, 0.909297426825682, 0.932039085967226,
+ 0.717356090899523, 0.717356090899523, 0.932039085967226, 0.909297426825682,
+ 0.999573603041505, 0.909297426825682, 0.717356090899523, 0.909297426825682,
+ 0.932039085967226, 0.999573603041505), C = c(-0.0291995223012888,
+ -0.737393715541246, -0.998294775794753, -0.0291995223012888,
+ -0.0291995223012888, -0.998294775794753, -0.0291995223012888,
+ -0.998294775794753, -0.737393715541246, -0.0291995223012888,
+ -0.998294775794753, -0.737393715541246, -0.653643620863612, -0.737393715541246,
+ -0.0291995223012888, -0.0291995223012888, -0.737393715541246,
+ -0.653643620863612, -0.998294775794753, -0.653643620863612,
+ -0.0291995223012888,
+ -0.653643620863612, -0.737393715541246, -0.998294775794753),
+     D = c(0.999573603041505, 0.67546318055115, -0.0583741434275801,
+     0.999573603041505, 0.999573603041505, -0.0583741434275801,
+     0.999573603041505, -0.0583741434275801, 0.67546318055115,
+     0.999573603041505, -0.0583741434275801, 0.67546318055115,
+     -0.756802495307928, 0.67546318055115, 0.999573603041505,
+     0.999573603041505, 0.67546318055115, -0.756802495307928,
+     -0.0583741434275801, -0.756802495307928, 0.999573603041505,
+     -0.756802495307928, 0.67546318055115, -0.0583741434275801
+     ), groups = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2,
+     2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3), class = "factor", .Label = c("1",
1110 1111
+     "2", "3"))), .Names = c("A", "B", "C", "D", "groups"), row.names = 1:24,
+             class = "data.frame")
1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
> 
> gofX.manova <- manova(formula = cbind(A, B, C, D) ~ groups, data = gofX.df)
> try(summary(gofX.manova))
Error in summary.manova(gofX.manova) : residuals have rank 3 < 4
> ## should fail with an error message `residuals have rank 3 < 4'
> 
> ## Prior to 1.3.0 dist did not handle missing values, and the
> ## internal C code was incorrectly scaling for missing values.
> z <- as.matrix(t(trees))
> z[1,1] <- z[2,2] <- z[3,3] <- z[2,4] <- NA
> dist(z, method="euclidean")
          Girth   Height
Height 352.4365         
Volume 123.5503 261.5802
> dist(z, method="maximum")
       Girth Height
Height  72.7       
Volume  56.4   63.3
> dist(z, method="manhattan")
1131 1132 1133
           Girth    Height
Height 1954.8821          
Volume  557.1448 1392.3429
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166
> dist(z, method="canberra")
          Girth   Height
Height 21.66477         
Volume 10.96200 13.63365
> 
> ## F. Tusell 2001-03-07.  printing kernels.
> kernel("daniell", m=5)
Daniell(5) 
coef[-5] = 0.09091
coef[-4] = 0.09091
coef[-3] = 0.09091
coef[-2] = 0.09091
coef[-1] = 0.09091
coef[ 0] = 0.09091
coef[ 1] = 0.09091
coef[ 2] = 0.09091
coef[ 3] = 0.09091
coef[ 4] = 0.09091
coef[ 5] = 0.09091
> kernel("modified.daniell", m=5)
mDaniell(5) 
coef[-5] = 0.05
coef[-4] = 0.10
coef[-3] = 0.10
coef[-2] = 0.10
coef[-1] = 0.10
coef[ 0] = 0.10
coef[ 1] = 0.10
coef[ 2] = 0.10
coef[ 3] = 0.10
coef[ 4] = 0.10
coef[ 5] = 0.05
> kernel("daniell", m=c(3,5,7))
1167
Daniell(3,5,7) 
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
coef[-15] = 0.0008658
coef[-14] = 0.0025974
coef[-13] = 0.0051948
coef[-12] = 0.0086580
coef[-11] = 0.0129870
coef[-10] = 0.0181818
coef[ -9] = 0.0242424
coef[ -8] = 0.0303030
coef[ -7] = 0.0363636
coef[ -6] = 0.0424242
coef[ -5] = 0.0484848
coef[ -4] = 0.0536797
coef[ -3] = 0.0580087
coef[ -2] = 0.0614719
coef[ -1] = 0.0640693
coef[  0] = 0.0649351
coef[  1] = 0.0640693
coef[  2] = 0.0614719
coef[  3] = 0.0580087
coef[  4] = 0.0536797
coef[  5] = 0.0484848
coef[  6] = 0.0424242
coef[  7] = 0.0363636
coef[  8] = 0.0303030
coef[  9] = 0.0242424
coef[ 10] = 0.0181818
coef[ 11] = 0.0129870
coef[ 12] = 0.0086580
coef[ 13] = 0.0051948
coef[ 14] = 0.0025974
coef[ 15] = 0.0008658
> ## fixed by patch from Adrian Trapletti 2001-03-08
> 
> ## Start new year (i.e. line) at Jan:
> (tt <- ts(1:10, start = c(1920,7), end = c(1921,4), freq = 12))
     Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
1920                           1   2   3   4   5   6
1921   7   8   9  10                                
> cbind(tt, tt + 1)
         tt tt + 1
Jul 1920  1      2
Aug 1920  2      3
Sep 1920  3      4
Oct 1920  4      5
Nov 1920  5      6
Dec 1920  6      7
Jan 1921  7      8
Feb 1921  8      9
Mar 1921  9     10
Apr 1921 10     11
> 
> 
> ## PR 883 (cor(x,y) when is.null(y))
> try(cov(rnorm(10), NULL))
1222 1223
Error in cov(rnorm(10), NULL) : 
  supply both 'x' and 'y' or a matrix-like 'x'
1224
> try(cor(rnorm(10), NULL))
1225 1226
Error in cor(rnorm(10), NULL) : 
  supply both 'x' and 'y' or a matrix-like 'x'
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244
> ## gave the variance and 1 respectively in 1.2.2.
> 
> 
> ## PR 960 (format() of a character matrix converts to vector)
> ## example from <John.Peters@tip.csiro.au>
> a <- matrix(c("axx","b","c","d","e","f","g","h"), nrow=2)
> format(a)
     [,1]  [,2]  [,3]  [,4] 
[1,] "axx" "c  " "e  " "g  "
[2,] "b  " "d  " "f  " "h  "
> format(a, justify="right")
     [,1]  [,2]  [,3]  [,4] 
[1,] "axx" "  c" "  e" "  g"
[2,] "  b" "  d" "  f" "  h"
> ## lost dimensions in 1.2.3
> 
> 
> ## PR 963
1245 1246 1247
> res <- svd(rbind(1:7))## $v lost dimensions in 1.2.3
> if(res$u[1,1] < 0) {res$u <- -res$u; res$v <- -res$v}
> res
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347
$d
[1] 11.83216

$u
     [,1]
[1,]    1

$v
           [,1]
[1,] 0.08451543
[2,] 0.16903085
[3,] 0.25354628
[4,] 0.33806170
[5,] 0.42257713
[6,] 0.50709255
[7,] 0.59160798

> 
> 
> ## Make sure  on.exit() keeps being evaluated in the proper env [from PD]:
> ## A more complete example:
> g1 <- function(fitted) { on.exit(remove(fitted)); return(function(foo) foo) }
> g2 <- function(fitted) { on.exit(remove(fitted));        function(foo) foo }
> f <- function(g) { fitted <- 1; h <- g(fitted); print(fitted)
+                    ls(envir=environment(h)) }
> f(g1)
[1] 1
character(0)
> f(g2)
[1] 1
character(0)
> 
> f2 <- function()
+ {
+   g.foo <- g1
+   g.bar <- g2
+   g <- function(x,...) UseMethod("g")
+   fitted <- 1; class(fitted) <- "foo"
+   h <- g(fitted); print(fitted); print(ls(envir=environment(h)))
+   fitted <- 1; class(fitted) <- "bar"
+   h <- g(fitted); print(fitted); print(ls(envir=environment(h)))
+   invisible(NULL)
+ }
> f2()
[1] 1
attr(,"class")
[1] "foo"
character(0)
[1] 1
attr(,"class")
[1] "bar"
character(0)
> ## The first case in f2() is broken in 1.3.0(-patched).
> 
> ## on.exit() consistency check from Luke:
> g <- function() as.environment(-1)
> f <- function(x) UseMethod("f")
> f.foo <- function(x) { on.exit(e <<- g()); NULL }
> f.bar <- function(x) { on.exit(e <<- g()); return(NULL) }
> f(structure(1,class = "foo"))
NULL
> ls(env = e)# only "x", i.e. *not* the GlobalEnv
[1] "x"
> f(structure(1,class = "bar"))
NULL
> stopifnot("x" == ls(env = e))# as above; wrongly was .GlobalEnv in R 1.3.x
> 
> 
> ## some tests that R supports logical variables in formulae
> ## it coerced them to numeric prior to 1.4.0
> ## they should appear like 2-level factors, following S
> 
> oldCon <- options("contrasts")
> y <- rnorm(10)
> x <- rep(c(TRUE, FALSE), 5)
> model.matrix(y ~ x)
   (Intercept) xTRUE
1            1     1
2            1     0
3            1     1
4            1     0
5            1     1
6            1     0
7            1     1
8            1     0
9            1     1
10           1     0
attr(,"assign")
[1] 0 1
attr(,"contrasts")
attr(,"contrasts")$x
[1] "contr.treatment"

> lm(y ~ x)

Call:
lm(formula = y ~ x)

Coefficients:
(Intercept)        xTRUE  
1348
   -0.05293     -0.20018  
1349 1350 1351 1352 1353 1354 1355 1356 1357

> DF <- data.frame(x, y)
> lm(y ~ x, data=DF)

Call:
lm(formula = y ~ x, data = DF)

Coefficients:
(Intercept)        xTRUE  
1358
   -0.05293     -0.20018  
1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385

> options(contrasts=c("contr.helmert", "contr.poly"))
> model.matrix(y ~ x)
   (Intercept) x1
1            1  1
2            1 -1
3            1  1
4            1 -1
5            1  1
6            1 -1
7            1  1
8            1 -1
9            1  1
10           1 -1
attr(,"assign")
[1] 0 1
attr(,"contrasts")
attr(,"contrasts")$x
[1] "contr.helmert"

> lm(y ~ x, data=DF)

Call:
lm(formula = y ~ x, data = DF)

Coefficients:
(Intercept)           x1  
1386
    -0.1530      -0.1001  
1387 1388 1389 1390 1391 1392 1393 1394 1395

> z <- 1:10
> lm(y ~ x*z)

Call:
lm(formula = y ~ x * z)

Coefficients:
(Intercept)           x1            z         x1:z  
1396
  -0.088089    -0.508170    -0.005102     0.073733  
1397 1398 1399 1400 1401 1402 1403

> lm(y ~ x*z - 1)

Call:
lm(formula = y ~ x * z - 1)

Coefficients:
1404 1405
   xFALSE      xTRUE          z       x1:z  
 0.420081  -0.596259  -0.005102   0.073733  
1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440

> options(oldCon)
> 
> ## diffinv, Adrian Trapletti, 2001-08-27
> x <- ts(1:10)
> diffinv(diff(x),xi=x[1])
Time Series:
Start = 1 
End = 10 
Frequency = 1 
 [1]  1  2  3  4  5  6  7  8  9 10
> diffinv(diff(x,lag=1,differences=2),lag=1,differences=2,xi=x[1:2])
Time Series:
Start = 1 
End = 10 
Frequency = 1 
 [1]  1  2  3  4  5  6  7  8  9 10
> ## last had wrong start and end
> 
> ## PR#1072  (Reading Inf and NaN values)
> as.numeric(as.character(NaN))
[1] NaN
> as.numeric(as.character(Inf))
[1] Inf
> ## were NA on Windows at least under 1.3.0.
> 
> ## PR#1092 (rowsum dimnames)
> rowsum(matrix(1:12, 3,4), c("Y","X","Y"))
  [,1] [,2] [,3] [,4]
X    2    5    8   11
Y    4   10   16   22
> ## rownames were 1,2 in <= 1.3.1.
> 
> ## PR#1115 (saving strings with ascii=TRUE)
> x <- y <- unlist(as.list(
1441 1442
+     parse(text=paste("\"\\", as.character(as.octmode(1:255)), "\"",sep=""))))
> save(x, ascii=TRUE, file=(fn <- tempfile()))
1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459
> load(fn)
> all(x==y)
[1] TRUE
> unlink(fn)
> ## 1.3.1 had trouble with \
> 
> 
> ## Some tests of sink() and connections()
> ## capture all the output to a file.
> zz <- file("all.Rout", open="wt")
> sink(zz)
> sink(zz, type="message")
> try(log("a"))
> ## back to the console
> sink(type="message")
> sink()
> try(log("a"))
1460
Error in log("a") : non-numeric argument to mathematical function
1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473
> 
> ## capture all the output to a file.
> zz <- file("all.Rout", open="wt")
> sink(zz)
> sink(zz, type="message")
> try(log("a"))
> 
> ## bail out
> closeAllConnections()
> (foo <- showConnections())
     description class mode text isopen can read can write
> stopifnot(nrow(foo) == 0)
> try(log("a"))
1474
Error in log("a") : non-numeric argument to mathematical function
1475 1476 1477 1478 1479 1480 1481 1482 1483 1484
> unlink("all.Rout")
> ## many of these were untested before 1.4.0.
> 
> 
> ## test mean() works on logical but not factor
> x <- c(TRUE, FALSE, TRUE, TRUE)
> mean(x)
[1] 0.75
> mean(as.factor(x))
[1] NA
1485
Warning message:
1486 1487
In mean.default(as.factor(x)) :
  argument is not numeric or logical: returning NA
1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513
> ## last had confusing error message in 1.3.1.
> 
> 
> ## Kurt Hornik 2001-Nov-13
> z <- table(x = 1:2, y = 1:2)
> z - 1
   y
x    1  2
  1  0 -1
  2 -1  0
> unclass(z - 1)
   y
x    1  2
  1  0 -1
  2 -1  0
> ## lost object bit prior to 1.4.0, so printed class attribute.
> 
> 
> ## PR#1226  (predict.mlm ignored newdata)
> ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
> trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
> group <- gl(2,10,20, labels = c("Ctl","Trt"))
> weight <- c(ctl, trt)
> data <- data.frame(weight, group)
> fit <- lm(cbind(w=weight, w2=weight^2) ~ group, data=data)
> predict(fit, newdata=data[1:2, ])
1514 1515 1516
      w       w2
1 5.032 25.62702
2 5.032 25.62702
1517 1518 1519 1520 1521
> ## was 20 rows in R <= 1.4.0
> 
> 
> ## Chong Gu 2002-Feb-8: `.' not expanded in drop1
> lab <- dimnames(HairEyeColor)
1522 1523 1524
> HairEye <- cbind(expand.grid(Hair=lab$Hair, Eye=lab$Eye, Sex=lab$Sex,
+ 			     stringsAsFactors = TRUE),
+ 		 Fr = as.vector(HairEyeColor))
1525 1526 1527 1528 1529
> HairEye.fit <- glm(Fr ~ . ^2, poisson, HairEye)
> drop1(HairEye.fit)
Single term deletions

Model:
1530
Fr ~ (Hair + Eye + Sex)^2
1531
         Df Deviance    AIC
1532 1533 1534 1535
<none>         6.761 191.64
Hair:Eye  9  156.678 323.56
Hair:Sex  3   18.327 197.21
Eye:Sex   3   11.764 190.64
1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597
> ## broken around 1.2.1 it seems.
> 
> 
> ## PR#1329  (subscripting matrix lists)
> m <- list(a1=1:3, a2=4:6, a3=pi, a4=c("a","b","c"))
> dim(m) <- c(2,2)
> m
     [,1]      [,2]       
[1,] Integer,3 3.141593   
[2,] Integer,3 Character,3
> m[,2]
[[1]]
[1] 3.141593

[[2]]
[1] "a" "b" "c"

> m[2,2]
[[1]]
[1] "a" "b" "c"

> ## 1.4.1 returned null components: the case was missing from a switch.
> 
> m <- list(a1=1:3, a2=4:6, a3=pi, a4=c("a","b","c"))
> matrix(m, 2, 2)
     [,1]      [,2]       
[1,] Integer,3 3.141593   
[2,] Integer,3 Character,3
> ## 1.4.1 gave `Unimplemented feature in copyVector'
> 
> x <- vector("list",6)
> dim(x) <- c(2,3)
> x[1,2] <- list(letters[10:11])
> x
     [,1] [,2]        [,3]
[1,] NULL Character,2 NULL
[2,] NULL NULL        NULL
> ## 1.4.1 gave `incompatible types in subset assignment'
> 
> 
> ## printing of matrix lists
> m <- list(as.integer(1), pi, 3+5i, "testit", TRUE, factor("foo"))
> dim(m) <- c(1, 6)
> m
     [,1] [,2]     [,3] [,4]     [,5] [,6]    
[1,] 1    3.141593 3+5i "testit" TRUE factor,1
> ## prior to 1.5.0 had quotes for 2D case (but not kD, k > 2),
> ## gave "numeric,1" etc, (even "numeric,1" for integers and factors)
> 
> 
> ## ensure RNG is unaltered.
> for(type in c("Wichmann-Hill", "Marsaglia-Multicarry", "Super-Duper",
+               "Mersenne-Twister", "Knuth-TAOCP", "Knuth-TAOCP-2002"))
+ {
+     set.seed(123, type)
+     print(RNGkind())
+     runif(100); print(runif(4))
+     set.seed(1000, type)
+     runif(100); print(runif(4))
+     set.seed(77, type)
+     runif(100); print(runif(4))
+ }
1598
[1] "Wichmann-Hill" "Inversion"    
1599 1600 1601
[1] 0.8308841 0.4640221 0.9460082 0.8764644
[1] 0.12909876 0.07294851 0.45594560 0.68884911
[1] 0.4062450 0.7188432 0.6241738 0.2511611
1602
[1] "Marsaglia-Multicarry" "Inversion"           
1603 1604 1605
[1] 0.3479705 0.9469351 0.2489207 0.7329251
[1] 0.5041512 0.3617873 0.1469184 0.3798119
[1] 0.14388128 0.04196294 0.36214015 0.86053575
1606
[1] "Super-Duper" "Inversion"  
1607 1608 1609
[1] 0.2722510 0.9230240 0.3971743 0.8284474
[1] 0.5706241 0.1806023 0.9633860 0.8434444
[1] 0.09356585 0.41081124 0.38635627 0.72993396
1610
[1] "Mersenne-Twister" "Inversion"       
1611 1612 1613
[1] 0.5999890 0.3328235 0.4886130 0.9544738
[1] 0.5993679 0.4516818 0.1368254 0.7261788
[1] 0.09594961 0.31235651 0.81244335 0.72330846
1614
[1] "Knuth-TAOCP" "Inversion"  
1615 1616 1617
[1] 0.9445502 0.3366297 0.6296881 0.5914161
[1] 0.9213954 0.5468138 0.8817100 0.4442237
[1] 0.8016962 0.9226080 0.1473484 0.8827707
1618
[1] "Knuth-TAOCP-2002" "Inversion"       
1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643
[1] 0.9303634 0.2812239 0.1085806 0.8053228
[1] 0.2916627 0.9085017 0.7958965 0.1980655
[1] 0.05247575 0.28290867 0.20930324 0.16794887
> RNGkind(normal.kind = "Kinderman-Ramage")
> set.seed(123)
> RNGkind()
[1] "Knuth-TAOCP-2002" "Kinderman-Ramage"
> rnorm(4)
[1] -1.9699090 -2.2429340  0.5339321  0.2097153
> RNGkind(normal.kind = "Ahrens-Dieter")
> set.seed(123)
> RNGkind()
[1] "Knuth-TAOCP-2002" "Ahrens-Dieter"   
> rnorm(4)
[1]  0.06267229  0.12421568 -1.86653499 -0.14535921
> RNGkind(normal.kind = "Box-Muller")
> set.seed(123)
> RNGkind()
[1] "Knuth-TAOCP-2002" "Box-Muller"      
> rnorm(4)
[1]  2.26160990  0.59010303  0.30176045 -0.01346139
> set.seed(123)
> runif(4)
[1] 0.04062130 0.06511825 0.99290488 0.95540467
> set.seed(123, "default")
1644
> set.seed(123, "Marsaglia-Multicarry") ## Careful, not the default anymore
1645 1646 1647 1648
> runif(4)
[1] 0.1200427 0.1991600 0.7292821 0.8115922
> ## last set.seed failed < 1.5.0.
> 
1649
> 
1650 1651 1652 1653 1654 1655 1656
> ## merging, ggrothendieck@yifan.net, 2002-03-16
> d.df <- data.frame(x = 1:3, y = c("A","D","E"), z = c(6,9,10))
> merge(d.df[1,], d.df)
  x y z
1 1 A 6
> ## 1.4.1 got confused by inconsistencies in as.character
> 
1657
> 
1658 1659 1660 1661 1662
> ## PR#1394 (levels<-.factor)
> f <- factor(c("a","b"))
> levels(f) <- list(C="C", A="a", B="b")
> f
[1] A B
1663
Levels: C A B
1664 1665 1666 1667 1668 1669
> ## was  [1] C A; Levels:  C A  in 1.4.1
> 
> 
> ## NA levels in factors
> (x <- factor(c("a", "NA", "b"), exclude=NULL))
[1] a  NA b 
1670
Levels: NA a b
1671 1672 1673 1674
> ## 1.4.1 had wrong order for levels
> is.na(x)[3] <- TRUE
> x
[1] a    NA   <NA>
1675
Levels: NA a b
1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690
> ## missing entry prints as <NA>
> 
> 
> ## printing/formatting NA strings
> (x <- c("a", "NA", NA, "b"))
[1] "a"  "NA" NA   "b" 
> print(x, quote = FALSE)
[1] a    NA   <NA> b   
> paste(x)
[1] "a"  "NA" "NA" "b" 
> format(x)
[1] "a " "NA" "NA" "b "
> format(x, justify = "right")
[1] " a" "NA" "NA" " b"
> format(x, justify = "none")
1691
[1] "a"  "NA" "NA" "b" 
1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711
> ## not ideal.
> 
> 
> ## print.ts problems  ggrothendieck@yifan.net on R-help, 2002-04-01
> x <- 1:20
> tt1 <- ts(x,start=c(1960,2), freq=12)
> tt2 <- ts(10+x,start=c(1960,2), freq=12)
> cbind(tt1, tt2)
         tt1 tt2
Feb 1960   1  11
Mar 1960   2  12
Apr 1960   3  13
May 1960   4  14
Jun 1960   5  15
Jul 1960   6  16
Aug 1960   7  17
Sep 1960   8  18
Oct 1960   9  19
Nov 1960  10  20
Dec 1960  11  21
1712
Jan 1961  12  22
1713 1714 1715 1716 1717 1718 1719 1720 1721
Feb 1961  13  23
Mar 1961  14  24
Apr 1961  15  25
May 1961  16  26
Jun 1961  17  27
Jul 1961  18  28
Aug 1961  19  29
Sep 1961  20  30
> ## 1.4.1 had `Jan 1961' as `NA 1961'
1722
> ## ...and 1.9.1 had it as `Jan 1960'!!
1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740
> 
> ## glm boundary bugs (related to PR#1331)
> x <- c(0.35, 0.64, 0.12, 1.66, 1.52, 0.23, -1.99, 0.42, 1.86, -0.02,
+        -1.64, -0.46, -0.1, 1.25, 0.37, 0.31, 1.11, 1.65, 0.33, 0.89,
+        -0.25, -0.87, -0.22, 0.71, -2.26, 0.77, -0.05, 0.32, -0.64, 0.39,
+        0.19, -1.62, 0.37, 0.02, 0.97, -2.62, 0.15, 1.55, -1.41, -2.35,
+        -0.43, 0.57, -0.66, -0.08, 0.02, 0.24, -0.33, -0.03, -1.13, 0.32,
+        1.55, 2.13, -0.1, -0.32, -0.67, 1.44, 0.04, -1.1, -0.95, -0.19,
+        -0.68, -0.43, -0.84, 0.69, -0.65, 0.71, 0.19, 0.45, 0.45, -1.19,
+        1.3, 0.14, -0.36, -0.5, -0.47, -1.31, -1.02, 1.17, 1.51, -0.33,
+        -0.01, -0.59, -0.28, -0.18, -1.07, 0.66, -0.71, 1.88, -0.14,
+        -0.19, 0.84, 0.44, 1.33, -0.2, -0.45, 1.46, 1, -1.02, 0.68, 0.84)
> y <- c(1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0,
+        0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1,
+        1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1,
+        0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1,
+        1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0)
> try(glm(y ~ x, family = poisson(identity)))
1741
Error : no valid set of coefficients has been found: please supply starting values
1742
In addition: Warning message:
1743
In log(y/mu) : NaNs produced
1744 1745 1746 1747
> ## failed because start = NULL in 1.4.1
> ## now gives useful error message
> glm(y ~ x, family = poisson(identity), start = c(1,0))

1748 1749
Call:  glm(formula = y ~ x, family = poisson(identity), start = c(1, 
    0))
1750 1751 1752

Coefficients:
(Intercept)            x  
1753
     0.5114       0.1690  
1754 1755 1756

Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
Null Deviance:	    68.01 
1757
Residual Deviance: 60.66 	AIC: 168.7
1758 1759 1760
Warning messages:
1: step size truncated: out of bounds 
2: step size truncated: out of bounds 
1761 1762 1763 1764 1765
> ## step reduction failed in 1.4.1
> set.seed(123)
> y <- rpois(100, pmax(3*x, 0))
> glm(y ~ x, family = poisson(identity), start = c(1,0))

1766 1767
Call:  glm(formula = y ~ x, family = poisson(identity), start = c(1, 
    0))
1768 1769 1770

Coefficients:
(Intercept)            x  
1771
     1.1561       0.4413  
1772 1773 1774

Degrees of Freedom: 99 Total (i.e. Null);  98 Residual
Null Deviance:	    317.2 
1775
Residual Deviance: 228.5 	AIC: 344.7
1776
There were 27 warnings (use warnings() to see them)
1777 1778
> warnings()
Warning messages:
1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803
1: step size truncated: out of bounds
2: step size truncated: out of bounds
3: step size truncated: out of bounds
4: step size truncated: out of bounds
5: step size truncated: out of bounds
6: step size truncated: out of bounds
7: step size truncated: out of bounds
8: step size truncated: out of bounds
9: step size truncated: out of bounds
10: step size truncated: out of bounds
11: step size truncated: out of bounds
12: step size truncated: out of bounds
13: step size truncated: out of bounds
14: step size truncated: out of bounds
15: step size truncated: out of bounds
16: step size truncated: out of bounds
17: step size truncated: out of bounds
18: step size truncated: out of bounds
19: step size truncated: out of bounds
20: step size truncated: out of bounds
21: step size truncated: out of bounds
22: step size truncated: out of bounds
23: step size truncated: out of bounds
24: step size truncated: out of bounds
25: step size truncated: out of bounds
1804 1805
26: glm.fit: algorithm did not converge
27: glm.fit: algorithm stopped at boundary value
1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845
> 
> 
> ## extending char arrrays
> x <- y <- LETTERS[1:2]
> x[5] <- "C"
> length(y) <- 5
> x
[1] "A" "B" NA  NA  "C"
> y
[1] "A" "B" NA  NA  NA 
> ## x was filled with "", y with NA in 1.5.0
> 
> 
> ## formula with no intercept, 2002-07-22
> oldcon <- options(contrasts = c("contr.helmert", "contr.poly"))
> U <- gl(3, 6, 18, labels=letters[1:3])
> V <- gl(3, 2, 18, labels=letters[1:3])
> A <- rep(c(0, 1), 9)
> B <- rep(c(1, 0), 9)
> set.seed(1); y <- rnorm(18)
> terms(y ~ A:U + A:V - 1)
y ~ A:U + A:V - 1
attr(,"variables")
list(y, A, U, V)
attr(,"factors")
  A:U A:V
y   0   0
A   2   2
U   2   0
V   0   1
attr(,"term.labels")
[1] "A:U" "A:V"
attr(,"order")
[1] 2 2
attr(,"intercept")
[1] 0
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
1846
> lm(y ~ A:U + A:V - 1)$coefficients  # 1.5.1 used dummies coding for V
1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864
       A:Ua        A:Ub        A:Uc        A:V1        A:V2 
 0.25303884 -0.21875499 -0.71708528 -0.61467193 -0.09030436 
> lm(y ~ (A + B) : (U + V) - 1) # 1.5.1 used dummies coding for A:V but not B:V

Call:
lm(formula = y ~ (A + B):(U + V) - 1)

Coefficients:
   A:Ua     A:Ub     A:Uc     A:V1     A:V2     B:Ua     B:Ub     B:Uc  
 0.2530  -0.2188  -0.7171  -0.6147  -0.0903   1.7428   0.0613   0.7649  
   B:V1     B:V2  
-0.4420   0.5388  

> options(oldcon)
> ## 1.5.1 miscomputed the first factor in the formula.
> 
> 
> ## quantile extremes, MM 13 Apr 2000 and PR#1852
1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947
> (qq <- sapply(0:5, function(k) {
+     x <- c(rep(-Inf,k+1), 0:k, rep(Inf, k))
+     sapply(1:9, function(typ)
+            quantile(x, pr=(2:10)/10, type=typ))
+ }, simplify="array"))
, , 1

     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
20%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
30%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
40%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
50%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf
60%     0    0 -Inf -Inf -Inf -Inf -Inf -Inf -Inf
70%     0    0 -Inf -Inf -Inf    0 -Inf -Inf -Inf
80%     0    0    0 -Inf    0    0 -Inf    0    0
90%     0    0    0 -Inf    0    0 -Inf    0    0
100%    0    0    0    0    0    0    0    0    0

, , 2

     [,1] [,2] [,3] [,4] [,5] [,6] [,7]      [,8]  [,9]
20%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf      -Inf  -Inf
30%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf      -Inf  -Inf
40%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf      -Inf  -Inf
50%     0  0.0 -Inf -Inf  0.0  0.0  0.0 0.0000000 0.000
60%     0  0.5    0  0.0  0.5  0.6  0.4 0.5333333 0.525
70%     1  1.0    1  0.5  1.0  Inf  0.8       Inf   Inf
80%     1  Inf    1  1.0  Inf  Inf  Inf       Inf   Inf
90%   Inf  Inf    1  Inf  Inf  Inf  Inf       Inf   Inf
100%  Inf  Inf  Inf  Inf  Inf  Inf  Inf       Inf   Inf

, , 3

     [,1] [,2] [,3] [,4] [,5] [,6] [,7]     [,8]  [,9]
20%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf     -Inf  -Inf
30%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf     -Inf  -Inf
40%     0  0.0 -Inf -Inf -Inf -Inf -Inf     -Inf  -Inf
50%     0  0.5    0  0.0  0.5  0.5  0.5 0.500000 0.500
60%     1  1.0    1  0.8  1.3  1.4  1.2 1.333333 1.325
70%     2  2.0    2  1.6  Inf  Inf  1.9      Inf   Inf
80%   Inf  Inf    2  Inf  Inf  Inf  Inf      Inf   Inf
90%   Inf  Inf  Inf  Inf  Inf  Inf  Inf      Inf   Inf
100%  Inf  Inf  Inf  Inf  Inf  Inf  Inf      Inf   Inf

, , 4

     [,1] [,2] [,3] [,4] [,5] [,6] [,7]     [,8]  [,9]
20%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf     -Inf  -Inf
30%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf     -Inf  -Inf
40%     0    0 -Inf -Inf -Inf -Inf    0     -Inf  -Inf
50%     1    1    1  0.5  1.0  1.0    1 1.000000 1.000
60%     2    2    2  1.6  2.1  2.2    2 2.133333 2.125
70%     3    3    3  2.7  Inf  Inf    3      Inf   Inf
80%   Inf  Inf  Inf  Inf  Inf  Inf  Inf      Inf   Inf
90%   Inf  Inf  Inf  Inf  Inf  Inf  Inf      Inf   Inf
100%  Inf  Inf  Inf  Inf  Inf  Inf  Inf      Inf   Inf

, , 5

     [,1] [,2] [,3] [,4] [,5] [,6] [,7]       [,8]  [,9]
20%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf       -Inf  -Inf
30%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf       -Inf  -Inf
40%     0  0.0    0 -Inf  0.1  0.0  0.2 0.06666667 0.075
50%     1  1.5    1  1.0  1.5  1.5  1.5 1.50000000 1.500
60%     3  3.0    2  2.4  2.9  3.0  2.8 2.93333333 2.925
70%     4  4.0    4  3.8  Inf  Inf  Inf        Inf   Inf
80%   Inf  Inf  Inf  Inf  Inf  Inf  Inf        Inf   Inf
90%   Inf  Inf  Inf  Inf  Inf  Inf  Inf        Inf   Inf
100%  Inf  Inf  Inf  Inf  Inf  Inf  Inf        Inf   Inf

, , 6

     [,1] [,2] [,3] [,4] [,5] [,6] [,7]      [,8]  [,9]
20%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf      -Inf  -Inf
30%  -Inf -Inf -Inf -Inf -Inf -Inf -Inf      -Inf  -Inf
40%     0    0    0 -Inf  0.3  0.2  0.4 0.2666667 0.275
50%     2    2    1  1.5  2.0  2.0  2.0 2.0000000 2.000
60%     4    4    3  3.2  3.7  3.8  3.6 3.7333333 3.725
70%     5    5    5  4.9  Inf  Inf  Inf       Inf   Inf
80%   Inf  Inf  Inf  Inf  Inf  Inf  Inf       Inf   Inf
90%   Inf  Inf  Inf  Inf  Inf  Inf  Inf       Inf   Inf
100%  Inf  Inf  Inf  Inf  Inf  Inf  Inf       Inf   Inf

1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980
> x <- c(-Inf, -Inf, Inf, Inf)
> median(x)
[1] NaN
> quantile(x)
  0%  25%  50%  75% 100% 
-Inf -Inf  NaN  Inf  Inf 
> ## 1.5.1 had -Inf not NaN in several places
> 
> 
> ## NAs in matrix dimnames
> z <- matrix(1:9, 3, 3)
> dimnames(z) <- list(c("x", "y", NA), c(1, NA, 3))
> z
     1 <NA> 3
x    1    4 7
y    2    5 8
<NA> 3    6 9
> ## NAs in dimnames misaligned when printing in 1.5.1
> 
> 
> ## weighted aov (PR#1930)
> r <- c(10,23,23,26,17,5,53,55,32,46,10,8,10,8,23,0,3,22,15,32,3)
> n <- c(39,62,81,51,39,6,74,72,51,79,13,16,30,28,45,4,12,41,30,51,7)
> trt <- factor(rep(1:4,c(5,6,5,5)))
> Y <- r/n
> z <- aov(Y ~ trt, weights=n)
> ## 1.5.1 gave unweighted RSS
> 
> 
> ## rbind (PR#2266)
> test <- as.data.frame(matrix(1:25, 5, 5))
> test1 <- matrix(-(1:10), 2, 5)
> rbind(test, test1)
1981 1982 1983 1984 1985 1986 1987 1988
  V1 V2 V3 V4  V5
1  1  6 11 16  21
2  2  7 12 17  22
3  3  8 13 18  23
4  4  9 14 19  24
5  5 10 15 20  25
6 -1 -3 -5 -7  -9
7 -2 -4 -6 -8 -10
1989
> rbind(test1, test)
1990 1991 1992 1993 1994 1995 1996 1997
  V1 V2 V3 V4  V5
1 -1 -3 -5 -7  -9
2 -2 -4 -6 -8 -10
3  1  6 11 16  21
4  2  7 12 17  22
5  3  8 13 18  23
6  4  9 14 19  24
7  5 10 15 20  25
1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206
> ## 1.6.1 treated matrix as a vector.
> 
> 
> ## escapes in non-quoted printing
> x <- "\\abc\\"
> names(x) <- 1
> x
        1 
"\\abc\\" 
> print(x, quote=FALSE)
      1 
\\abc\\ 
> ## 1.6.2 had label misaligned
> 
> 
> ## summary on data frames containing data frames (PR#1891)
> x <- data.frame(1:10)
> x$z <- data.frame(x=1:10,yyy=11:20)
> summary(x)
     X1.10             z.x             z.yyy     
 Min.   : 1.00   Min.   : 1.00    Min.   :11.00  
 1st Qu.: 3.25   1st Qu.: 3.25    1st Qu.:13.25  
 Median : 5.50   Median : 5.50    Median :15.50  
 Mean   : 5.50   Mean   : 5.50    Mean   :15.50  
 3rd Qu.: 7.75   3rd Qu.: 7.75    3rd Qu.:17.75  
 Max.   :10.00   Max.   :10.00    Max.   :20.00  
> ## 1.6.2 had NULL labels on output with z columns stacked.
> 
> 
> ## re-orderings in terms.formula (PR#2206)
> form <- formula(y ~ a + b:c + d + e + e:d)
> (tt <- terms(form))
y ~ a + b:c + d + e + e:d
attr(,"variables")
list(y, a, b, c, d, e)
attr(,"factors")
  a d e b:c d:e
y 0 0 0   0   0
a 1 0 0   0   0
b 0 0 0   2   0
c 0 0 0   2   0
d 0 1 0   0   1
e 0 0 1   0   1
attr(,"term.labels")
[1] "a"   "d"   "e"   "b:c" "d:e"
attr(,"order")
[1] 1 1 1 2 2
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
> (tt2 <- terms(formula(tt)))
y ~ a + b:c + d + e + e:d
attr(,"variables")
list(y, a, b, c, d, e)
attr(,"factors")
  a d e b:c d:e
y 0 0 0   0   0
a 1 0 0   0   0
b 0 0 0   2   0
c 0 0 0   2   0
d 0 1 0   0   1
e 0 0 1   0   1
attr(,"term.labels")
[1] "a"   "d"   "e"   "b:c" "d:e"
attr(,"order")
[1] 1 1 1 2 2
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
> stopifnot(identical(tt, tt2))
> terms(delete.response(tt))
~a + b:c + d + e + e:d
attr(,"variables")
list(a, b, c, d, e)
attr(,"factors")
  a d e b:c d:e
a 1 0 0   0   0
b 0 0 0   2   0
c 0 0 0   2   0
d 0 1 0   0   1
e 0 0 1   0   1
attr(,"term.labels")
[1] "a"   "d"   "e"   "b:c" "d:e"
attr(,"order")
[1] 1 1 1 2 2
attr(,"intercept")
[1] 1
attr(,"response")
[1] 0
attr(,".Environment")
<environment: R_GlobalEnv>
> ## both tt and tt2 re-ordered the formula < 1.7.0
> ## now try with a dot
> terms(breaks ~ ., data = warpbreaks)
breaks ~ wool + tension
attr(,"variables")
list(breaks, wool, tension)
attr(,"factors")
        wool tension
breaks     0       0
wool       1       0
tension    0       1
attr(,"term.labels")
[1] "wool"    "tension"
attr(,"order")
[1] 1 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
> terms(breaks ~ . - tension, data = warpbreaks)
breaks ~ (wool + tension) - tension
attr(,"variables")
list(breaks, wool, tension)
attr(,"factors")
        wool
breaks     0
wool       1
tension    0
attr(,"term.labels")
[1] "wool"
attr(,"order")
[1] 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
> terms(breaks ~ . - tension, data = warpbreaks, simplify = TRUE)
breaks ~ wool
attr(,"variables")
list(breaks, wool, tension)
attr(,"factors")
        wool
breaks     0
wool       1
tension    0
attr(,"term.labels")
[1] "wool"
attr(,"order")
[1] 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
> terms(breaks ~ . ^2, data = warpbreaks)
breaks ~ (wool + tension)^2
attr(,"variables")
list(breaks, wool, tension)
attr(,"factors")
        wool tension wool:tension
breaks     0       0            0
wool       1       0            1
tension    0       1            1
attr(,"term.labels")
[1] "wool"         "tension"      "wool:tension"
attr(,"order")
[1] 1 1 2
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
> terms(breaks ~ . ^2, data = warpbreaks, simplify = TRUE)
breaks ~ wool + tension + wool:tension
attr(,"variables")
list(breaks, wool, tension)
attr(,"factors")
        wool tension wool:tension
breaks     0       0            0
wool       1       0            1
tension    0       1            1
attr(,"term.labels")
[1] "wool"         "tension"      "wool:tension"
attr(,"order")
[1] 1 1 2
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>
> ## 1.6.2 expanded these formulae out as in simplify = TRUE
> 
> 
> ## printing attributes (PR#2506)
> (x <- structure(1:4, other=as.factor(LETTERS[1:3])))
[1] 1 2 3 4
attr(,"other")
[1] A B C
Levels: A B C
> ## < 1.7.0 printed the codes of the factor attribute
> 
> 
> ## add logical matrix replacement indexing for data frames
> TEMP <- data.frame(VAR1=c(1,2,3,4,5), VAR2=c(5,4,3,2,1), VAR3=c(1,1,1,1,NA))
> TEMP[,c(1,3)][TEMP[,c(1,3)]==1 & !is.na(TEMP[,c(1,3)])] < -10
2207
[1] FALSE FALSE FALSE FALSE FALSE
2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228
> TEMP
  VAR1 VAR2 VAR3
1    1    5    1
2    2    4    1
3    3    3    1
4    4    2    1
5    5    1   NA
> ##
> 
> ## moved from reg-plot.R as exact output depends on rounding error
> ## PR 390 (axis for small ranges)
> 
> relrange <- function(x) {
+     ## The relative range in EPS units
+     r <- range(x)
+     diff(r)/max(abs(r))/.Machine$double.eps
+ }
> 
> x <- c(0.12345678912345678,
+        0.12345678912345679,
+        0.12345678912345676)
2229
> # relrange(x) ## 1.0125, but depends on strtod
2230 2231 2232 2233 2234 2235
> plot(x) # `extra horizontal' ;  +- ok on Solaris; label off on Linux
> 
> y <- c(0.9999563255363383973418,
+        0.9999563255363389524533,
+        0.9999563255363382863194)
> ## The relative range number:
2236
> # relrange(y) ## 3.000131, but depends on strtod
2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290
> plot(y)# once gave infinite loop on Solaris [TL];  y-axis too long
> 
> ## Comments: The whole issue was finally deferred to main/graphics.c l.1944
> ##    error("relative range of values is too small to compute accurately");
> ## which is not okay.
> 
> set.seed(101)
> par(mfrow = c(3,3))
> for(j.fac in 1e-12* c(10, 1, .7, .3, .2, .1, .05, .03, .01)) {
+ ##           ====
+     #set.seed(101) # or don't
+     x <- pi + jitter(numeric(101), f = j.fac)
+     rrtxt <- paste("rel.range =", formatC(relrange(x), dig = 4),"* EPS")
+     cat("j.f = ", format(j.fac)," ;  ", rrtxt,"\n",sep="")
+     plot(x, type = "l", main = rrtxt)
+     cat("par(\"usr\")[3:4]:", formatC(par("usr")[3:4], wid = 10),"\n",
+         "par(\"yaxp\") :   ", formatC(par("yaxp"), wid = 10),"\n\n", sep="")
+ }
j.f = 1e-11 ;  rel.range = 553.9 * EPS
par("usr")[3:4]:     3.142     3.142
par("yaxp") :        3.142     3.142         3

j.f = 1e-12 ;  rel.range = 56.02 * EPS
par("usr")[3:4]:     3.142     3.142
par("yaxp") :        3.142     3.142         1

j.f = 7e-13 ;  rel.range = 39.47 * EPS
par("usr")[3:4]:     3.142     3.142
par("yaxp") :        3.142     3.142         1

j.f = 3e-13 ;  rel.range = 16.55 * EPS
par("usr")[3:4]:     3.142     3.142
par("yaxp") :        3.142     3.142         1

j.f = 2e-13 ;  rel.range = 11.46 * EPS
par("usr")[3:4]:     3.108     3.176
par("yaxp") :         3.11      3.17         6

j.f = 1e-13 ;  rel.range = 5.093 * EPS
par("usr")[3:4]:     3.108     3.176
par("yaxp") :         3.11      3.17         6

j.f = 5e-14 ;  rel.range = 2.546 * EPS
par("usr")[3:4]:     3.108     3.176
par("yaxp") :         3.11      3.17         6

j.f = 3e-14 ;  rel.range = 1.273 * EPS
par("usr")[3:4]:     3.108     3.176
par("yaxp") :         3.11      3.17         6

j.f = 1e-14 ;  rel.range =     0 * EPS
par("usr")[3:4]:     1.784     4.499
par("yaxp") :            2         4         4

2291
Warning messages:
2292 2293 2294 2295 2296
1: In plot.window(...) :
  relative range of values =  43 * EPS, is small (axis 2)
2: In plot.window(...) :
  relative range of values =  36 * EPS, is small (axis 2)
3: In plot.window(...) :
2297
  relative range of values =   0 * EPS, is small (axis 2)
2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313
> par(mfrow = c(1,1))
> ## The warnings from inside GScale() will differ in their  relrange() ...
> ## >> do sloppy testing
> ## 2003-02-03 hopefully no more.  BDR
> ## end of PR 390
> 
> 
> ## scoping rules calling step inside a function
> "cement" <-
+     structure(list(x1 = c(7, 1, 11, 11, 7, 11, 3, 1, 2, 21, 1, 11, 10),
+                    x2 = c(26, 29, 56, 31, 52, 55, 71, 31, 54, 47, 40, 66, 68),
+                    x3 = c(6, 15, 8, 8, 6, 9, 17, 22, 18, 4, 23, 9, 8),
+                    x4 = c(60, 52, 20, 47, 33, 22, 6, 44, 22, 26, 34, 12, 12),
+                    y = c(78.5, 74.3, 104.3, 87.6, 95.9, 109.2, 102.7, 72.5,
+                    93.1, 115.9, 83.8, 113.3, 109.4)),
+               .Names = c("x1", "x2", "x3", "x4", "y"), class = "data.frame",
2314
+               row.names = 1:13)
2315 2316 2317 2318 2319 2320 2321
> teststep <- function(formula, data)
+ {
+     d2 <- data
+     fit <- lm(formula, data=d2)
+     step(fit)
+ }
> teststep(formula(y ~ .), cement)
2322 2323
Start:  AIC=26.94
y ~ x1 + x2 + x3 + x4
2324 2325

       Df Sum of Sq    RSS    AIC
2326 2327 2328
- x3    1    0.1091 47.973 24.974
- x4    1    0.2470 48.111 25.011
- x2    1    2.9725 50.836 25.728
2329
<none>              47.864 26.944
2330
- x1    1   25.9509 73.815 30.576
2331

2332 2333
Step:  AIC=24.97
y ~ x1 + x2 + x4
2334 2335

       Df Sum of Sq    RSS    AIC
2336 2337 2338 2339
<none>               47.97 24.974
- x4    1      9.93  57.90 25.420
- x2    1     26.79  74.76 28.742
- x1    1    820.91 868.88 60.629
2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350

Call:
lm(formula = y ~ x1 + x2 + x4, data = d2)

Coefficients:
(Intercept)           x1           x2           x4  
    71.6483       1.4519       0.4161      -0.2365  

> ## failed in 1.6.2
> 
> str(array(1))# not a scalar
2351
 num [1(1d)] 1
2352
> 
2353
> 
2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434
> ## na.print="" shouldn't apply to (dim)names!
> (tf <- table(ff <- factor(c(1:2,NA,2), exclude=NULL)))

   1    2 <NA> 
   1    2    1 
> identical(levels(ff), dimnames(tf)[[1]])
[1] TRUE
> str(levels(ff))
 chr [1:3] "1" "2" NA
> ## not quite ok previous to 1.7.0
> 
> 
> ## PR#3058  printing with na.print and right=TRUE
> a <- matrix( c(NA, "a", "b", "10",
+                NA, NA,  "d", "12",
+                NA, NA,  NA,  "14"),
+             byrow=T, ncol=4 )
> print(a, right=TRUE, na.print=" ")
     [,1] [,2] [,3] [,4]
[1,]       "a"  "b" "10"
[2,]            "d" "12"
[3,]                "14"
> print(a, right=TRUE, na.print="----")
     [,1] [,2] [,3] [,4]
[1,] ----  "a"  "b" "10"
[2,] ---- ----  "d" "12"
[3,] ---- ---- ---- "14"
> ## misaligned in 1.7.0
> 
> 
> ## assigning factors to dimnames
> A <- matrix(1:4, 2)
> aa <- factor(letters[1:2])
> dimnames(A) <- list(aa, NULL)
> A
  [,1] [,2]
a    1    3
b    2    4
> dimnames(A)
[[1]]
[1] "a" "b"

[[2]]
NULL

> ## 1.7.0 gave internal codes as display and dimnames()
> ## 1.7.1beta gave NAs via dimnames()
> ## 1.8.0 converts factors to character
> 
> 
> ## wishlist PR#2776: aliased coefs in lm/glm
> set.seed(123)
> x2 <- x1 <- 1:10
> x3 <- 0.1*(1:10)^2
> y <- x1 + rnorm(10)
> (fit <- lm(y ~ x1 + x2 + x3))

Call:
lm(formula = y ~ x1 + x2 + x3)

Coefficients:
(Intercept)           x1           x2           x3  
     1.4719       0.5867           NA       0.2587  

> summary(fit, cor = TRUE)

Call:
lm(formula = y ~ x1 + x2 + x3)

Residuals:
    Min      1Q  Median      3Q     Max 
-1.0572 -0.4836  0.0799  0.4424  1.2699 

Coefficients: (1 not defined because of singularities)
            Estimate Std. Error t value Pr(>|t|)
(Intercept)   1.4719     0.9484   1.552    0.165
x1            0.5867     0.3961   1.481    0.182
x2                NA         NA      NA       NA
x3            0.2587     0.3509   0.737    0.485

Residual standard error: 0.8063 on 7 degrees of freedom
2435 2436
Multiple R-squared:  0.9326,	Adjusted R-squared:  0.9134 
F-statistic: 48.43 on 2 and 7 DF,  p-value: 7.946e-05
2437 2438 2439 2440 2441 2442 2443 2444

Correlation of Coefficients:
   (Intercept) x1   
x1 -0.91            
x3  0.81       -0.97

> (fit <- glm(y ~ x1 + x2 + x3))

2445
Call:  glm(formula = y ~ x1 + x2 + x3)
2446 2447 2448 2449 2450 2451 2452

Coefficients:
(Intercept)           x1           x2           x3  
     1.4719       0.5867           NA       0.2587  

Degrees of Freedom: 9 Total (i.e. Null);  7 Residual
Null Deviance:	    67.53 
2453
Residual Deviance: 4.551 	AIC: 28.51
2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520
> summary(fit, cor = TRUE)

Call:
glm(formula = y ~ x1 + x2 + x3)

Deviance Residuals: 
    Min       1Q   Median       3Q      Max  
-1.0572  -0.4836   0.0799   0.4424   1.2699  

Coefficients: (1 not defined because of singularities)
            Estimate Std. Error t value Pr(>|t|)
(Intercept)   1.4719     0.9484   1.552    0.165
x1            0.5867     0.3961   1.481    0.182
x2                NA         NA      NA       NA
x3            0.2587     0.3509   0.737    0.485

(Dispersion parameter for gaussian family taken to be 0.6501753)

    Null deviance: 67.5316  on 9  degrees of freedom
Residual deviance:  4.5512  on 7  degrees of freedom
AIC: 28.507

Number of Fisher Scoring iterations: 2

Correlation of Coefficients:
   (Intercept) x1   
x1 -0.91            
x3  0.81       -0.97

> ## omitted silently in summary.glm < 1.8.0
> 
> 
> ## list-like indexing of data frames with drop specified
> women["height"]
   height
1      58
2      59
3      60
4      61
5      62
6      63
7      64
8      65
9      66
10     67
11     68
12     69
13     70
14     71
15     72
> women["height", drop = FALSE]  # same with a warning
   height
1      58
2      59
3      60
4      61
5      62
6      63
7      64
8      65
9      66
10     67
11     68
12     69
13     70
14     71
15     72
2521
Warning message:
2522
In `[.data.frame`(women, "height", drop = FALSE) :
2523
  'drop' argument will be ignored
2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540
> women["height", drop = TRUE]   # ditto
   height
1      58
2      59
3      60
4      61
5      62
6      63
7      64
8      65
9      66
10     67
11     68
12     69
13     70
14     71
15     72
2541
Warning message:
2542
In `[.data.frame`(women, "height", drop = TRUE) :
2543
  'drop' argument will be ignored
2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637
> women[,"height", drop = FALSE] # no warning
   height
1      58
2      59
3      60
4      61
5      62
6      63
7      64
8      65
9      66
10     67
11     68
12     69
13     70
14     71
15     72
> women[,"height", drop = TRUE]  # a vector
 [1] 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
> ## second and third were interpreted as women["height", , drop] in 1.7.x
> 
> 
> ## make.names
> make.names("")
[1] "X"
> make.names(".aa")
[1] ".aa"
> ## was "X.aa" in 1.7.1
> make.names(".2")
[1] "X.2"
> make.names(".2a") # not valid in R
[1] "X.2a"
> make.names(as.character(NA))
[1] "NA."
> ##
> 
> 
> ## strange names in data frames
> as.data.frame(list(row.names=17))  # 0 rows in 1.7.1
  row.names
1        17
> aa <- data.frame(aa=1:3)
> aa[["row.names"]] <- 4:6
> aa # fine in 1.7.1
  aa row.names
1  1         4
2  2         5
3  3         6
> A <- matrix(4:9, 3, 2)
> colnames(A) <- letters[1:2]
> aa[["row.names"]] <- A
> aa
  aa row.names.a row.names.b
1  1           4           7
2  2           5           8
3  3           6           9
> ## wrong printed names in 1.7.1
> 
> ## assigning to NULL
> a <- NULL
> a[["a"]] <- 1
> a
a 
1 
> a <- NULL
> a[["a"]] <- "something"
> a
          a 
"something" 
> a <- NULL
> a[["a"]] <- 1:3
> a
$a
[1] 1 2 3

> ## Last was an error in 1.7.1
> 
> 
> ## examples of 0-rank models, some empty, some rank-deficient
> y <- rnorm(10)
> x <- rep(0, 10)
> (fit <- lm(y ~ 0))

Call:
lm(formula = y ~ 0)

No coefficients

> summary(fit)

Call:
lm(formula = y ~ 0)

Residuals:
2638 2639
     Min       1Q   Median       3Q      Max 
-1.36919 -0.21073  0.00840  0.08437  0.55292 
2640 2641 2642 2643 2644 2645 2646 2647 2648

No Coefficients

Residual standard error: 0.5235 on 10 degrees of freedom

> anova(fit)
Analysis of Variance Table

Response: y
2649 2650
          Df Sum Sq Mean Sq F value Pr(>F)
Residuals 10 2.7404 0.27404               
2651 2652 2653 2654 2655
> predict(fit)
 1  2  3  4  5  6  7  8  9 10 
 0  0  0  0  0  0  0  0  0  0 
> predict(fit, data.frame(x=x), se=TRUE)
$fit
2656 2657
 1  2  3  4  5  6  7  8  9 10 
 0  0  0  0  0  0  0  0  0  0 
2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669

$se.fit
 [1] 0 0 0 0 0 0 0 0 0 0

$df
[1] 10

$residual.scale
[1] 0.5234843

> predict(fit, type="terms", se=TRUE)
$fit
2670
     
2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684
 [1,]
 [2,]
 [3,]
 [4,]
 [5,]
 [6,]
 [7,]
 [8,]
 [9,]
[10,]
attr(,"constant")
[1] 0

$se.fit
2685
     
2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705
 [1,]
 [2,]
 [3,]
 [4,]
 [5,]
 [6,]
 [7,]
 [8,]
 [9,]
[10,]

$df
[1] 10

$residual.scale
[1] 0.5234843

> variable.names(fit) #should be empty
character(0)
> model.matrix(fit)
2706
  
2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717
1 
2 
3 
4 
5 
6 
7 
8 
9 
10
attr(,"assign")
2718
integer(0)
2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734
> 
> (fit <- lm(y ~ x + 0))

Call:
lm(formula = y ~ x + 0)

Coefficients:
 x  
NA  

> summary(fit)

Call:
lm(formula = y ~ x + 0)

Residuals:
2735 2736
     Min       1Q   Median       3Q      Max 
-1.36919 -0.21073  0.00840  0.08437  0.55292 
2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747

Coefficients: (1 not defined because of singularities)
  Estimate Std. Error t value Pr(>|t|)
x       NA         NA      NA       NA

Residual standard error: 0.5235 on 10 degrees of freedom

> anova(fit)
Analysis of Variance Table

Response: y
2748 2749
          Df Sum Sq Mean Sq F value Pr(>F)
Residuals 10 2.7404 0.27404               
2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766
> predict(fit)
 1  2  3  4  5  6  7  8  9 10 
 0  0  0  0  0  0  0  0  0  0 
> predict(fit, data.frame(x=x), se=TRUE)
$fit
 1  2  3  4  5  6  7  8  9 10 
 0  0  0  0  0  0  0  0  0  0 

$se.fit
 [1] 0 0 0 0 0 0 0 0 0 0

$df
[1] 10

$residual.scale
[1] 0.5234843

2767
Warning message:
2768 2769
In predict.lm(fit, data.frame(x = x), se = TRUE) :
  prediction from a rank-deficient fit may be misleading
2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823
> predict(fit, type="terms", se=TRUE)
$fit
   x
1  0
2  0
3  0
4  0
5  0
6  0
7  0
8  0
9  0
10 0
attr(,"constant")
[1] 0

$se.fit
   x
1  0
2  0
3  0
4  0
5  0
6  0
7  0
8  0
9  0
10 0

$df
[1] 10

$residual.scale
[1] 0.5234843

> variable.names(fit) #should be empty
character(0)
> model.matrix(fit)
   x
1  0
2  0
3  0
4  0
5  0
6  0
7  0
8  0
9  0
10 0
attr(,"assign")
[1] 1
> 
> (fit <- glm(y ~ 0))

2824
Call:  glm(formula = y ~ 0)
2825 2826 2827 2828 2829 2830

No coefficients


Degrees of Freedom: 10 Total (i.e. Null);  10 Residual
Null Deviance:	    2.74 
2831
Residual Deviance: 2.74 	AIC: 17.43
2832 2833 2834 2835 2836 2837
> summary(fit)

Call:
glm(formula = y ~ 0)

Deviance Residuals: 
2838 2839
     Min        1Q    Median        3Q       Max  
-1.36919  -0.21073   0.00840   0.08437   0.55292  
2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867

No Coefficients

(Dispersion parameter for gaussian family taken to be 0.2740358)

    Null deviance: 2.7404  on 10  degrees of freedom
Residual deviance: 2.7404  on 10  degrees of freedom
AIC: 17.434

Number of Fisher Scoring iterations: 0

> anova(fit)
Analysis of Deviance Table

Model: gaussian, link: identity

Response: y

Terms added sequentially (first to last)


     Df Deviance Resid. Df Resid. Dev
NULL                    10     2.7404
> predict(fit)
 1  2  3  4  5  6  7  8  9 10 
 0  0  0  0  0  0  0  0  0  0 
> predict(fit, data.frame(x=x), se=TRUE)
$fit
2868 2869
 1  2  3  4  5  6  7  8  9 10 
 0  0  0  0  0  0  0  0  0  0 
2870 2871 2872 2873 2874 2875 2876 2877 2878

$se.fit
 [1] 0 0 0 0 0 0 0 0 0 0

$residual.scale
[1] 0.5234843

> predict(fit, type="terms", se=TRUE)
$fit
2879
     
2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893
 [1,]
 [2,]
 [3,]
 [4,]
 [5,]
 [6,]
 [7,]
 [8,]
 [9,]
[10,]
attr(,"constant")
[1] 0

$se.fit
2894
     
2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911
 [1,]
 [2,]
 [3,]
 [4,]
 [5,]
 [6,]
 [7,]
 [8,]
 [9,]
[10,]

$residual.scale
[1] 0.5234843

> 
> (fit <- glm(y ~ x + 0))

2912
Call:  glm(formula = y ~ x + 0)
2913 2914 2915 2916 2917 2918 2919

Coefficients:
 x  
NA  

Degrees of Freedom: 10 Total (i.e. Null);  10 Residual
Null Deviance:	    2.74 
2920
Residual Deviance: 2.74 	AIC: 17.43
2921 2922 2923 2924 2925 2926
> summary(fit)

Call:
glm(formula = y ~ x + 0)

Deviance Residuals: 
2927 2928
     Min        1Q    Median        3Q       Max  
-1.36919  -0.21073   0.00840   0.08437   0.55292  
2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953

Coefficients: (1 not defined because of singularities)
  Estimate Std. Error t value Pr(>|t|)
x       NA         NA      NA       NA

(Dispersion parameter for gaussian family taken to be 0.2740358)

    Null deviance: 2.7404  on 10  degrees of freedom
Residual deviance: 2.7404  on 10  degrees of freedom
AIC: 17.434

Number of Fisher Scoring iterations: 2

> anova(fit)
Analysis of Deviance Table

Model: gaussian, link: identity

Response: y

Terms added sequentially (first to last)


     Df Deviance Resid. Df Resid. Dev
NULL                    10     2.7404
2954
x     0        0        10     2.7404
2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968
> predict(fit)
 1  2  3  4  5  6  7  8  9 10 
 0  0  0  0  0  0  0  0  0  0 
> predict(fit, data.frame(x=x), se=TRUE)
$fit
 1  2  3  4  5  6  7  8  9 10 
 0  0  0  0  0  0  0  0  0  0 

$se.fit
 [1] 0 0 0 0 0 0 0 0 0 0

$residual.scale
[1] 0.5234843

2969
Warning message:
2970 2971
In predict.lm(object, newdata, se.fit, scale = residual.scale, type = ifelse(type ==  :
  prediction from a rank-deficient fit may be misleading
2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070
> predict(fit, type="terms", se=TRUE)
$fit
   x
1  0
2  0
3  0
4  0
5  0
6  0
7  0
8  0
9  0
10 0
attr(,"constant")
[1] 0

$se.fit
   x
1  0
2  0
3  0
4  0
5  0
6  0
7  0
8  0
9  0
10 0

$residual.scale
[1] 0.5234843

> ## Lots of problems in 1.7.x
> 
> 
> ## lm.influence on deficient lm models
> dat <- data.frame(y=rnorm(10), x1=1:10, x2=1:10, x3 = 0, wt=c(0,rep(1, 9)),
+                   row.names=letters[1:10])
> dat[3, 1] <- dat[4, 2] <- NA
> lm.influence(lm(y ~ x1 + x2, data=dat, weights=wt, na.action=na.omit))
$hat
        b         e         f         g         h         i         j 
0.6546053 0.2105263 0.1546053 0.1447368 0.1809211 0.2631579 0.3914474 

$coefficients
  (Intercept)           x1
b  1.39138784 -0.173267165
e -0.70930972  0.068642877
f  0.12039809 -0.007818058
g  0.01971595  0.001314397
h  0.03272637 -0.017325726
i -0.36929526  0.092323814
j  0.33861311 -0.070163076

$sigma
        b         e         f         g         h         i         j 
0.9641441 0.7434598 1.0496727 1.0681908 1.0389586 0.7633748 1.0093187 

$wt.res
         b          e          f          g          h          i          j 
 0.5513046 -1.3728575  0.4018482  0.1708716 -0.4793451  1.2925334 -0.5643552 

> lm.influence(lm(y ~ x1 + x2, data=dat, weights=wt, na.action=na.exclude))
$hat
        b         e         c         d         f         g         h         i 
0.6546053 0.2105263 0.0000000 0.0000000 0.1546053 0.1447368 0.1809211 0.2631579 
        j 
0.3914474 

$coefficients
  (Intercept)           x1
b  1.39138784 -0.173267165
e -0.70930972  0.068642877
c  0.00000000  0.000000000
d  0.00000000  0.000000000
f  0.12039809 -0.007818058
g  0.01971595  0.001314397
h  0.03272637 -0.017325726
i -0.36929526  0.092323814
j  0.33861311 -0.070163076

$sigma
        b         e         c         d         f         g         h         i 
0.9641441 0.7434598 0.9589854 0.9589854 1.0496727 1.0681908 1.0389586 0.7633748 
        j 
1.0093187 

$wt.res
         b          e          c          d          f          g          h 
 0.5513046 -1.3728575         NA         NA  0.4018482  0.1708716 -0.4793451 
         i          j 
 1.2925334 -0.5643552 

> lm.influence(lm(y ~ 0, data=dat, weights=wt, na.action=na.omit))
$hat
b d e f g h i j 
0 0 0 0 0 0 0 0 

$coefficients
3071
 
3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082
b
d
e
f
g
h
i
j

$sigma
        b         d         e         f         g         h         i         j 
3083
0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 
3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096

$wt.res
         b          d          e          f          g          h          i 
 0.3604547  0.1146812 -1.1426753  0.7723744  0.6817419  0.1718693  2.0840918 
         j 
 0.3675473 

> lm.influence(lm(y ~ 0, data=dat, weights=wt, na.action=na.exclude))
$hat
b d c e f g h i j 
0 0 0 0 0 0 0 0 0 

$coefficients
3097
 
3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109
b
d
c
e
f
g
h
i
j

$sigma
        b         d         c         e         f         g         h         i 
3110
0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 0.9366289 
3111
        j 
3112
0.9366289 
3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125

$wt.res
         b          d          c          e          f          g          h 
 0.3604547  0.1146812         NA -1.1426753  0.7723744  0.6817419  0.1718693 
         i          j 
 2.0840918  0.3675473 

> lm.influence(lm(y ~ 0 + x3, data=dat, weights=wt, na.action=na.omit))
$hat
b d e f g h i j 
0 0 0 0 0 0 0 0