diff --git a/DESCRIPTION b/DESCRIPTION index 6c75a44..ae2dbea 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: SimuNet -Title: Network simulation framework, with a zest of empiricism -Version: 2.1.0 +Title: Network Simulation Framework, with a Zest of Empiricism +Version: 2.1.1 Authors@R: person(given = "Kenneth", family = "Keuk", diff --git a/NAMESPACE b/NAMESPACE index abdd647..1ed893a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,8 @@ S3method(count_NA,scanList) S3method(count_nonNA,empirical) S3method(count_nonNA,sLlist) S3method(count_nonNA,scanList) +S3method(print,edgeProb) +S3method(print,edgeProbMat) S3method(print,matList) S3method(print,scaled) S3method(print,scanList) diff --git a/NEWS.md b/NEWS.md index 1c3383b..f387049 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# SimuNet 2.1.1 +* `print` method is cleaner for `edgeProb` and newly introduced `edgeProbMat` classes: + * `edgeProbMat` is the matrix itself stored in `edgeProb` object (their `$P`), with attribute + `Beta prior` + # SimuNet 2.1.0 * `print` methods are cleaner for SimuNet specific objects: *`scanList` objects printing now relies on Matrix `sparseMatrix` class diff --git a/R/edgeProb.R b/R/edgeProb.R index 5d18600..cd3c001 100644 --- a/R/edgeProb.R +++ b/R/edgeProb.R @@ -138,6 +138,7 @@ draw_edgeProb <- function(Adj,samp.effort, P[Adj.subfun(P)] <- Adj[Adj.subfun(Adj)] |> {\(x) stats::rbeta(length(x),shape1 = x + alpha.prior,shape2 = samp.effort - x + beta.prior)}() + class(P) <- c("edgeProbMat","weightedAdj") attr(P,"Beta priors") <- c(alpha.prior,beta.prior) P } diff --git a/R/scanList_tools.R b/R/scanList_tools.R index acc45b0..cd33b24 100644 --- a/R/scanList_tools.R +++ b/R/scanList_tools.R @@ -401,13 +401,32 @@ print.weightedAdj <- function(x,...) { invisible(x) } +#' Print method for `edgeProb` objects +#' @export +#' @noRd +print.edgeProb <- function(x,...) { + print(x$P) + invisible(x) +} + +#' Print method for `edgeProbMat` objects +#' @export +#' @noRd +print.edgeProbMat <- function(x,digits = 3,...) { + to.print <- x |> round(digits = digits) + class(to.print) <- NULL + print_clean_scan(to.print,"Edge presence probability matrix",...) + format_attributes(x,...) + invisible(x) +} + #' Print method for `scaled` objects #' @export #' @noRd -print.scaled <- function(x,digits = 2,...) { +print.scaled <- function(x,digits = 3,...) { to.print <- without_attrs(x) |> round(digits = digits) class(to.print) <- NULL - print_clean_scan(to.print,"Weighted adjacency matrix",...) + print_clean_scan(to.print,"Scaled weighted adjacency matrix",...) format_attributes(x,...) invisible(x) } @@ -467,7 +486,8 @@ print_clean_scan <- function(scan,s, col.names = FALSE, note.dropping.colnames = FALSE, ...) { - cat("\nscan: ",s,sep = "") + if (is.numeric(s)) cat("\nscan: ",s,sep = "") + else cat("\n",s,sep = "") methods::as(scan,"dgCMatrix") |> Matrix::printSpMatrix(col.names = col.names,note.dropping.colnames = note.dropping.colnames, ...) @@ -482,5 +502,9 @@ print_clean_scan <- function(scan,s, #' @noRd format_attributes <- function(x,...) { if (!is.null(get_attrs(x))) cat("\n\nHidden attributes:",names(get_attrs(x))) + if (inherits(x,"edgeProbMat")) { + bet <- attr(x,"Beta priors") + cat("\n","alpha.prior =",bet[1],"-","beta.prior =",bet[2]) + } invisible(x) } diff --git a/docs/404.html b/docs/404.html index 77db3b3..a044f55 100644 --- a/docs/404.html +++ b/docs/404.html @@ -71,7 +71,7 @@
diff --git a/docs/LICENSE-text.html b/docs/LICENSE-text.html index 2a5d9fb..974b4ea 100644 --- a/docs/LICENSE-text.html +++ b/docs/LICENSE-text.html @@ -71,7 +71,7 @@ diff --git a/docs/articles/articles/SimuNet.html b/docs/articles/articles/SimuNet.html index 2d904ff..0c55d1f 100644 --- a/docs/articles/articles/SimuNet.html +++ b/docs/articles/articles/SimuNet.html @@ -31,7 +31,7 @@ diff --git a/docs/articles/articles/bayesian_framework.html b/docs/articles/articles/bayesian_framework.html index c8a2dcd..1aabd30 100644 --- a/docs/articles/articles/bayesian_framework.html +++ b/docs/articles/articles/bayesian_framework.html @@ -31,7 +31,7 @@ diff --git a/docs/articles/articles/experiments.html b/docs/articles/articles/experiments.html index d62d6e8..a5f8a10 100644 --- a/docs/articles/articles/experiments.html +++ b/docs/articles/articles/experiments.html @@ -31,7 +31,7 @@ diff --git a/docs/articles/articles/first_simulations.html b/docs/articles/articles/first_simulations.html index a9bf120..393c8e9 100644 --- a/docs/articles/articles/first_simulations.html +++ b/docs/articles/articles/first_simulations.html @@ -31,7 +31,7 @@ @@ -293,116 +293,84 @@
attrs(sL1,"edge.Prob")
#>
-#> scan: Weighted adjacency matrix
-#> 1 . 0.0776161 0.0492505 0.19986459 0.22234518 0.01638577 0.02899979
-#> 2 . . 0.0496862 0.07848638 0.14766658 0.01207263 0.03504616
-#> 3 . . . 0.06673512 0.04245128 0.01326973 0.02086057
-#> 4 . . . . 0.23123765 0.04059005 0.10114616
-#> 5 . . . . . 0.02359744 0.06448588
-#> 6 . . . . . . 0.01610144
-#> 7 . . . . . . .
-#> 8 . . . . . . .
-#> 9 . . . . . . .
-#> 10 . . . . . . .
-#> 11 . . . . . . .
-#> 12 . . . . . . .
-#> 13 . . . . . . .
-#> 14 . . . . . . .
-#> 15 . . . . . . .
-#> 16 . . . . . . .
-#> 17 . . . . . . .
-#>
-#> 1 0.0006450756 0.0040950044 0.0122652350 0.03217798 0.029062592 4.986895e-03
-#> 2 0.0104276291 0.0327193439 0.0080912292 0.05208179 0.021934324 4.110393e-03
-#> 3 0.0029787842 0.0283641146 0.0237015100 0.05515156 0.000196407 9.058990e-04
-#> 4 0.0138772622 0.0002038678 0.0084223261 0.02797502 0.007118848 1.107962e-02
-#> 5 0.0207999024 0.0148036189 0.0145838108 0.03056718 0.005601463 9.386840e-03
-#> 6 0.0030905384 0.0121620932 0.0175044108 0.01139219 0.021744509 6.345596e-03
-#> 7 0.0109808606 0.0065556647 0.0007369142 0.02492163 0.007605176 1.243715e-02
-#> 8 . 0.0147895998 0.0025051077 0.01200596 0.003340425 4.129263e-03
-#> 9 . . 0.0360907445 0.02981308 0.011994371 3.699488e-03
-#> 10 . . . 0.04006253 0.014968495 9.356379e-05
-#> 11 . . . . 0.010471724 7.054436e-03
-#> 12 . . . . . 1.601266e-03
-#> 13 . . . . . .
-#> 14 . . . . . .
-#> 15 . . . . . .
-#> 16 . . . . . .
-#> 17 . . . . . .
-#>
-#> 1 0.022184977 0.015801537 2.441892e-03 4.783421e-04
-#> 2 0.024475770 0.012675214 2.718076e-03 1.576357e-03
-#> 3 0.001476006 0.005078207 7.238291e-03 1.070115e-04
-#> 4 0.010985443 0.019933258 2.269240e-03 4.299671e-03
-#> 5 0.013364264 0.007368450 3.879572e-03 1.316662e-04
-#> 6 0.007657000 0.018576164 9.672575e-03 4.718849e-06
-#> 7 0.015618045 0.010941799 8.278908e-03 3.340425e-03
-#> 8 0.002238004 0.001165090 2.131663e-04 2.558103e-04
-#> 9 0.001463999 0.016276154 2.352043e-03 6.154304e-03
-#> 10 0.010434343 0.002065702 4.948608e-03 1.274535e-03
-#> 11 0.007021987 0.040815764 9.266944e-03 6.330251e-04
-#> 12 0.010726018 0.003002353 2.117829e-03 5.038555e-03
-#> 13 0.001176362 0.032799854 3.615031e-03 2.103654e-04
-#> 14 . 0.003637221 1.227522e-03 1.073882e-03
-#> 15 . . 1.401112e-05 6.226573e-03
-#> 16 . . . 9.215061e-04
-#> 17 . . . .
+#> Edge presence probability matrix
+#> 1 . 0.078 0.049 0.200 0.222 0.016 0.029 0.001 0.004 0.012 0.032 0.029 0.005
+#> 2 . . 0.050 0.078 0.148 0.012 0.035 0.010 0.033 0.008 0.052 0.022 0.004
+#> 3 . . . 0.067 0.042 0.013 0.021 0.003 0.028 0.024 0.055 . 0.001
+#> 4 . . . . 0.231 0.041 0.101 0.014 . 0.008 0.028 0.007 0.011
+#> 5 . . . . . 0.024 0.064 0.021 0.015 0.015 0.031 0.006 0.009
+#> 6 . . . . . . 0.016 0.003 0.012 0.018 0.011 0.022 0.006
+#> 7 . . . . . . . 0.011 0.007 0.001 0.025 0.008 0.012
+#> 8 . . . . . . . . 0.015 0.003 0.012 0.003 0.004
+#> 9 . . . . . . . . . 0.036 0.030 0.012 0.004
+#> 10 . . . . . . . . . . 0.040 0.015 .
+#> 11 . . . . . . . . . . . 0.010 0.007
+#> 12 . . . . . . . . . . . . 0.002
+#> 13 . . . . . . . . . . . . .
+#> 14 . . . . . . . . . . . . .
+#> 15 . . . . . . . . . . . . .
+#> 16 . . . . . . . . . . . . .
+#> 17 . . . . . . . . . . . . .
+#>
+#> 1 0.022 0.016 0.002 .
+#> 2 0.024 0.013 0.003 0.002
+#> 3 0.001 0.005 0.007 .
+#> 4 0.011 0.020 0.002 0.004
+#> 5 0.013 0.007 0.004 .
+#> 6 0.008 0.019 0.010 .
+#> 7 0.016 0.011 0.008 0.003
+#> 8 0.002 0.001 . .
+#> 9 0.001 0.016 0.002 0.006
+#> 10 0.010 0.002 0.005 0.001
+#> 11 0.007 0.041 0.009 0.001
+#> 12 0.011 0.003 0.002 0.005
+#> 13 0.001 0.033 0.004 .
+#> 14 . 0.004 0.001 0.001
+#> 15 . . . 0.006
+#> 16 . . . 0.001
+#> 17 . . . .
+#>
+#> alpha.prior = 0.5 - beta.prior = 0.5
sL2 |> attrs("edge.Prob") # most of `SimuNet`'s functions have been written to allow for piping
#>
-#> scan: Weighted adjacency matrix
-#> 1 . 0.08562081 0.04493884 0.16517529 0.19864749 0.01715270 0.10443958
-#> 2 . . 0.02696101 0.11539047 0.06752228 0.01677422 0.03618678
-#> 3 . . . 0.05178456 0.08449750 0.01631503 0.02928023
-#> 4 . . . . 0.16636952 0.03199504 0.05423566
-#> 5 . . . . . 0.02461877 0.07562590
-#> 6 . . . . . . 0.01697340
-#> 7 . . . . . . .
-#> 8 . . . . . . .
-#> 9 . . . . . . .
-#> 10 . . . . . . .
-#> 11 . . . . . . .
-#> 12 . . . . . . .
-#> 13 . . . . . . .
-#> 14 . . . . . . .
-#> 15 . . . . . . .
-#> 16 . . . . . . .
-#> 17 . . . . . . .
-#>
-#> 1 1.850615e-02 0.016599337 2.164714e-02 0.044539699 0.002727028 2.036787e-02
-#> 2 4.684866e-03 0.046779787 1.250943e-02 0.053332837 0.002711297 2.843922e-02
-#> 3 6.907011e-03 0.042060039 1.313331e-02 0.060186833 0.002043329 5.580191e-05
-#> 4 3.790919e-03 0.027805963 4.487977e-03 0.035504618 0.006133952 1.175743e-02
-#> 5 6.405007e-05 0.020336607 2.329693e-02 0.020282220 0.011646091 4.976527e-03
-#> 6 6.787192e-03 0.004679183 1.763469e-02 0.016240387 0.002596024 8.940842e-03
-#> 7 7.013750e-03 0.003070953 9.002736e-05 0.007461442 0.012325443 9.818591e-03
-#> 8 . 0.007687619 4.686595e-03 0.010955405 0.022971716 4.843406e-06
-#> 9 . . 1.395572e-02 0.056727038 0.004214322 2.957549e-04
-#> 10 . . . 0.024600453 0.001567789 3.891127e-06
-#> 11 . . . . 0.011287116 1.581856e-02
-#> 12 . . . . . 3.376707e-04
-#> 13 . . . . . .
-#> 14 . . . . . .
-#> 15 . . . . . .
-#> 16 . . . . . .
-#> 17 . . . . . .
-#>
-#> 1 1.429509e-02 1.090588e-02 0.0005938726 2.034523e-03
-#> 2 1.998622e-04 3.413044e-02 0.0001852346 5.166429e-04
-#> 3 1.713310e-04 1.846301e-02 0.0041872102 6.012093e-03
-#> 4 1.121332e-02 1.038360e-02 0.0008201424 2.541165e-03
-#> 5 2.846518e-02 9.767288e-03 0.0068632078 1.595663e-03
-#> 6 3.025193e-03 2.038940e-02 0.0008922951 8.693587e-03
-#> 7 4.408574e-03 8.206820e-03 0.0016565667 5.614195e-03
-#> 8 2.942689e-05 5.358921e-03 0.0031282429 1.810929e-03
-#> 9 1.158168e-03 8.244626e-03 0.0021872888 6.716383e-04
-#> 10 1.694990e-04 1.578871e-03 0.0002342553 1.416320e-02
-#> 11 6.757044e-03 2.050620e-02 0.0002415173 8.858702e-04
-#> 12 4.820351e-06 1.348147e-05 0.0045961543 1.209877e-03
-#> 13 1.168548e-03 1.407823e-02 0.0005742883 9.068857e-04
-#> 14 . 3.548803e-03 0.0010019616 3.406046e-03
-#> 15 . . 0.0005329228 1.265442e-03
-#> 16 . . . 8.653044e-05
-#> 17 . . . .
sum_scans(sL1)
#>
-#> scan: Weighted adjacency matrix
+#> Weighted adjacency matrix
#> 1 . . 1 4 2 . . . 1 . . . . . . . .
#> 2 . . . . 4 . . . . . . . . . . . .
#> 3 . . . . . . . . . . . . . . 1 . .
@@ -438,7 +406,7 @@
#> Hidden attributes: scanList.type raw.scanList Adj samp.effort n.scans mode Adj.subfun edge.Prob summed.scanList sampled
sL2 |> sum_scans()
#>
-#> scan: Weighted adjacency matrix
+#> Weighted adjacency matrix
#> 1 . . . 3 3 . . . 1 . 1 . 1 . . . .
#> 2 . . 1 . 1 . . . . . 1 . 1 . 1 . .
#> 3 . . . . 1 . . . . . 1 . . . 1 . .
@@ -470,7 +438,7 @@
sL3.Adj |> attrs("Adj")
#>
-#> scan: Weighted adjacency matrix
+#> Weighted adjacency matrix
#> 1 . 21 10 45 54 7 16 1 3 4 7 3 2 3 3 . .
#> 2 . . 9 19 20 3 9 1 10 4 11 2 2 2 6 . .
#> 3 . . . 8 10 3 5 1 9 4 10 . . . 3 2 .
@@ -490,7 +458,7 @@
#> 17 . . . . . . . . . . . . . . . . .
sL3.Adj
#>
-#> scan: Weighted adjacency matrix
+#> Weighted adjacency matrix
#> 1 . 28 17 41 45 11 14 . 2 2 7 6 1 3 6 5 1
#> 2 . . 2 9 16 12 4 1 6 7 6 6 . 1 16 . .
#> 3 . . . 11 20 5 3 4 5 5 9 . . 1 4 2 .
@@ -531,7 +499,7 @@
scale_scans(sL1)
#>
-#> scan: Weighted adjacency matrix
+#> Scaled weighted adjacency matrix
#> 1 . . 0.1 0.4 0.2 . . . 0.1 . . . . . . . .
#> 2 . . . . 0.4 . . . . . . . . . . . .
#> 3 . . . . . . . . . . . . . . 0.1 . .
@@ -554,7 +522,7 @@
#> Hidden attributes: scanList.type raw.scanList Adj samp.effort n.scans mode Adj.subfun edge.Prob summed.scanList sampled
sL2 |> scale_scans()
#>
-#> scan: Weighted adjacency matrix
+#> Scaled weighted adjacency matrix
#> 1 . . . 0.3 0.3 . . . 0.1 . 0.1 . 0.1 . . . .
#> 2 . . 0.1 . 0.1 . . . . . 0.1 . 0.1 . 0.1 . .
#> 3 . . . . 0.1 . . . . . 0.1 . . . 0.1 . .
@@ -577,42 +545,42 @@
#> Hidden attributes: scanList.type raw.scanList Adj samp.effort n.scans mode Adj.subfun edge.Prob summed.scanList sampled
scale_scans(sL3.Adj)
#>
-#> scan: Weighted adjacency matrix
-#> 1 . 0.12 0.07 0.17 0.19 0.05 0.06 . 0.01 0.01 0.03 0.02 . 0.01 0.02 0.02
-#> 2 . . 0.01 0.04 0.07 0.05 0.02 . 0.02 0.03 0.02 0.02 . . 0.07 .
-#> 3 . . . 0.05 0.08 0.02 0.01 0.02 0.02 0.02 0.04 . . . 0.02 0.01
-#> 4 . . . . 0.16 0.02 0.10 . 0.01 0.02 0.05 0.01 0.03 0.01 0.02 .
-#> 5 . . . . . 0.01 0.11 . 0.02 0.02 0.05 . 0.02 0.02 0.01 0.02
-#> 6 . . . . . . 0.01 0.01 . 0.02 . 0.01 0.02 . 0.01 .
-#> 7 . . . . . . . . 0.01 . 0.03 0.01 0.01 . 0.01 0.01
-#> 8 . . . . . . . . 0.01 0.02 0.01 . . . 0.01 .
-#> 9 . . . . . . . . . 0.02 0.05 . . . . .
-#> 10 . . . . . . . . . . 0.06 0.01 . . . .
-#> 11 . . . . . . . . . . . . . . 0.04 .
-#> 12 . . . . . . . . . . . . . . . .
-#> 13 . . . . . . . . . . . . . . 0.01 .
-#> 14 . . . . . . . . . . . . . . . .
-#> 15 . . . . . . . . . . . . . . . .
-#> 16 . . . . . . . . . . . . . . . .
-#> 17 . . . . . . . . . . . . . . . .
-#>
-#> 1 .
-#> 2 .
-#> 3 .
-#> 4 .
-#> 5 .
-#> 6 .
-#> 7 .
-#> 8 .
-#> 9 .
-#> 10 .
-#> 11 .
-#> 12 .
-#> 13 .
-#> 14 .
-#> 15 .
-#> 16 .
-#> 17 .
+#> Scaled weighted adjacency matrix
+#> 1 . 0.116 0.071 0.170 0.187 0.046 0.058 . 0.008 0.008 0.029 0.025 0.004
+#> 2 . . 0.008 0.037 0.066 0.050 0.017 0.004 0.025 0.029 0.025 0.025 .
+#> 3 . . . 0.046 0.083 0.021 0.012 0.017 0.021 0.021 0.037 . .
+#> 4 . . . . 0.162 0.021 0.104 . 0.012 0.025 0.046 0.008 0.029
+#> 5 . . . . . 0.008 0.112 . 0.021 0.017 0.046 0.004 0.017
+#> 6 . . . . . . 0.008 0.012 . 0.025 0.004 0.008 0.021
+#> 7 . . . . . . . . 0.008 . 0.029 0.008 0.008
+#> 8 . . . . . . . . 0.008 0.025 0.008 . .
+#> 9 . . . . . . . . . 0.021 0.054 0.004 .
+#> 10 . . . . . . . . . . 0.062 0.008 .
+#> 11 . . . . . . . . . . . 0.004 .
+#> 12 . . . . . . . . . . . . .
+#> 13 . . . . . . . . . . . . .
+#> 14 . . . . . . . . . . . . .
+#> 15 . . . . . . . . . . . . .
+#> 16 . . . . . . . . . . . . .
+#> 17 . . . . . . . . . . . . .
+#>
+#> 1 0.012 0.025 0.021 0.004
+#> 2 0.004 0.066 . .
+#> 3 0.004 0.017 0.008 .
+#> 4 0.012 0.017 . .
+#> 5 0.025 0.012 0.017 .
+#> 6 . 0.008 . .
+#> 7 0.004 0.008 0.008 .
+#> 8 . 0.008 . .
+#> 9 . 0.004 . .
+#> 10 . . . .
+#> 11 . 0.041 . .
+#> 12 . . . 0.004
+#> 13 . 0.008 . 0.004
+#> 14 . 0.004 . .
+#> 15 . . . .
+#> 16 . . . .
+#> 17 . . . .
#>
#>
#> Hidden attributes: scanList.type raw.scanList Adj samp.effort n.scans mode Adj.subfun edge.Prob summed.scanList sampled
diff --git a/docs/articles/articles/importing_networks.html b/docs/articles/articles/importing_networks.html
index 613b164..aaee31e 100644
--- a/docs/articles/articles/importing_networks.html
+++ b/docs/articles/articles/importing_networks.html
@@ -31,7 +31,7 @@