Skip to content

Commit

Permalink
Adding the fundamentals to the website
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Jan 6, 2024
1 parent 64bd9b4 commit 5b0d7b2
Show file tree
Hide file tree
Showing 30 changed files with 4,917 additions and 144 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/.quarto/
*_cache
78 changes: 73 additions & 5 deletions 01-fundamentals/index.qmd
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
---
title: Fundamentals
bibliography: ../references.bib
---

Before jumping into network science details, we need to cover some fundamentals. I assume that most of the contents here are well known to you--we will be brief--but I want to ensure we are all on the same page.

# Programming with R

The R programming language is the defacto language for social network analysis[^notfornetsci]. Furthermore, R homes the most comprehensive collection of packages implementing the methods we will cover here. Let's start by the fundamentals
The R programming language [@R] is the defacto language for social network analysis[^notfornetsci]. Furthermore, R homes the most comprehensive collection of packages implementing the methods we will cover here. Let's start by the fundamentals

[^notfornetsci]: Although, not for network science in general.

## Getting help

Unlike other languages, R's documentation is highly reliable. The Comprehensive R Archive Network (CRAN) is the official repository of R packages. All packages posted on CRAN must pass a series of tests to ensure the quality of the code, including the documentation.
Unlike other languages, R's documentation is highly reliable. The Comprehensive R Archive Network [CRAN] is the official repository of R packages. All packages posted on CRAN must pass a series of tests to ensure the quality of the code, including the documentation.

To get help on a function, we can use the `help()` function. For example, if we wanted to get help on the `mean()` function, we would do:

Expand Down Expand Up @@ -49,7 +50,7 @@ my-var

## Assignment

In R we have two (four) ways of assigning values to objects: the `<-` and `=` binary operators[^binop]. Although both are equivalent, the former is the preferred way of assigning values to objects, since the latter can be confused with function arguments.
In R, we have two (four) ways of assigning values to objects: the `<-` and `=` binary operators[^binop]. Although both are equivalent, the former is the preferred way of assigning values to objects since the latter can be confused with function arguments.

[^binop]: In mathematics and computer science, a binary operator is a function that takes two arguments. In R, binary operators are implemented as `variable 1` `[operator]` `variable 2`. For example, `1 + 2` is a binary operation.

Expand Down Expand Up @@ -95,7 +96,7 @@ c(1, 2, 3) |> mean()

## Data structures

Atomic types are the minimal building blocks of R. They are: logical, integer, double, character, complex, raw:
Atomic types are the minimal building blocks of R. They are logical, integer, double, character, complex, raw:

```{r}
#| label: data-structures
Expand All @@ -109,6 +110,10 @@ x_raw <- charToRaw("a")

Unlike other languages, we do not need to declare the data type before creating the object; R will infer it from the value.

::: {.callout .callout-tip title="Pro-tip"}
Adding the `L` suffix to the value is good practice when dealing with integers. Some R packages like `data.table` [@datatable] have internal checks that will throw an error if you are not explicit about the data type.
:::

The next type is the vector. A vector is a collection of elements of the same type. The most common way to create a vector is with the `c()` function:

```{r}
Expand Down Expand Up @@ -255,9 +260,24 @@ repeat {
}
```

## R packages

R is so powerful because of its extensions. R extensions (different from other programming languages) are called packages. Packages are collections of functions, data, and documentation that provide additional functionality to R. Although anyone can create and distribute R packages to other users, the Comprehensive R Archive Network [CRAN] is the official repository of R packages. All packages posted on CRAN are thoroughly tested, so generally, their quality is high.

To install R packages, we use the `install.packages()` function; to load them, we use the `library()` function. For example, the following code chunk installs the `ergm` package and loads it:

```{r}
#| label: packages
#| collapse: true
#| eval: false
install.packages("ergm")
library(ergm)
```


# Statistics

Generally, statistics are used for two purposes: to describe and to infer. We observe data samples in descriptive statistics, recording and reporting the mean, median, and standard deviation, among other statistics. Statistical inference, on the other hand, is used to infer the properties of a population from a sample.
Generally, statistics are used for two purposes: to describe and to infer. We observe data samples in descriptive statistics, recording and reporting the mean, median, and standard deviation, among other statistics. Statistical inference, on the other hand, is used to infer the properties of a population from a sample, particularly, about population parameters.

![Grad view of statistics -- Reproduced from @BasicDefinitionsConcepts2014](grand-view-stats.jpg){width=70%}

Expand Down Expand Up @@ -332,6 +352,54 @@ rbinom(1000, size = 10, prob = 0.1) |> hist(main = "Binomial distribution")
par(op)
```

