-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0423782
Showing
25 changed files
with
1,678 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Package: localboot | ||
Type: Package | ||
Title: Local Bootstrap Methods for Various Networks | ||
Version: 0.9.1 | ||
Date: 2023-12-18 | ||
Authors@R: c( | ||
person("Tianhai", "Zu", email = "zuti@mail.uc.edu", role = c("aut", "cre")), | ||
person("Yichen", "Qin", email = "qinyn@ucmail.uc.edu", role = c("aut","ctb")) | ||
) | ||
Description: Network analysis usually requires estimating the uncertainty of | ||
graph statistics. Through this package, we provide tools to bootstrap | ||
various networks via local bootstrap procedure. Additionally, it includes | ||
functions for generating probability matrices, creating network adjacency | ||
matrices from probability matrices, and plotting network structures. | ||
The reference will be updated soon. | ||
License: GPL-3 | ||
Depends: R (>= 3.5.0) | ||
Imports: graphics, viridis, Rcpp (>= 1.0.11) | ||
Suggests: testthat (>= 3.0.0) | ||
LinkingTo: Rcpp (>= 1.0.11), RcppEigen | ||
Encoding: UTF-8 | ||
RoxygenNote: 7.2.3 | ||
NeedsCompilation: yes | ||
Packaged: 2023-12-21 06:21:26 UTC; tianhaizu | ||
Author: Tianhai Zu [aut, cre], | ||
Yichen Qin [aut, ctb] | ||
Maintainer: Tianhai Zu <zuti@mail.uc.edu> | ||
Repository: CRAN | ||
Date/Publication: 2023-12-21 16:30:02 UTC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
b3ff1e6fb2563796e33807e5fb5277e1 *DESCRIPTION | ||
34b2759e632634bd546f0f996c90462d *NAMESPACE | ||
2de21dbbe9981853ed8044136e4bfac7 *R/RcppExports.R | ||
3f12e430a5c85fc62a93fa4a46566c42 *R/generate_network.R | ||
dbfa3d9aadd2c86f34d882814708dc99 *R/localboot-package.R | ||
2561a8d9d6edf4d3e1031010b9f1a7a0 *R/localboot.R | ||
a27164ba5703eb3ac36f0d4ff2fb8673 *R/plot_utils.R | ||
7db4f5555abf5afff49ac74d6b1b7aee *inst/sim/Fit_local_boot.R | ||
3297eecf83620025ab244fc3042be725 *inst/sim/Generate_various_networks.R | ||
cee90d493ca0b4fef38062105123af52 *inst/sim/Optimal_local_size.R | ||
4c91a053d9937e9a6d05a82697b114ac *inst/sim/Sim1_estimate_others.R | ||
ecbd16a807885cfd9f774444c9333efc *inst/sim/Sim1_estimates_local.R | ||
6c19806713660c3fae228f51e2d72e2c *inst/sim/Sim1_truese.R | ||
7aeb7398c9f8ef60a0931772f320086d *inst/sim/test_localcpp.R | ||
c6bd637748ae88df554ced68e6771e5f *man/generate_graphon.Rd | ||
d4a8f4bc1d08552a82ce03853a80b001 *man/generate_network_P.Rd | ||
29713984eab34fbaf668b7aeb31a0947 *man/localboot-package.Rd | ||
8e4dfea53e03f3df16393c8debc1214e *man/localboot.Rd | ||
5a4251717a7faa71fcf4313592d694d2 *man/plot_P.Rd | ||
2bb486ba071dbebebab7a32ea52a6e73 *man/plot_adj.Rd | ||
b4f0b014ec53404e843dbc718fabf57e *src/Makevars | ||
b4f0b014ec53404e843dbc718fabf57e *src/Makevars.win | ||
60ca2ca032d1a414ce63a92635ac1453 *src/RcppExports.cpp | ||
7fb7f7de7cc0aa9792b3ae46a8f87cde *src/localboot.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(generate_graphon) | ||
export(generate_network_P) | ||
export(localboot) | ||
export(plot_P) | ||
export(plot_adj) | ||
importFrom(Rcpp,evalCpp) | ||
importFrom(graphics,filled.contour) | ||
importFrom(viridis,viridis) | ||
useDynLib(localboot) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Generated by using Rcpp::compileAttributes() -> do not edit by hand | ||
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 | ||
|
||
get_dist_default_eigen <- function(A) { | ||
.Call('_localboot_get_dist_default_eigen', PACKAGE = 'localboot', A) | ||
} | ||
|
||
calculate_p_hat_matrix <- function(A, neibors_matrix) { | ||
.Call('_localboot_calculate_p_hat_matrix', PACKAGE = 'localboot', A, neibors_matrix) | ||
} | ||
|
||
sample_from_p_cpp <- function(p_hat_matrix, blist, random_matrix, no_loop) { | ||
.Call('_localboot_sample_from_p_cpp', PACKAGE = 'localboot', p_hat_matrix, blist, random_matrix, no_loop) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
# Define the formula to generate p matrix of graphon1 | ||
graphon1 <- function(u, size){ | ||
p_matrix = matrix(0,nrow=size,ncol=size) | ||
for(i in 1:size){ | ||
for(j in 1:size){ | ||
p <- cos(pi*(u[i]-u[j]))/(2^3) + 0.5 | ||
p_matrix[i,j] <- p | ||
} | ||
} | ||
p_matrix | ||
} | ||
|
||
# Define the formula to generate p matrix of graphon2 | ||
graphon2 <- function(u, size){ | ||
p_matrix = matrix(0,nrow=size,ncol=size) | ||
for(i in 1:size){ | ||
for(j in 1:size){ | ||
p <- cos(pi*(u[i]-u[j]))/(2^3) + 0.5 | ||
p_matrix[i,j] <- p | ||
} | ||
} | ||
p_matrix | ||
} | ||
|
||
# Define the formula to generate p matrix of graphon3 | ||
graphon3 <- function(u, size){ | ||
p_matrix = matrix(0,nrow=size,ncol=size) | ||
for(i in 1:size){ | ||
for(j in 1:size){ | ||
p <- cos(pi*(u[i]-u[j]))/(2^3) + 0.5 | ||
p_matrix[i,j] <- p | ||
} | ||
} | ||
p_matrix | ||
} | ||
# Define the formula to generate p matrix of graphon4 | ||
graphon4 <- function(u, size){ | ||
p_matrix = matrix(0,nrow=size,ncol=size) | ||
for(i in 1:size){ | ||
for(j in 1:size){ | ||
p <- cos(pi*(u[i]-u[j]))/(2^3) + 0.5 | ||
p_matrix[i,j] <- p | ||
} | ||
} | ||
p_matrix | ||
} | ||
|
||
# Define the formula to generate p matrix of graphon5 | ||
graphon5 <- function(u, size){ | ||
p_matrix = matrix(0,nrow=size,ncol=size) | ||
for(i in 1:size){ | ||
for(j in 1:size){ | ||
p <- cos(pi*(u[i]-u[j]))/(2^3) + 0.5 | ||
p_matrix[i,j] <- p | ||
} | ||
} | ||
p_matrix | ||
} | ||
|
||
# Define the formula to generate p matrix of graphon6 | ||
graphon6 <- function(u, size){ | ||
p_matrix = matrix(0,nrow=size,ncol=size) | ||
for(i in 1:size){ | ||
for(j in 1:size){ | ||
p <- cos(pi*(u[i]-u[j]))/(2^3) + 0.5 | ||
p_matrix[i,j] <- p | ||
} | ||
} | ||
p_matrix | ||
} | ||
|
||
# Function to generate sub-network from real network, labeled as 7 | ||
graphon7 <- function(u,size){ | ||
} | ||
|
||
|
||
# Function to generate sub-network from real network, labeled as 8 | ||
graphon8 <- function(u,size){ | ||
} | ||
|
||
|
||
#' Generate a Graphon Probability Matrix | ||
#' | ||
#' This function generates a graphon probability matrix based on a specified graphon type. | ||
#' Users can control the generation process through various parameters. | ||
#' | ||
#' @param size An integer specifying the size of the network. | ||
#' @param graph_num An integer (default is 1) indicating the graphon type to use. | ||
#' Acceptable values are from 1 to 6. | ||
#' @param sampling_on_u A logical value determining if uniform sampling should be used for 'u'. | ||
#' Defaults to TRUE. If FALSE, a regular sequence from 0 to 1 is used. | ||
#' @param u_input An optional numeric vector that provides specific values for 'u'. | ||
#' If NULL (default), 'u' is generated based on 'sampling_on_u'. | ||
#' | ||
#' @return A matrix of probabilities is returned. | ||
#' | ||
#' @examples | ||
#' # Generate a graphon probability matrix of size 100 using graphon setting 1 | ||
#' P = generate_graphon(100, 1) | ||
#' | ||
#' @export | ||
generate_graphon <- function(size, graph_num = 1,sampling_on_u=TRUE,u_input=NULL){ | ||
|
||
#handle user provided u | ||
if(!is.null(u_input)){u = u_input}else{ | ||
if(sampling_on_u){ | ||
u = stats::runif(n = size) | ||
}else{ | ||
u = seq(from = 0, to = 1,length.out=size) | ||
} | ||
} | ||
u = sort(u) | ||
# Use switch to select the graphon | ||
p_matrix <- switch(as.character(graph_num), | ||
"1" = graphon1(u, size), | ||
"2" = graphon2(u, size), | ||
"3" = graphon3(u, size), | ||
"4" = graphon4(u, size), | ||
"5" = graphon5(u, size), | ||
"6" = graphon6(u, size), | ||
stop("Invalid graph_num: should be between 1 and 6")) | ||
return(p_matrix) | ||
|
||
} | ||
|
||
#' Generate Network Adjacency Matrix from Probability Matrix | ||
#' | ||
#' This function generates a network adjacency matrix from a given probability matrix. | ||
#' It checks if the input is a valid probability matrix and can produce either a single | ||
#' network or multiple replicates. | ||
#' | ||
#' @param P A square matrix representing the probability matrix, where each element | ||
#' is a probability (between 0 and 1) of an edge between nodes. | ||
#' @param replicate An integer indicating the number of network replicates to generate. | ||
#' Defaults to 1. | ||
#' @param symmetric.out A logical value indicating whether the output matrix should be | ||
#' symmetric. Defaults to TRUE. | ||
#' @param noloop A logical value indicating whether to include self-loops in the network. | ||
#' Defaults to FALSE. | ||
#' | ||
#' @return If `replicate` is 1, returns a single adjacency matrix. If `replicate` is | ||
#' greater than 1, returns a list of adjacency matrices. Each matrix is a square | ||
#' binary matrix, where 1 indicates the presence of an edge and 0 indicates its absence. | ||
#' | ||
#' @examples | ||
#' P = generate_graphon(100, 1) | ||
#' network = generate_network_P(P, replicate = 1, symmetric.out = TRUE) | ||
#' | ||
#' @export | ||
generate_network_P = function(P, replicate = 1, symmetric.out=TRUE, noloop = FALSE){ | ||
## Check P | ||
cond1 = ((all(P>=0))&&(all(P<=1))) | ||
cond2 = (nrow(P)==ncol(P)) | ||
if (!(cond1&&cond2)){ | ||
stop("* gmodel.P : P is not a valid probability matrix.") | ||
} | ||
|
||
## Parameter | ||
n = nrow(P) | ||
|
||
## replicate 1 case | ||
if (replicate==1){ | ||
tmpmat = matrix(stats::runif(n^2),nrow=n) | ||
if (symmetric.out){ | ||
tmpmat[lower.tri(tmpmat)] <- t(tmpmat)[lower.tri(t(tmpmat))] | ||
} | ||
G = (tmpmat<P)*1 | ||
} else { | ||
G = list() | ||
for (i in 1:replicate){ | ||
tmpmat = matrix(stats::runif(n^2),nrow=n) | ||
if (symmetric.out){ | ||
tmpmat[lower.tri(tmpmat)] <- t(tmpmat)[lower.tri(t(tmpmat))] | ||
} | ||
tmpG = 1*(tmpmat<P) | ||
if (noloop){ | ||
diag(tmpG) = 0 | ||
} | ||
G[[i]] = tmpG | ||
} | ||
} | ||
## return output | ||
return(G) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#' localboot: A Package for Local Bootstrap Methods for Various Networks | ||
#' | ||
#' Network analysis usually requires estimating the uncertainty of | ||
#' a graph statistics. Through this package, we provides tools to bootstrap | ||
#' various networks via local bootstrap procedure. Additionally, it includes | ||
#' functions for generating probability matrices, creating network adjacency | ||
#' matrices from probability matrices, and plotting network structures. | ||
#' | ||
#' @name localboot-package | ||
#' @aliases localboot-package | ||
#' @docType package | ||
"_PACKAGE" |
Oops, something went wrong.