Skip to content

Commit

Permalink
version 0.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
zzz1990771 authored and cran-robot committed Jan 11, 2024
1 parent 0423782 commit fefe0b4
Show file tree
Hide file tree
Showing 15 changed files with 609 additions and 382 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: localboot
Type: Package
Title: Local Bootstrap Methods for Various Networks
Version: 0.9.1
Date: 2023-12-18
Version: 0.9.2
Date: 2024-01-08
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"))
Expand All @@ -21,9 +21,9 @@ LinkingTo: Rcpp (>= 1.0.11), RcppEigen
Encoding: UTF-8
RoxygenNote: 7.2.3
NeedsCompilation: yes
Packaged: 2023-12-21 06:21:26 UTC; tianhaizu
Packaged: 2024-01-09 23:36:45 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
Date/Publication: 2024-01-10 11:33:21 UTC
22 changes: 13 additions & 9 deletions MD5
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
b3ff1e6fb2563796e33807e5fb5277e1 *DESCRIPTION
a947509da42eac0e8ca8cad900e25ede *DESCRIPTION
34b2759e632634bd546f0f996c90462d *NAMESPACE
c2e388d5404970730871cb513d70b668 *NEWS.md
2de21dbbe9981853ed8044136e4bfac7 *R/RcppExports.R
3f12e430a5c85fc62a93fa4a46566c42 *R/generate_network.R
faec646538a6580729f9787c8a2e238f *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
b35837be1bcc3a6f0fcdf6c82b39d056 *README.md
59af8258a14eb1539b9bef66a61ee019 *inst/rds/email_Eu_core_adj.RDS
a215b98595c9f13cbf8c97ee1b351cdd *inst/rds/rattus_norvegicus_brain_3_adj.RDS
2cd7d660e71005f6248b683fab854f8f *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
5e01e394a9b195b58347a409a1a8afec *inst/sim/Optimal_local_size.R
54176d96b0c35fdcd3bbaa251c121c02 *inst/sim/Sim1_estimate_others.R
2640bffdcfbecf49fd8cb732fcaac6b6 *inst/sim/Sim1_estimates_local.R
f1b36c42327c09ed28aded29e4338aec *inst/sim/Sim1_truese.R
c66d0b124086ce00b9a3454de557ee50 *inst/sim/sup_funcs_sim.R
c6bd637748ae88df554ced68e6771e5f *man/generate_graphon.Rd
d4a8f4bc1d08552a82ce03853a80b001 *man/generate_network_P.Rd
29713984eab34fbaf668b7aeb31a0947 *man/localboot-package.Rd
Expand All @@ -21,4 +25,4 @@ d4a8f4bc1d08552a82ce03853a80b001 *man/generate_network_P.Rd
b4f0b014ec53404e843dbc718fabf57e *src/Makevars
b4f0b014ec53404e843dbc718fabf57e *src/Makevars.win
60ca2ca032d1a414ce63a92635ac1453 *src/RcppExports.cpp
7fb7f7de7cc0aa9792b3ae46a8f87cde *src/localboot.cpp
fc267719bb49cff524fa60eca14e7116 *src/localboot.cpp
15 changes: 15 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# localboot 0.9.2 (12/29/2023)

## New Features
- Added new simulation scenarios.
- Expanded `generate_graphon()` with more network types.
- Added simulation scripts in `inst` folder.

## Improvements
- Updated documentation with examples for new features.
- Optimized performance and improved error handling.

## Installation
```R
install.packages("localboot")
```
46 changes: 34 additions & 12 deletions R/generate_network.R
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
# Define the formula to generate p matrix of graphon1
graphon1 <- function(u, size){
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 <- sin(((u[i]^2+u[j]^2)^(1/4))*0.01)/2 +0.5
p_matrix[i,j] <- p
}
}
p_matrix
}