## Simulations and sampling

Simulations are front and center in statistical programming. We can use them to test the properties of statistical methods, generate data, and perform statistical inference. The following example uses the sample function in R to compute the bootstrap standard error of the mean:

```{r}
#| label: simulations
#| collapse: true
set.seed(1)
x <- rnorm(1000)
# Bootstrap standard error of the mean
n <- length(x)
B <- 1000
# We will store the results in a vector
res <- numeric(B)
for (i in 1:B) {
# Sample with replacement
res[i] <- sample(x, size = n, replace = TRUE) |>
mean()
}
# Plot the results
hist(res, main = "Bootstrap standard error of the mean")
```

Since the previous example is rather extensive, let us review it in detail.

- `set.seed(1)` sets the seed of the PRNG to 1. It ensures we get the same results every time we run the code.

- `rnorm()` generates a sample of 1,000 standard-normal values.

- `n <- length(x)` stores the length of the vector in the `n` variable.

- `B <- 1000` stores the number of bootstrap samples in the `B` variable.

- `res <- numeric(B)` creates a vector of length `B` to store the results.

- `for (i in 1:B)` is a for loop that iterates from 1 to `B`.

- `res[i] <- sample(x, size = n, replace = TRUE) |> mean()` samples `n` values from `x` with replacement and computes the mean of the sample.

- The pipe operator (`|>`) passes the output of the left-hand side expression as the first argument of the right-hand side expression.

- `hist(res, main = "Bootstrap standard error of the mean")` plots the histogram of the results.




# References
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ website:
href: index.qmd
- text: Overview
href: 00-overview/index.qmd
- text: Fundamentals
href: 01-fundamentals/index.qmd
- text: Random graphs
href: 01-random-graphs/index.qmd
href: 02-random-graphs/index.qmd
- text: Behavior and coevolution
href: 02-behavior-and-coevolution/index.qmd
href: 03-behavior-and-coevolution/index.qmd

