dwww Home | Show directory contents | Find package

R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

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

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

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

> 
> library("libcoin")
> 
> ### by Henric Winell
> set.seed(29)
> X <- runif(10)
> Y <- runif(10)
> o <- LinStatExpCov(X, Y)
> ov <- LinStatExpCov(X, Y, varonly = TRUE)
> stopifnot(all.equal(doTest(o, teststat = "scalar"),
+                     doTest(ov, teststat = "scalar")))
> 
> ### all weights = 0 and no weights at all was treated the same
> X <- as.double(1:10)
> Y <- as.double(10:1)
> sum(X*Y)
[1] 220
> cl <- gl(2, 5)
> 
> ### linstat = 220
> w <- as.integer(rep(1, 10))
> LinStatExpCov(X = X, Y = Y)
$LinearStatistic
[1] 220

$Expectation
[1] 302.5

$Covariance
[1] 756.25

$Variance
[1] 756.25

$ExpectationX
[1] 55

$varonly
[1] FALSE

$dimension
[1] 1 1

$ExpectationInfluence
[1] 5.5

$CovarianceInfluence
[1] 8.25

$VarianceInfluence
[1] 8.25

$Xfactor
[1] FALSE

$tol
[1] 1.490116e-08

$PermutedLinearStatistic
<0 x 0 matrix>

$StandardisedPermutedLinearStatistic
<0 x 0 matrix>

$TableBlock
[1]  0 10

$Sumweights
[1] 10

$Table
NULL

attr(,"class")
[1] "LinStatExpCov1d" "LinStatExpCov"  
> LinStatExpCov(X = X, Y = Y, weights = w)
$LinearStatistic
[1] 220

$Expectation
[1] 302.5

$Covariance
[1] 756.25

$Variance
[1] 756.25

$ExpectationX
[1] 55

$varonly
[1] FALSE

$dimension
[1] 1 1

$ExpectationInfluence
[1] 5.5

$CovarianceInfluence
[1] 8.25

$VarianceInfluence
[1] 8.25

$Xfactor
[1] FALSE

$tol
[1] 1.490116e-08

$PermutedLinearStatistic
<0 x 0 matrix>

$StandardisedPermutedLinearStatistic
<0 x 0 matrix>

$TableBlock
[1]  0 10

$Sumweights
[1] 10

$Table
NULL

attr(,"class")
[1] "LinStatExpCov1d" "LinStatExpCov"  
> LinStatExpCov(X = X, Y = Y, weights = w, block = cl)
$LinearStatistic
[1] 220

$Expectation
[1] 240

$Covariance
[1] 50

$Variance
[1] 50

$ExpectationX
[1] 55

$varonly
[1] FALSE

$dimension
[1] 1 1

$ExpectationInfluence
[1] 8 3

$CovarianceInfluence
[1] 2 2

$VarianceInfluence
[1] 2 2

$Xfactor
[1] FALSE

$tol
[1] 1.490116e-08

$PermutedLinearStatistic
<0 x 0 matrix>

$StandardisedPermutedLinearStatistic
<0 x 0 matrix>

$TableBlock
[1] 0 5 5

$Sumweights
[1] 5 5

$Table
NULL

attr(,"class")
[1] "LinStatExpCov1d" "LinStatExpCov"  
> 
> ### linstat = 0
> w <- as.integer(rep(0, 10))
> LinStatExpCov(X = X, Y = Y, weights = w)
$LinearStatistic
[1] 0

$Expectation
[1] 0

$Covariance
[1] 0

$Variance
[1] 0

$ExpectationX
[1] 0

$varonly
[1] FALSE

$dimension
[1] 1 1

$ExpectationInfluence
[1] 0

$CovarianceInfluence
[1] 0

$VarianceInfluence
[1] 0

$Xfactor
[1] FALSE

$tol
[1] 1.490116e-08

$PermutedLinearStatistic
<0 x 0 matrix>

$StandardisedPermutedLinearStatistic
<0 x 0 matrix>

$TableBlock
[1]  0 10

$Sumweights
[1] 0

$Table
NULL

attr(,"class")
[1] "LinStatExpCov1d" "LinStatExpCov"  
> LinStatExpCov(X = X, Y = Y, weights = w, block = cl)
$LinearStatistic
[1] 0

$Expectation
[1] 0

$Covariance
[1] 0

$Variance
[1] 0

$ExpectationX
[1] 0

$varonly
[1] FALSE

$dimension
[1] 1 1

$ExpectationInfluence
[1] 0 0

$CovarianceInfluence
[1] 0 0

$VarianceInfluence
[1] 0 0

$Xfactor
[1] FALSE

$tol
[1] 1.490116e-08

$PermutedLinearStatistic
<0 x 0 matrix>

$StandardisedPermutedLinearStatistic
<0 x 0 matrix>

$TableBlock
[1] 0 5 5

$Sumweights
[1] 0 0

$Table
NULL

attr(,"class")
[1] "LinStatExpCov1d" "LinStatExpCov"  
> 
> ### linstat = 110
> w <- as.integer(rep(0, 10))
> w[1:5] <- 1L
> LinStatExpCov(X = X, Y = Y, subset = 1:5)
$LinearStatistic
[1] 110

$Expectation
[1] 120

$Covariance
[1] 25

$Variance
[1] 25

$ExpectationX
[1] 15

$varonly
[1] FALSE

$dimension
[1] 1 1

$ExpectationInfluence
[1] 8

$CovarianceInfluence
[1] 2

$VarianceInfluence
[1] 2

$Xfactor
[1] FALSE

$tol
[1] 1.490116e-08

$PermutedLinearStatistic
<0 x 0 matrix>

