Running 'test-NMI.R' [0s]
  Running 'test-adj_RI.R' [0s]
  Running 'test-community_allegiance.R' [0s]
  Running 'test-compute_mod_matrix.R' [159s]
  Running 'test-compute_multimodal_mod.R' [157s]
  Running 'test-consensus_similarity.R' [1s]
  Running 'test-count_pairs.R' [161s]
  Running 'test-degree.R' [165s]
  Running 'test-entropy.R' [0s]
  Running 'test-ext_distance.R' [166s]
  Running 'test-ham_distance.R' [1s]
  Running 'test-hms.R' [0s]
  Running 'test-kernel.R' [162s]
  Running 'test-matrix_to_df.R' [1s]
  Running 'test-purity.R' [0s]
  Running 'test-score_cont_nonparam.R' [175s]
  Running 'test-score_cont_semiparam.R' [0s]
  Running 'test-score_log_nonparam.R' [158s]
  Running 'test-score_log_semiparam.R' [158s]
  Running 'test-sort_pairs.R' [0s]
  Running 'test-subset_matrix_to_df.R' [0s]
  Running 'test-trace.R' [162s]
  Running 'test-up_low.R' [159s]
  Running 'test-zrand.R' [0s]
Running the tests in 'tests/test-compute_mod_matrix.R' failed.
Complete output:
  > library(CommKern)
  
  Attaching package: 'CommKern'
  
  The following object is masked from 'package:stats':
  
      kernel
  
  > 
  > # Verifying output of compute_modularity_matrix
  > mod_matrix_alt <- function(net){
  +   m <- 0.5*sum(net$func_matrix)
  +   mod_matrix <- matrix(0,nrow=nrow(net$func_matrix),ncol=ncol(net$func_matrix))
  + 
  +   for (i in 1:nrow(net$func_matrix)){
  +     d_i <- net$vertexes$func_degree[i]
  +     for (j in 1:ncol(net$func_matrix)){
  +       A_ij <- net$func_matrix[i,j]
  +       d_j <- net$vertexes$func_degree[j]
  + 
  +       #Compute the null model
  +       null_probability <- (d_i*d_j)/(2*m)
  + 
  +       #Compute the modularity
  +       M_ij <- A_ij - null_probability
  +       mod_matrix[i,j] <- M_ij
  +     }
  +   }
  +   return(mod_matrix)
  + }
  > 
  > stopifnot(all(mod_matrix_alt(SBM_net)==CommKern:::compute_modularity_matrix(SBM_net)))
  > 
  > proc.time()
     user  system elapsed 
     0.17    0.17    0.32 
Running the tests in 'tests/test-compute_multimodal_mod.R' failed.
Complete output:
  > library(CommKern)
  
  Attaching package: 'CommKern'
  
  The following object is masked from 'package:stats':
  
      kernel
  
  > 
  > # Verifying the output of compute_multimodal_mod
  > multimod_alt <- function(net, mod_matrix, communities, alpha){
  +   rtn <- 0
  +   
  +   for (i in 1:nrow(mod_matrix)){
  +     for (j in 1:ncol(mod_matrix)){
  +       if(i==j){
  +         next
  +       }
  +       
  +       if(communities[i]!=communities[j]){
  +         next
  +       }
  +       M_ij <- mod_matrix[i,j]
  +       S_ij <- net$str_matrix[i,j]
  +       
  +       rtn <- rtn + (M_ij+(alpha*S_ij))
  +     }
  +   }
  +   -rtn
  + }
  > 
  > mod_mat_ex <- CommKern:::compute_modularity_matrix(SBM_net)
  > comms <- sample(c(1,2),80,replace=TRUE)
  > 
  > stopifnot(all.equal(multimod_alt(net=SBM_net,mod_matrix=mod_mat_ex,
  +                            communities=comms,alpha=1),
  +                     CommKern:::compute_multimodal_mod(mod_matrix=mod_mat_ex,net=SBM_net,
  +                                                       communities=comms,alpha=1),
  +                     tolerance=0.00001))
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.23    0.12    0.34 
Running the tests in 'tests/test-count_pairs.R' failed.
Complete output:
  > library(CommKern)
  
  Attaching package: 'CommKern'
  
  The following object is masked from 'package:stats':
  
      kernel
  
  > 
  > # ------------------------------------------------------------------------------
  > # Verify the return from count_pairs is as expected for a simple case
  > 
  > # Numeric inputs
  > x <- c(0,0,0,1,2,0,1,2,1,2)
  > y <- c(0,0,1,2,1,2,0,1,2,2)
  > i_order <- c(0,1,2,5,6,3,8,4,7,9)
  > 
  > numeric_rtn <- CommKern:::count_pairs(x,y,i_order)
  > 
  > stopifnot(identical(
  +           numeric_rtn,
  +           list(pair_nb = c(2,1,1,1,2,2,1),
  +                pair_a  = c(0,0,0,1,1,2,2),
  +                pair_b  = c(0,1,2,0,2,1,2),
  +                a_nb    = c(4,3,3),
  +                b_nb    = c(3,3,4))
  +           )
  +         )
  > 
  > proc.time()
     user  system elapsed 
     0.21    0.06    0.23 
