Running 'atest.R' [1s]
  Comparing 'atest.Rout' to 'atest.Rout.save' ... OK
  Running 'double.R' [169s]
  Running 'dtest.R' [0s]
  Comparing 'dtest.Rout' to 'dtest.Rout.save' ... OK
  Running 'dtest2.r' [154s]
  Running 'pbtest.R' [168s]
  Running 'theil.R' [169s]
Running the tests in 'tests/double.R' failed.
Complete output:
  > #
  > # Tests of integer case weights
  > #
  > library(deming)
  > 
  > data1 <- ferritin[ferritin$period==2,]
  > data1$wt <- c(1:10, 10:1)
  > data2 <- data1[rep(1:20, c(1:10, 10:1)),]
  > 
  > fit1a <- deming(new.lot ~ old.lot, data1, weight=wt)
  > fit1b <- deming(new.lot ~ old.lot, data2)
  > all.equal(coef(fit1a), coef(fit1b))
  [1] TRUE
  > 
  > fit2a <- deming(new.lot ~ old.lot, data1, cv=TRUE, weight=wt, conf=0)
  > fit2b <- deming(new.lot ~ old.lot, data2, cv=TRUE, conf=0)
  > all.equal(coef(fit2a), coef(fit2b))
  [1] TRUE
  > 
  > # Variable case wieghts do not replicate exactly for Thiel-Sen regression
  > #  It is a problem of discreteness. 
  > # However making all case weights the same gives a valid test
  > data3 <- data1[rep(1:20, 2),]
  > data1$wt2 <- rep(2,20)
  > for (sym in c(FALSE, TRUE)) {
  +     fit3a <- theilsen(new.lot ~ old.lot, data1, weight=wt2, conf=0, 
  +                       symmetric=sym)
  +     fit3b <- theilsen(new.lot ~ old.lot, data3, conf=0, symmetric=sym)
  +     print(all.equal(coef(fit3a), coef(fit3b)))
  + }
  [1] TRUE
  [1] TRUE
  >  
  > for (m in 1:3) {
  +      fit4a <- pbreg(new.lot ~ old.lot, data1, weight=wt2, conf=0,
  +                     method=m)
  +      fit4b <- pbreg(new.lot ~ old.lot, data3, conf=0, method=m)
  +      print(all.equal(coef(fit4a), coef(fit4b)))
  +  }
  [1] TRUE
  [1] TRUE
  [1] TRUE
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.26    0.04    0.29 
Running the tests in 'tests/dtest2.r' failed.
Complete output:
  > #
  > # Weighted Deming puzzled me at first.  The Deming line with variance
  > #  weights does not lie in between the two weighted LS lines of y~x and x~y.
  > #
  > aeq <- function(x, y, ...) all.equal(as.vector(x), as.vector(y), ...)
  > require(deming)
  Loading required package: deming
  > 
  > #
  > # Create a data set where the true line is y= .5 x + 3
  > set.seed(12345)
  > true <- 1:10
  > x <- true + rnorm(10, mean=0, true/4)
  > y <- 0.5*true + rnorm(10, 3, true/4)
  > 
  > d1 <- deming(y ~ x, xstd=x, ystd=y)
  > d1b <- deming(x ~ y, ystd=x, xstd=y)
  > # The deming routine uses optimize, which defaults to a tolerance of
  > #  .Machine$double.eps^.25, less than the default for all.equal.
  > tol <- .Machine$double.eps^.25
  > aeq(coef(d1b), c(-coef(d1)[1], 1)/coef(d1)[2], tol=tol)
  [1] TRUE
  > 
  > d2 <- deming(y ~ x, cv=TRUE)
  > 
  > # Given a proposed fit, this function gives the xy values on the
  > #  fitted line that are closest to each data point.
  > ufun <- function(coef, x, y, xvar, yvar) {
  +     wt <- 1/(yvar + coef[2]*xvar)
  +     u <- wt* (yvar*x + xvar* coef[2] *(y-coef[1]))
  +     list(x=u, y = coef[1] + coef[2]*u, wt=wt)
  + }
  > 
  > # Iterations of the proportional fit
  > #  It uses average weights to stabilize the iteration path
  > imat <- matrix(0, 20, 2)
  > xstd <- x; ystd <- y
  > imat[1,] <- coef(d1)
  > for (i in 2:20) {
  +     temp <- ufun(imat[i-1,], x, y,  xstd^2, ystd^2)
  +     xstd <- (temp$x + xstd)/2
  +     ystd <- (temp$y + ystd)/2
  +     ifit <- deming(y ~ x, xstd=xstd, ystd=ystd)
  +     imat[i,] <- coef(ifit)
  + }
  >     
  > # The fit with CV=true does not follow exactly this path, since for the
  > #  intermediate steps it uses different bounds for the optimize routine.
  > aeq(coef(d2), imat[10,], tol=.001)
  [1] TRUE
  > 
  > proc.time()
     user  system elapsed 
     0.32    0.09    0.39 