format:
html:
Expand Down
8 changes: 6 additions & 2 deletions docs/00-overview/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4496,11 +4496,15 @@
<span class="menu-text">Overview</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="../01-random-graphs/index.html" rel target>
<a class="nav-link" href="../01-fundamentals/index.html" rel target>
<span class="menu-text">Fundamentals</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="../02-random-graphs/index.html" rel target>
<span class="menu-text">Random graphs</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="../02-behavior-and-coevolution/index.html" rel target>
<a class="nav-link" href="../03-behavior-and-coevolution/index.html" rel target>
<span class="menu-text">Behavior and coevolution</span></a>
</li>
</ul>
Expand Down
117 changes: 95 additions & 22 deletions docs/01-fundamentals/index.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4511,11 +4511,15 @@
<span class="menu-text">Overview</span></a>
</li>
<li class="nav-item">
<a class="nav-link active" href="../01-random-graphs/index.html" rel target aria-current="page">
<a class="nav-link" href="../01-fundamentals/index.html" rel target>
<span class="menu-text">Fundamentals</span></a>
</li>
<li class="nav-item">
<a class="nav-link active" href="../02-random-graphs/index.html" rel target aria-current="page">
<span class="menu-text">Random graphs</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="../02-behavior-and-coevolution/index.html" rel target>
<a class="nav-link" href="../03-behavior-and-coevolution/index.html" rel target>
<span class="menu-text">Behavior and coevolution</span></a>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4530,11 +4530,15 @@
<span class="menu-text">Overview</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="../01-random-graphs/index.html" rel target>
<a class="nav-link" href="../01-fundamentals/index.html" rel target>
<span class="menu-text">Fundamentals</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="../02-random-graphs/index.html" rel target>
<span class="menu-text">Random graphs</span></a>
</li>
<li class="nav-item">
<a class="nav-link active" href="../02-behavior-and-coevolution/index.html" rel target aria-current="page">
<a class="nav-link active" href="../03-behavior-and-coevolution/index.html" rel target aria-current="page">
<span class="menu-text">Behavior and coevolution</span></a>
</li>
</ul>
Expand Down
17 changes: 15 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4464,11 +4464,15 @@
<span class="menu-text">Overview</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="./01-random-graphs/index.html" rel target>
<a class="nav-link" href="./01-fundamentals/index.html" rel target>
<span class="menu-text">Fundamentals</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="./02-random-graphs/index.html" rel target>
<span class="menu-text">Random graphs</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="./02-behavior-and-coevolution/index.html" rel target>
<a class="nav-link" href="./03-behavior-and-coevolution/index.html" rel target>
<span class="menu-text">Behavior and coevolution</span></a>
</li>
</ul>
Expand Down Expand Up @@ -4531,6 +4535,9 @@ <h2 data-number="1" class="anchored" data-anchor-id="introduction"><span class="
<section id="references" class="level2" data-number="2">
<h2 data-number="2" class="anchored" data-anchor-id="references"><span class="header-section-number">2</span> References</h2>
<div id="refs" class="references csl-bib-body hanging-indent" role="list">
<div id="ref-BasicDefinitionsConcepts2014" class="csl-entry" role="listitem">
<span>“1.1: <span>Basic Definitions</span> and <span>Concepts</span>.”</span> 2014. <em>Statistics LibreTexts</em>. https://stats.libretexts.org/Bookshelves/Introductory_Statistics/Introductory_Statistics_(Shafer_and_Zhang)/01%3A_Introduction_to_Statistics/1.01%3A_Basic_Definitions_and_Concepts.
</div>
<div id="ref-bellSensingEatingMimicry2019" class="csl-entry" role="listitem">
Bell, Brooke M., Donna Spruijt-Metz, George G. Vega Yon, Abu S. Mondol, Ridwan Alam, Meiyi Ma, Ifat Emi, John Lach, John A. Stankovic, and Kayla De La Haye. 2019. <span>“Sensing Eating Mimicry Among Family Members.”</span> <em>Translational Behavioral Medicine</em>. <a href="https://doi.org/10.1093/tbm/ibz051">https://doi.org/10.1093/tbm/ibz051</a>.
</div>
Expand All @@ -4540,6 +4547,12 @@ <h2 data-number="2" class="anchored" data-anchor-id="references"><span class="he
<div id="ref-ernmsFellows2023" class="csl-entry" role="listitem">
Fellows, Ian E. 2012. <span>“Exponential Family Random Network Models.”</span> <em>ProQuest Dissertations and Theses</em>. PhD thesis. <a href="https://login.ezproxy.lib.utah.edu/login?url=https://www.proquest.com/dissertations-theses/exponential-family-random-network-models/docview/1221548720/se-2">https://login.ezproxy.lib.utah.edu/login?url=https://www.proquest.com/dissertations-theses/exponential-family-random-network-models/docview/1221548720/se-2</a>.
</div>
<div id="ref-gelmanFailureNullHypothesis2018" class="csl-entry" role="listitem">
Gelman, Andrew. 2018. <span>“The <span>Failure</span> of <span>Null Hypothesis Significance Testing When Studying Incremental Changes</span>, and <span>What</span> to <span>Do About It</span>.”</span> <em>Personality and Social Psychology Bulletin</em> 44 (1): 16–23. <a href="https://doi.org/10.1177/0146167217729162">https://doi.org/10.1177/0146167217729162</a>.
</div>
<div id="ref-greenlandStatisticalTestsValues2016" class="csl-entry" role="listitem">
Greenland, Sander, Stephen J. Senn, Kenneth J. Rothman, John B. Carlin, Charles Poole, Steven N. Goodman, and Douglas G. Altman. 2016. <span>“Statistical Tests, <span>P</span> Values, Confidence Intervals, and Power: A Guide to Misinterpretations.”</span> <em>European Journal of Epidemiology</em> 31 (4): 337–50. <a href="https://doi.org/10.1007/s10654-016-0149-3">https://doi.org/10.1007/s10654-016-0149-3</a>.
</div>
<div id="ref-Handcock2023" class="csl-entry" role="listitem">
Handcock, Mark S., David R. Hunter, Carter T. Butts, Steven M. Goodreau, Pavel N. Krivitsky, and Martina Morris. 2023. <em>Ergm: Fit, Simulate and Diagnose Exponential-Family Models for Networks</em>. The Statnet Project (<a href="https://statnet.org" class="uri">https://statnet.org</a>). <a href="https://CRAN.R-project.org/package=ergm">https://CRAN.R-project.org/package=ergm</a>.
</div>
Expand Down
Loading

0 comments on commit 5b0d7b2

Please sign in to comment.