# Define the formula to generate p matrix of graphon2
graphon2 <- function(u, size){
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 <- sin(((u[i]^2+u[j]^2)^(1/4))*10)/2 +0.5
p_matrix[i,j] <- p
}
}
p_matrix
}

# Define the formula to generate p matrix of graphon3
graphon3 <- function(u, size){
graphon1 <- function(u, size){
p_matrix = matrix(0,nrow=size,ncol=size)
for(i in 1:size){
for(j in 1:size){
Expand All @@ -38,44 +38,64 @@ 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 <- cos(pi*(u[i]-u[j]))/(2) + 0.5
p_matrix[i,j] <- p
}
}
p_matrix
}

# Define the formula to generate p matrix of graphon5
graphon5 <- function(u, size){
graphon2 <- function(u, size){
p_matrix = matrix(0,nrow=size,ncol=size)
s = 8
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
if(u[i]>=u[j]){
p = sin((s*u[i]-s/2)*sin(s*u[j]-s/2))
}else{
p = sin((s*u[j]-s/2)*sin(s*u[i]-s/2))
}
p_matrix[i,j] <- (p+1)/2
}
}
p_matrix
}

# Define the formula to generate p matrix of graphon6
graphon6 <- function(u, size){
graphon5 <- function(u, size){
p_matrix = matrix(0,nrow=size,ncol=size)
s = 10
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
if(u[i]>=u[j]){
p = sin((s*u[i]-s/2)*sin(s*u[j]-s/2))
}else{
p = sin((s*u[j]-s/2)*sin(s*u[i]-s/2))
}
p_matrix[i,j] <- (p+1)/2
}
}
p_matrix
}

# Function to generate sub-network from real network, labeled as 7
graphon7 <- function(u,size){
#read real data
RDS_path <- system.file("rds", "rattus_norvegicus_brain_3_adj.RDS", package = "localboot")
P <- readRDS(RDS_path)
node_samples <- sample(1:NROW(P),size,replace = TRUE)
P[node_samples,node_samples]
}


# Function to generate sub-network from real network, labeled as 8
graphon8 <- function(u,size){
#read real data
RDS_path <- system.file("rds", "email_Eu_core_adj.RDS", package = "localboot")
P <- readRDS(RDS_path)
node_samples <- sample(1:NROW(P),size,replace = TRUE)
P[node_samples,node_samples]
}


Expand Down Expand Up @@ -118,6 +138,8 @@ generate_graphon <- function(size, graph_num = 1,sampling_on_u=TRUE,u_input=NULL
"4" = graphon4(u, size),
"5" = graphon5(u, size),
"6" = graphon6(u, size),
"7" = graphon7(u, size),
"8" = graphon8(u, size),
stop("Invalid graph_num: should be between 1 and 6"))
return(p_matrix)

Expand Down
86 changes: 86 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# localboot

## Overview

`localboot` is an R package that offers tools for bootstrapping various networks through a local bootstrap procedure. It's particularly useful in network analysis for estimating the uncertainty of graph statistics. The package also includes utility functions that generating probability matrices, creating network adjacency matrices, and plotting network.

## Installation

To install the latest version of `localboot` from CRAN:

```R
install.packages("localboot")
```

To install the development version from GitHub:

```R
# install.packages("devtools")
devtools::install_github("zzz1990771/localboot")
```

## Features

- Local bootstrap methods for network analysis.
- Tools for generating probability matrices and network adjacency matrices.
- Functions for plotting network structures.
- Several simulation scripts included in the `inst\sim` folder for advanced analysis.

## Usage

After installing the `localboot` package, you can load it into your R session:

```R
library(localboot)
?localboot
```

Example usage:

```R
# Example usage
P = generate_graphon(100, 1)
A = generate_network_P(P, replicate = 1, symmetric.out = TRUE)
result <- localboot(A = A, B = 100, returns = "boot")
```

### Included Simulation Scripts

The localboot package comes with several simulation scripts located in the `inst\sim` folder. These scripts can be loaded and used for various simulations and analyses:

- `Fit_local_boot.R`: Demonstrates the application of local bootstrap procedures to networks. It generates random networks by `generate_graphon()` and `generate_network_P()` and fit local boostrap procedures on it using the main function `localboot()`.

- `Generate_various_networks.R`: Generates a variety of synthetic networks for testing network analysis algorithms.

- `Sim1_truese.R`: Obtains true simulated standard errors for graph statistics in various network simulations.

- `Sim1_estimates_local.R`: Generates various simulated networks and obtains estimated standard errors for different graph statistics by applying local bootstrap procedure.

- `Sim1_estimate_others.R`: Generates various simulated networks and obtains estimated standard errors for different graph statistics by applying other alternative procedures.

- `sup_funcs_sim.R`: Support functions for simulations in `Sim1_estimate_others.R`.

- `Optimal_local_size.R`: Generates plots to visualize the optimal neighbor set size of local bootstrap procedure for standard error estimation in relation to the number of blocks (K) in a Stochastic Block Model (SBM).


To load a script, use the `system.file()` function to find its path and then load it with `file.edit()`. For example:

```R
scriptPath <- system.file("sim/Generate_various_networks.R", package = "localboot")
file.edit(scriptPath)
```

## Results from Paper XXX

This package, along with the scripts `Sim1_truese.R`, `Sim1_estimates_local.R`, and `Sim1_estimate_others.R`, can be used to replicate the results presented in Paper XXX. Detailed instructions and data required for replication are provided within each script, ensuring a comprehensive understanding of the proposed local boostrap procedure.


## License

This package is free and open source software, licensed under GPL-3.

## Authors

-Tianhai Zu (zuti@mail.uc.edu)

-Yichen Qin (qinyn@ucmail.uc.edu)
Binary file added inst/rds/email_Eu_core_adj.RDS
Binary file not shown.
Binary file added inst/rds/rattus_norvegicus_brain_3_adj.RDS
Binary file not shown.
18 changes: 3 additions & 15 deletions inst/sim/Fit_local_boot.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,9 @@

# Library Imports
library(igraph)
#library(localboot) #currently commented out
library(localboot)
library(ggplot2)

#temp source, will be deleted after the package is finished.
source("./R/generate_network.R")
source("./R/localboot.R")
source("./R/plot_utils.R")

# -------------------------------------------------------------------
# Script Starts Here
# -------------------------------------------------------------------
Expand All @@ -42,7 +37,7 @@ source("./R/plot_utils.R")
n = 400

# Generate network adjacency matrix
P <- graphon3(size = n)
P <- generate_graphon(n,1)
adj.matrix <- generate_network_P(P)

# Let's assume we are investigating:
Expand All @@ -59,12 +54,5 @@ getT <- function(adj.matrix){
getT(adj.matrix)

# Use local bootstrap to estimate standard error of certain graph statistics
local_boot_res = local_boot(adj.matrix,0.1,100,returns = "T",fast=1)
local_boot_res = localboot(adj.matrix,200,returns = "T",getT=getT)
local_boot_res$se #should be around 0.003 to 0.0036.

local_boot_old(adj.matrix,0.1,100,returns = "T",fast=1)$se


system.time(local_boot(adj.matrix,0.1,100,fast=1))

system.time(local_boot_old(adj.matrix,0.1,100,fast=1))
4 changes: 2 additions & 2 deletions inst/sim/Optimal_local_size.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
#
# Author: Tianhai Zu
# Affiliation: University of Texas at San Antonio
# Created on: 12/05/2023
# Created on: 01/08/2024
#
# Requirements:
# The script requires the following R packages:
# - igraph (for basic network generation and manipulation)
# - [Any other packages needed for specific models or patterns]
# - localboot (this package)
# Install these packages using install.packages() if not already installed.

# Library Imports
Expand Down

0 comments on commit fefe0b4

Please sign in to comment.