Running the tests in 'tests/pbtest.R' failed.
Complete output:
  > library(deming)
  > 
  > # Data set from Sen.  Since it is monotone the Thiel-Sen and PB regressions
  > #  are identical
  > #
  > sen <- data.frame(t=c(1,  2,  3,  4, 10, 12, 18),
  +                   y=c(9, 15, 19, 20, 45, 55, 78))
  > fit <- pbreg(y ~ t, data=sen, conf=.93)
  > all.equal(coef(fit), c("(Intercept)"=6, "t"=4))
  [1] TRUE
  > all.equal(fit$ci[2,], c(26/7, 35/8), check.attributes=FALSE)
  [1] TRUE
  > 
  > fit2 <- pbreg(y ~ t, data=sen, conf=.93, method=2)
  > fit3 <- pbreg(y ~ t, data=sen, conf=.93, method=3)
  > all.equal(coef(fit2), coef(fit))
  [1] TRUE
  > all.equal(coef(fit3), coef(fit))
  [1] TRUE
  > all.equal(fit2$ci, fit$ci)
  [1] TRUE
  > all.equal(fit3$ci, fit$ci)
  [1] TRUE
  > 
  > # Simple data set with noise
  > pdata <- data.frame(x=1:6, y=c(2,1.2, 4.1,3.5,6.3, 3))
  > fit <- pbreg(y~x, pdata)
  > all.equal(coef(fit), c(1/8, 1.05), check.attributes=FALSE)
  [1] TRUE
  > 
  > fit3 <- pbreg(y ~ x, pdata, method=3)
  > all.equal(coef(fit3), coef(fit))
  [1] TRUE
  > 
  > fit2 <- pbreg(y ~ x, pdata, method=2)
  > temp <- tan(mean(c(atan(2.2/2), atan(4.3/4))))
  > all.equal(as.vector(coef(fit2)), c(median(pdata$y- pdata$x*temp), temp))
  [1] "Mean relative difference: 0.05024691"
  > 
  > # test case with boot library
  > # library(boot)
  > # bfit <- pbreg(aes ~ aas, arsenate, method=3, nboot=500)
  > 
  > proc.time()
     user  system elapsed 
     0.18    0.10    0.26 
Running the tests in 'tests/theil.R' failed.
Complete output:
  > #
  > # Tests of Thiel-Sen regresion
  > #
  > library(deming)
  > 
  > # Data from Sen, JASA 1968
  > # Note that his confidence interval is incorrect in the paper, since
  > #  his list of values for (y_i - y_j)/(t_i - t_j) has mistakes
  > # He also does not use the large sample formula, but rather a table from
  > #  Kendall for the width of the interval
  > sen <- data.frame(t=c(1,  2,  3,  4, 10, 12, 18),
  +                   y=c(9, 15, 19, 20, 45, 55, 78))
  > fit <- theilsen(y ~ t, data=sen, conf=.93)
  > all.equal(coef(fit), c("(Intercept)"=6, "t"=4))
  [1] TRUE
  > all.equal(fit$ci[2,], c(26/7, 35/8))
  [1] TRUE
  > 
  > # The data is strictly monotone, so the symmetric solution = usual one
  > fit2 <- theilsen(y ~ t, data=sen, symmetric=TRUE)
  > all.equal(coef(fit2), coef(fit))
  [1] TRUE
  > 
  > 
  > # How do the symmetric and regular compare?
  > fcoef <- matrix(0, 7, 3)
  > for (i in 1:7) {
  +     tfit1 <- theilsen(new.lot ~ old.lot, ferritin, subset=(period==i))
  +     tfit2 <- theilsen(new.lot ~ old.lot, ferritin, subset=(period==i), 
  +                       symmetric=TRUE)
  +     tfit3 <- pbreg(new.lot ~ old.lot, ferritin, subset=(period==i))
  +     fcoef[i,] <- c(tfit1$coef[2], tfit2$coef[2], tfit3$coef[2])
  + }
  > # For this set Passing-Bablock and STS agree
  > # (When the slope is exactly 1 they must be identical, and these are close to 1).
  > all.equal(fcoef[,2], fcoef[,3])
  [1] TRUE
  > 
  > proc.time()
     user  system elapsed 
     0.26    0.06    0.32