Running the tests in 'tests/test-degree.R' failed.
Complete output:
  > library(CommKern)
  
  Attaching package: 'CommKern'
  
  The following object is masked from 'package:stats':
  
      kernel
  
  > 
  > # Does the trace of the degree matrix match column and row sums?
  > vertex_df_ex <- data.frame(node_id=seq(1:80),node_label=NA,
  +                            func_degree=NA,str_degree=NA,community=NA)
  > 
  > func_mat_ex <- SBM_net$func_matrix
  > str_mat_ex <- SBM_net$str_matrix
  > 
  > vertex_df_ex <- CommKern:::degree(func_mat_ex,str_mat_ex,vertex_df_ex)
  > 
  > stopifnot(all(vertex_df_ex$func_degree==colSums(func_mat_ex)))
  > stopifnot(all(vertex_df_ex$func_degree==rowSums(func_mat_ex)))
  > stopifnot(all(vertex_df_ex$str_degree==colSums(str_mat_ex)))
  > stopifnot(all(vertex_df_ex$str_degree==colSums(str_mat_ex)))
  > 
  > 
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.25    0.01    0.25 
Running the tests in 'tests/test-ext_distance.R' failed.
Complete output:
  > library(CommKern)
  
  Attaching package: 'CommKern'
  
  The following object is masked from 'package:stats':
  
      kernel
  
  > 
  > # Testing that function returns a symmetric matrix
  > w <- c(1,2,2,1,1,2,2,2,3,2,1,3)
  > x <- c(2,2,3,1,3,1,3,3,2,2,1,1)
  > y <- c(3,3,2,1,1,1,1,2,2,3,2,3)
  > z <- c(1,1,2,3,2,3,2,1,1,2,3,3)
  > 
  > wxyz_comms <- data.frame(w_comm = w, x_comm = x, y_comm = y, z_comm = z)
  > 
  > wxyz_NMI_comms <- ext_distance(wxyz_comms, variant = 'NMI')
  > wxyz_ARI_comms <- ext_distance(wxyz_comms, variant = 'adj_RI')
  > wxyz_purity_comms <- ext_distance(wxyz_comms, variant = 'purity')
  > 
  > stopifnot(isSymmetric(wxyz_NMI_comms)==FALSE)
  > stopifnot(isSymmetric(wxyz_ARI_comms)==FALSE)
  > stopifnot(isSymmetric(wxyz_purity_comms)==FALSE)
  > 
  > 
  > # Testing that distance matrix has values >=0
  > w <- c(1,2,2,1,1,2,2,2,3,2,1,3)
  > x <- c(2,2,3,1,3,1,3,3,2,2,1,1)
  > y <- c(3,3,2,1,1,1,1,2,2,3,2,3)
  > z <- c(1,1,2,3,2,3,2,1,1,2,3,3)
  > 
  > wxyz_comms <- data.frame(w_comm = w, x_comm = x, y_comm = y, z_comm = z)
  > 
  > wxyz_NMI_comms <- ext_distance(wxyz_comms, variant = 'NMI')
  > wxyz_ARI_comms <- ext_distance(wxyz_comms, variant = 'adj_RI')
  > wxyz_purity_comms <- ext_distance(wxyz_comms, variant = 'purity')
  > 
  > stopifnot(all(wxyz_NMI_comms >=0)==TRUE)
  > stopifnot(all(wxyz_ARI_comms >=0)==TRUE)
  > stopifnot(all(wxyz_purity_comms >=0)==TRUE)
  > 
  > proc.time()
     user  system elapsed 
     0.76    0.15    0.89 
