程序代写代做代考 —


title: “ERGM model”
author: “Robin Burke”
date: “10/15/2017”
output: html_document

“`{r setup, include=FALSE}
library(knitr)
#setwd(“/Users/robinburke/Box Sync/2017_cFall/csc495Bx/notes/w07”)
setwd(“C:\\Users\\rburke\\Box Sync\\2017_cFall\\csc495Bx\\notes\\w07”)
read_chunk(“ergm-model.R”)
knitr::opts_chunk$set(echo = TRUE)
“`

## ERGM Model

This example demonstrates the properties of the exponential random graph model with a very simple network.

“`{r C1, results=”hide”, warning=FALSE, message=FALSE}
“`

Create two simple networks of four nodes.

“`{r C2}

“`

“`{r C3}

“`

### Modeling density (edges term)

Convert to network and model using only edge count term. This means that the model has only one coefficient. For any given value of the parameter, we can compute the probability of a network with that edge count using the ERGM equation. We will do this below.

“`{r C4}

“`

Create a data frame with edge counts for all possible networks of these four nodes.

“`{r C5}

“`

Compute the scores for each possible network using theta (parameter) values from 0.1 to 0.9

“`{r C6}

“`

Add up all of the scores for networks with a given edge count 0 to 6.

“`{r C7}

“`

Normalize all of the columns by the total to get a probability — dividing by the total of all possible networks.

“`{r C8}

“`

Melt the data frame to make it ggplot compatible.

“`{r C9}

“`

Plot the percentages

“`{r C10}

“`

Examine the row for edges = 2

“`{r C11}

“`

Note that the actual learned parameter -0.69

Examine the row for edges = 3

“`{r C12}

“`

Note that the learned parameter was 0.0

### Modeling density and degree 2 count

Note that a more complex fitting process is required

“`{r C13}
“`

The deg2 vector is the number of degree 2 nodes in every possible configuration of the 4 nodes (64 networks). The calculation computes the probability of each possible network configuration given different ERGM parameters.

“`{r C14}
“`

Normalize so that we have percents.

“`{r C15}
“`
Group and summarize so that networks that have the same counts are together.

“`{r C16}
“`

Get rid of the columns we don’t need

“`{r C17}
“`

Plot 9 functions for different values of edge count and degree 2 count.

“`{r C18}
“`