$StandardisedPermutedLinearStatistic
<0 x 0 matrix>

$TableBlock
[1] 0 5

$Sumweights
[1] 5

$Table
NULL

attr(,"class")
[1] "LinStatExpCov1d" "LinStatExpCov"  
> LinStatExpCov(X = X, Y = Y, weights = w)
$LinearStatistic
[1] 110

$Expectation
[1] 120

$Covariance
[1] 25

$Variance
[1] 25

$ExpectationX
[1] 15

$varonly
[1] FALSE

$dimension
[1] 1 1

$ExpectationInfluence
[1] 8

$CovarianceInfluence
[1] 2

$VarianceInfluence
[1] 2

$Xfactor
[1] FALSE

$tol
[1] 1.490116e-08

$PermutedLinearStatistic
<0 x 0 matrix>

$StandardisedPermutedLinearStatistic
<0 x 0 matrix>

$TableBlock
[1]  0 10

$Sumweights
[1] 5

$Table
NULL

attr(,"class")
[1] "LinStatExpCov1d" "LinStatExpCov"  
> LinStatExpCov(X = X, Y = Y, weights = w, block = cl)
$LinearStatistic
[1] 110

$Expectation
[1] 120

$Covariance
[1] 25

$Variance
[1] 25

$ExpectationX
[1] 15

$varonly
[1] FALSE

$dimension
[1] 1 1

$ExpectationInfluence
[1] 8 0

$CovarianceInfluence
[1] 2 0

$VarianceInfluence
[1] 2 0

$Xfactor
[1] FALSE

$tol
[1] 1.490116e-08

$PermutedLinearStatistic
<0 x 0 matrix>

$StandardisedPermutedLinearStatistic
<0 x 0 matrix>

$TableBlock
[1] 0 5 5

$Sumweights
[1] 5 0

$Table
NULL

attr(,"class")
[1] "LinStatExpCov1d" "LinStatExpCov"  
> 
> ### linstat = 0
> LinStatExpCov(X = X, Y = Y, weights = w, subset = 6:10)
$LinearStatistic
[1] 0

$Expectation
[1] 0

$Covariance
[1] 0

$Variance
[1] 0

$ExpectationX
[1] 0

$varonly
[1] FALSE

$dimension
[1] 1 1

$ExpectationInfluence
[1] 0

$CovarianceInfluence
[1] 0

$VarianceInfluence
[1] 0

$Xfactor
[1] FALSE

$tol
[1] 1.490116e-08

$PermutedLinearStatistic
<0 x 0 matrix>

$StandardisedPermutedLinearStatistic
<0 x 0 matrix>

$TableBlock
[1] 0 5

$Sumweights
[1] 0

$Table
NULL

attr(,"class")
[1] "LinStatExpCov1d" "LinStatExpCov"  
> LinStatExpCov(X = X, Y = Y, weights = w, block = cl, subset = 6:10)
$LinearStatistic
[1] 0

$Expectation
[1] 0

$Covariance
[1] 0

$Variance
[1] 0

$ExpectationX
[1] 0

$varonly
[1] FALSE

$dimension
[1] 1 1

$ExpectationInfluence
[1] 0 0

$CovarianceInfluence
[1] 0 0

$VarianceInfluence
[1] 0 0

$Xfactor
[1] FALSE

$tol
[1] 1.490116e-08

$PermutedLinearStatistic
<0 x 0 matrix>

$StandardisedPermutedLinearStatistic
<0 x 0 matrix>

$TableBlock
[1] 0 0 5

$Sumweights
[1] 0 0

$Table
NULL

attr(,"class")
[1] "LinStatExpCov1d" "LinStatExpCov"  
> 
> ### missing values in 1d and 2d case
> x <- gl(6, 20)
> y <- gl(3, 40)
> x[sample(1:length(x), 10)] <- NA
> y[sample(1:length(y), 10)] <- NA
> 
> X <- matrix(NA, nrow = length(x), ncol = nlevels(x))
> X[!is.na(x),] <- model.matrix(~ x - 1)
> Y <- matrix(NA, nrow = length(y), ncol = nlevels(y))
> Y[!is.na(y),] <- model.matrix(~ y - 1)
> 
> lev1 <- LinStatExpCov(X = X, Y = Y)
> lev1$Sumweights
[1] 100
> t1 <- doTest(lev1, teststat = "quadratic")
> 
> X <- rbind(0, diag(nlevels(x)))
> Y <- rbind(0, diag(nlevels(y)))
> ix <- unclass(x)
> ix[is.na(ix)] <- 0L
> iy <- unclass(y)
> iy[is.na(iy)] <- 0L
> levels(ix) <- levels(x)
> levels(iy) <- levels(y)
> 
> lev2 <- LinStatExpCov(X = X, Y = Y, ix = ix, iy = iy)
> lev2$Sumweights
[1] 100
> t2 <- doTest(lev2, teststat = "quadratic")
> stopifnot(all.equal(t1, t2))
> 
> ### unnecessary memory allocation; fixed in 1.0-2
> N <- 146341L
> y <- runif(N)
> x <- 1:N
> lev1 <- LinStatExpCov(X = x, Y = y, varonly = TRUE)
> # Note: N * (N + 1) / 2 > .Machine$integer.max
> try(lev2 <- LinStatExpCov(X = x, Y = y, varonly = FALSE))
Error in .LinStatExpCov1d(X = X, Y = Y, weights = weights, subset = subset,  : 
  cannot allocate memory: number of levels too large
> 
> 
> proc.time()
   user  system elapsed 
  0.160   0.032   0.187 

Generated by dwww version 1.15 on Sun Jun 16 02:51:18 CEST 2024.