Skip to content

Commit 297b6f8

Browse files
committed
Adding the theory section
1 parent 89a1eee commit 297b6f8

File tree

6 files changed

+453
-140
lines changed

6 files changed

+453
-140
lines changed

_quarto.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ website:
1717
href: getstarted.qmd
1818
- text: Diffusion Theory
1919
href: theory.qmd
20-
- text: Introduction
21-
href: intro.qmd
20+
- text: The netdiffuseR package
21+
href: netdiffuser.qmd
2222
- text: Simulations
2323
href: sim.qmd
2424
- text: Reading data

index.qmd

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ Workshop materials can be downloaded from https://github.com/USCCANA/netdiffuser
1515

1616
Source code per section:
1717

18-
1. <a href="Network Interventions INSNA updated.ppt" target="_blank">Presentation</a>
19-
2. <a href="https://raw.githubusercontent.com/USCCANA/netdiffuser-sunbelt2018/sunbelt2019/getstarted.Rmd" target="_blank">Getting started</a>
20-
3. <a href="https://raw.githubusercontent.com/USCCANA/netdiffuser-sunbelt2018/sunbelt2019/intro.Rmd" target="_blank">Introduction</a>
21-
4. <a href="https://raw.githubusercontent.com/USCCANA/netdiffuser-sunbelt2018/sunbelt2019/sim.Rmd" target="_blank">Simulations</a>
22-
5. <a href="https://raw.githubusercontent.com/USCCANA/netdiffuser-sunbelt2018/sunbelt2019/stats.Rmd" target="_blank">Statistical inference</a>
23-
5. <a href="https://raw.githubusercontent.com/USCCANA/netdiffuser-sunbelt2018/sunbelt2019/classic.Rmd" target="_blank">Classic Diffnet Analyses</a>
18+
1. [Getting started](getstarted.qmd) (optional)
19+
2. [Diffusion Theory](theory.qmd)
20+
3. [The netdiffuseR package](netdiffuser.qmd)
21+
4. [Simulations](sim.qmd)
22+
5. [Reading data](read.qmd)
23+
6. [Statistical inference](stats.qmd)
2424

2525
From the description:
2626

intro.qmd

-132
This file was deleted.

intro.rda

5 Bytes
Binary file not shown.

netdiffuser.qmd

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
---
2+
title: "Introduction to the package"
3+
author: "George G. Vega Yon"
4+
date: "2024-12-05"
5+
date-modified: "2024-12-05"
6+
---
7+
8+
```{r setup, echo=FALSE, message=FALSE, warning=FALSE}
9+
library(netdiffuseR)
10+
knitr::opts_chunk$set(comment = "#")
11+
```
12+
13+
14+
* One of the cannonical concepts is the **network threshold**. Network thresholds (Valente, 1995; 1996), $\tau$, are defined as the required proportion or number of neighbors that leads you to adopt a particular behavior (innovation), $a=1$. In (very) general terms\pause
15+
16+
$$
17+
a_i = \left\{\begin{array}{ll}
18+
1 &\mbox{if } \tau_i\leq E_i \\
19+
0 & \mbox{Otherwise}
20+
\end{array}\right. \qquad
21+
E_i \equiv \frac{\sum_{j\neq i}\mathbf{X}_{ij}a_j}{\sum_{j\neq i}\mathbf{X}_{ij}}
22+
$$
23+
24+
Where $E_i$ is i's exposure to the innovation and $\mathbf{X}$ is the adjacency matrix (the network).
25+
26+
* This can be generalized and extended to include covariates and other network weighting schemes (that's what __netdiffuseR__ is all about).
27+
28+
# netdiffuseR
29+
30+
## Overview
31+
32+
__netdiffuseR__ is an R package that:
33+
34+
* Is designed for Visualizing, Analyzing and Simulating network diffusion data (in general).
35+
36+
* Depends on some pretty popular packages:
37+
38+
* _RcppArmadillo_: So it's fast,
39+
* _Matrix_: So it's big,
40+
* _statnet_ and _igraph_: So it's not from scratch
41+
42+
* Can handle big graphs, e.g., an adjacency matrix with more than 4 billion elements (PR for RcppArmadillo)
43+
44+
* Already on CRAN with ~6,000 downloads since its first version, Feb 2016,
45+
46+
* A lot of features to make it easy to read network (dynamic) data, making it a nice companion of other net packages.
47+
48+
49+
## Datasets
50+
51+
- __netdiffuseR__ has the three classic Diffusion Network Datasets:
52+
53+
- `medInnovationsDiffNet` Doctors and the innovation of Tetracycline (1955).
54+
- `brfarmersDiffNet` Brazilian farmers and the innovation of Hybrid Corn Seed (1966).
55+
- `kfamilyDiffNet` Korean women and Family Planning methods (1973).
56+
57+
```{r printing}
58+
brfarmersDiffNet
59+
medInnovationsDiffNet
60+
kfamilyDiffNet
61+
```
62+
63+
## Visualization methods
64+
65+
```{r viz, cache=TRUE, eval=TRUE}
66+
set.seed(12315)
67+
x <- rdiffnet(
68+
n = 400, t = 6,
69+
rgraph.args = list(k=6, p=.3),
70+
seed.graph = "small-world",
71+
seed.nodes = "central",
72+
rewire = FALSE,
73+
threshold.dist = 1/4
74+
)
75+
x
76+
```
77+
78+
Diffusion networks can visualized using many methods included in the package. Here are some of them:
79+
80+
81+
```{r}
82+
#| label: plot-methods
83+
plot(x)
84+
plot_diffnet(x)
85+
plot_diffnet2(x)
86+
plot_adopters(x)
87+
plot_threshold(x)
88+
plot_infectsuscep(x, K=2)
89+
plot_hazard(x)
90+
```
91+
92+
93+
# Problems
94+
95+
1. Using the diffnet object in [`intro.rda`](intro.rda), use the function `plot_threshold` specifying shapes and colors according to the variables ItrustMyFriends and Age. Do you see any pattern? (<a href="intro-solutions.r" target="_blank">solution script</a> and <a href="intro-solutions.png" target="_blank">solution plot</a>)
96+
97+
```{r datasim, echo=FALSE, eval=TRUE}
98+
set.seed(1252)
99+
dat <- data.frame(
100+
ItrustMyFriends = sample(c(0,1), 200, TRUE),
101+
Age = 10 + rpois(200, 4)
102+
)
103+
net <- rgraph_er(200, p = .05)
104+
# net <- diag_expand(list(net, net))
105+
# net[cbind(1:20, 101:120)] <- 1
106+
107+
# Generating the process
108+
diffnet <- rdiffnet(
109+
threshold.dist = 4 - dat$ItrustMyFriends*3,
110+
seed.graph = net,
111+
t=6,
112+
seed.nodes = c(9:25),
113+
exposure.args = list(normalized=FALSE),
114+
rewire = FALSE)
115+
116+
diffnet[["ItrustMyFriends"]] <- dat$ItrustMyFriends
117+
diffnet[["Age"]] <- dat$Age
118+
119+
save(diffnet, file = "intro.rda")
120+
```
121+
122+

0 commit comments

Comments
 (0)