Running the tests in 'tests/test-kernel.R' failed.
Complete output:
  > library(CommKern)
  
  Attaching package: 'CommKern'
  
  The following object is masked from 'package:stats':
  
      kernel
  
  > 
  > # Testing that the kernel function produces the same result as a a hard-coded kernel
  > test_mat <- matrix(data=runif(16,0,1),nrow=4,ncol=4)
  > test_rho <- 1.25
  > 
  > kernel_rtn <- kernel(test_mat,test_rho)
  > 
  > stopifnot(all.equal(
  +             kernel_rtn,exp(-(test_mat^2)/test_rho)
  +           )
  +         )
  > 
  > # More advanced check: does the kernel produce a positive semi-definite matrix?
  > sym_mat <- matrix(1:25,5)
  > sym_mat[lower.tri(sym_mat)] = t(sym_mat)[lower.tri(sym_mat)]
  > 
  > sym_rho <- 1.105
  > 
  > kernel_rtn <- kernel(sym_mat,sym_rho)
  > 
  > stopifnot(matrixcalc::is.positive.semi.definite(kernel_rtn)==TRUE)
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.17    0.06    0.21 
Running the tests in 'tests/test-score_cont_nonparam.R' failed.
Complete output:
  > library(CommKern)
  
  Attaching package: 'CommKern'
  
  The following object is masked from 'package:stats':
  
      kernel
  
  > 
  > # Verify expected error handles - grid granularity
  > y <- rnorm(10,mean=100,sd=10)
  > 
  > ex_mat <- matrix(runif(100,0,1),10)
  > ex_mat[lower.tri(ex_mat)] <- ex_mat[upper.tri(ex_mat)]
  > 
  > rtn <- tryCatch(CommKern::score_cont_nonparam(outcome=y,dist_mat=ex_mat,
  +                                               grid_gran=1),
  +                 error = function(e) {e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "Need to specify a grid search length of at least 2")
  > 
  > # Verify expected error handles - outcome vector
  > ex_mat <- matrix(runif(100,0,1),10)
  > ex_mat[lower.tri(ex_mat)] <- ex_mat[upper.tri(ex_mat)]
  > 
  > y <- as.matrix(rnorm(10,mean=100,sd=10))
  > 
  > rtn <- tryCatch(CommKern::score_cont_nonparam(outcome=y,dist_mat=ex_mat,
  +                                               grid_gran=5000),
  +                 error = function(e) {e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "Outcome must be specified as a vector")
  > 
  > # Verify expected error handles - numeric outcome
  > ex_mat <- matrix(runif(100,0,1),10)
  > ex_mat[lower.tri(ex_mat)] <- ex_mat[upper.tri(ex_mat)]
  > 
  > y <- as.list(rnorm(10,mean=100,sd=10))
  > 
  > rtn <- tryCatch(CommKern::score_cont_nonparam(outcome=y,dist_mat=ex_mat,
  +                                               grid_gran=5000),
  +                 error = function(e) {e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "Outcome vector must be numeric")
  > 
  > # Verify expected error handles - square distance matrix
  > y <- rnorm(10,mean=100,sd=10)
  > 
  > ex_mat <- matrix(runif(90,0,1),10)
  > 
  > rtn <- tryCatch(CommKern::score_cont_nonparam(outcome=y,dist_mat=ex_mat,
  +                                               grid_gran=5000),
  +                 error = function(e) {e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "The distance matrix must be a square matrix")
  > 
  > # Verify expected error handles - distance matrix and outcome dimensions
  > y <- rnorm(12,mean=100,sd=10)
  > 
  > ex_mat <- matrix(runif(100,0,1),10)
  > ex_mat[lower.tri(ex_mat)] <- ex_mat[upper.tri(ex_mat)]
  > 
  > rtn <- tryCatch(CommKern::score_cont_nonparam(outcome=y,dist_mat=ex_mat,
  +                                               grid_gran=5000),
  +                 error = function(e) {e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "The number of rows in the distance matrix must be equal to the length of the outcome vector")
  > 
  > proc.time()
     user  system elapsed 
     0.18    0.12    0.25 
Running the tests in 'tests/test-score_log_nonparam.R' failed.
Complete output:
  > library(CommKern)
  
  Attaching package: 'CommKern'
  
  The following object is masked from 'package:stats':
  
      kernel
  
  > 
  > # Verify expected error handles - grid granularity
  > y <- sample(c(0,1),10,replace=TRUE)
  > 
  > ex_mat <- matrix(runif(100,0,1),10)
  > ex_mat[lower.tri(ex_mat)] <- ex_mat[upper.tri(ex_mat)]
  > 
  > rtn <- tryCatch(CommKern::score_log_nonparam(outcome=y,dist_mat=ex_mat,
  +                                              grid_gran=1),
  +                 error = function(e) {e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "Need to specify a grid search length of at least 2")
  > 
  > # Verify expected error handles - outcome vector
  > ex_mat <- matrix(runif(100,0,1),10)
  > ex_mat[lower.tri(ex_mat)] <- ex_mat[upper.tri(ex_mat)]
  > 
  > y <- as.matrix(sample(c(0,1),10,replace=TRUE))
  > 
  > rtn <- tryCatch(CommKern::score_log_nonparam(outcome=y,dist_mat=ex_mat,
  +                                              grid_gran=5000),
  +                 error = function(e) {e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "Outcome must be specified as a vector")
  > 
  > # Verify expected error handles - numeric outcome
  > ex_mat <- matrix(runif(100,0,1),10)
  > ex_mat[lower.tri(ex_mat)] <- ex_mat[upper.tri(ex_mat)]
  > 
  > y <- sample(c("No","Yes"),10,replace=TRUE)
  > 
  > rtn <- tryCatch(CommKern::score_log_nonparam(outcome=y,dist_mat=ex_mat,
  +                                              grid_gran=5000),
  +                 error = function(e) {e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "Outcome vector must be numeric")
  > 
  > # Verify expected error handles - square distance matrix
  > y <- sample(c(0,1),10,replace=TRUE)
  > 
  > ex_mat <- matrix(runif(90,0,1),10)
  > 
  > rtn <- tryCatch(CommKern::score_log_nonparam(outcome=y,dist_mat=ex_mat,
  +                                              grid_gran=5000),
  +                 error = function(e) {e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "The distance matrix must be a square matrix")
  > 
  > # Verify expected error handles - distance matrix and outcome dimensions
  > y <- sample(c(0,1),15,replace=TRUE)
  > 
  > ex_mat <- matrix(runif(100,0,1),10)
  > ex_mat[lower.tri(ex_mat)] <- ex_mat[upper.tri(ex_mat)]
  > 
  > rtn <- tryCatch(CommKern::score_log_nonparam(outcome=y,dist_mat=ex_mat,
  +                                              grid_gran=5000),
  +                 error = function(e) {e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "The number of rows in the distance matrix must be equal to the length of the outcome vector")
  > 
  > 
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.21    0.04    0.25 
Running the tests in 'tests/test-score_log_semiparam.R' failed.
Complete output:
  > library(CommKern)
  
  Attaching package: 'CommKern'
  
  The following object is masked from 'package:stats':
  
      kernel
  
  > 
  > # Verify expected error handles - grid granularity
  > y <- sample(c(0,1),10,replace=TRUE)
  > covs <- data.frame(a=rnorm(10,mean=100,sd=5),b=sample(c(0,1),10,replace=TRUE))
  > 
  > ex_mat <- matrix(runif(100,0,1),10)
  > ex_mat[lower.tri(ex_mat)] <- ex_mat[upper.tri(ex_mat)]
  > 
  > rtn <- tryCatch(CommKern::score_log_semiparam(outcome=y,covars=covs,
  +                                               dist_mat=ex_mat,grid_gran=1),
  +                 error = function(e) {e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "Need to specify a grid search length of at least 2")
  > 
  > # Verify expected error handles - outcome vector
  > ex_mat <- matrix(runif(100,0,1),10)
  > ex_mat[lower.tri(ex_mat)] <- ex_mat[upper.tri(ex_mat)]
  > 
  > covs <- data.frame(a=rnorm(10,mean=100,sd=5),b=sample(c(0,1),10,replace=TRUE))
  > y <- as.matrix(sample(c(0,1),10,replace=TRUE))
  > 
  > rtn <- tryCatch(CommKern::score_log_semiparam(outcome=y,covars=covs,
  +                                              dist_mat=ex_mat,grid_gran=5000),
  +                 error = function(e) {e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "Outcome must be specified as a vector")
  > 
  > # Verify expected error handles - numeric outcome
  > ex_mat <- matrix(runif(100,0,1),10)
  > ex_mat[lower.tri(ex_mat)] <- ex_mat[upper.tri(ex_mat)]
  > 
  > covs <- data.frame(a=rnorm(10,mean=100,sd=5),b=sample(c(0,1),10,replace=TRUE))
  > y <- sample(c("No","Yes"),10,replace=TRUE)
  > 
  > rtn <- tryCatch(CommKern::score_log_semiparam(outcome=y,covars=covs,
  +                                              dist_mat=ex_mat,grid_gran=5000),
  +                 error = function(e) {e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "Outcome vector must be numeric")
  > 
  > # Verify expected error handles - square distance matrix
  > y <- sample(c(0,1),10,replace=TRUE)
  > covs <- data.frame(a=rnorm(10,mean=100,sd=5),b=sample(c(0,1),10,replace=TRUE))
  > 
  > ex_mat <- matrix(runif(90,0,1),10)
  > 
  > rtn <- tryCatch(CommKern::score_log_semiparam(outcome=y,covars=covs,
  +                                               dist_mat=ex_mat,grid_gran=5000),
  +                 error = function(e) {e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "The distance matrix must be a square matrix")
  > 
  > # Verify expected error handles - distance matrix and outcome dimensions
  > y <- sample(c(0,1),15,replace=TRUE)
  > covs <- data.frame(a=rnorm(10,mean=100,sd=5),b=sample(c(0,1),10,replace=TRUE))
  > 
  > ex_mat <- matrix(runif(100,0,1),10)
  > ex_mat[lower.tri(ex_mat)] <- ex_mat[upper.tri(ex_mat)]
  > 
  > rtn <- tryCatch(CommKern::score_log_semiparam(outcome=y,covars=covs,
  +                                               dist_mat=ex_mat,grid_gran=5000),
  +                 error = function(e) {e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "The number of rows in the distance matrix must be equal to the length of the outcome vector")
  > 
  > # Verify expected error handles - distance matrix and covariates dimensions
  > y <- sample(c(0,1),10,replace=TRUE)
  > covs <- data.frame(a=rnorm(12,mean=100,sd=5),b=sample(c(0,1),12,replace=TRUE))
  > 
  > ex_mat <- matrix(runif(100,0,1),10)
  > ex_mat[lower.tri(ex_mat)] <- ex_mat[upper.tri(ex_mat)]
  > 
  > rtn <- tryCatch(CommKern::score_log_semiparam(outcome=y,covars=covs,
  +                                               dist_mat=ex_mat,grid_gran=5000),
  +                 error = function(e) {e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "The number of rows in the distance matrix must be equal to the number of rows of the covariate dataframe")
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.21    0.06    0.21 
Running the tests in 'tests/test-trace.R' failed.
Complete output:
  > library(CommKern)
  
  Attaching package: 'CommKern'
  
  The following object is masked from 'package:stats':
  
      kernel
  
  > 
  > # Test that the trace function works for a square matrix
  > x <- matrix(1:9, ncol = 3)
  > stopifnot(CommKern:::tr(x) == sum(diag(x)))
  > 
  > # test that an error is thrown if a non square matrix is used.
  > x <- matrix(1:12, ncol = 3)
  > trc <- tryCatch(CommKern:::tr(x), error = function(e) {e})
  > stopifnot(inherits(trc, "simpleError"))
  > stopifnot(trc$message == "nrow(x) == ncol(x) is not TRUE")
  > 
  > # error if x is not an matrix
  > x <- 1:9
  > trc <- tryCatch(CommKern:::tr(x), error = function(e) {e})
  > stopifnot(inherits(trc, "simpleError"))
  > stopifnot(trc$message == "is.matrix(x) is not TRUE")
  > 
  > 
  > proc.time()
     user  system elapsed 
     0.17    0.06    0.21 
Running the tests in 'tests/test-up_low.R' failed.
Complete output:
  > library(CommKern)
  
  Attaching package: 'CommKern'
  
  The following object is masked from 'package:stats':
  
      kernel
  
  > 
  > 
  > # check for square matrix
  > x <- 1:12
  > rtn <- tryCatch(CommKern:::up_low(x), error = function(e){e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "is.matrix(dist_mat) is not TRUE")
  > 
  > x <- matrix(x, nrow = 3)
  > rtn <- tryCatch(CommKern:::up_low(x), error = function(e){e})
  > stopifnot(inherits(rtn, "simpleError"))
  > stopifnot(rtn$message == "nrow(dist_mat) == ncol(dist_mat) is not TRUE")
  > 
  > # check for integer inputs
  > x <- matrix(as.integer(1:9), ncol = 3)
  > rtn <- CommKern:::up_low(x)
  > stopifnot(identical(x, structure(1:9, dim = c(3L, 3L))))
  > 
  > # check for numeric inputs
  > x <- structure(c(-0.7, 1.2, 0.1, -0.7, 0.5, -0.9, 0.5, 1.8, 0.3, 0,
  +               -2.1, -0.6, -0.8, 0.4, -0.4, -2.3), dim = c(4L, 4L))
  > rtn <- CommKern:::up_low(x)
  > stopifnot(all.equal(rtn,
  +                     structure(c(0, 7.1, 6.56, 4.75, 7.1, 0, 8.22, 18.55, 6.56, 8.22,
  +                                 0, 8.19, 4.75, 18.55, 8.19, 0), dim = c(4L, 4L))
  +                     ))
  > 
  > proc.time()
     user  system elapsed 
     0.15    0.10    0.25