## R Functions

Below are several R functions that I have programmed. I have found these very useful.

**Sensitivity Analysis for Latent Homophily**Studies of social influence often estimate the effect of peers by regressing some outcome of interest (e.g. delinquency) on a measure of peer behavior (e.g. average peer delinquency in the network). However,

*latent homophily*, an unmeasured factor which influences friendship selection and some outcome of interest, can create artificial statistical dependence between an outcome of interest for two individuals in the absence of any causal relationship (Shalizi and Thomas 2011). This program examines the sensitivity of estimates from a regression model of some outcome on a directly measured outcome of peers. VanderWeele and Arah (2011) and VanderWeele (2011) have developed a means to examine the sensitivity of an estimate to latent homophily. Basically, the approach examines the hypothetical conditions under which the effect of social influence would be explained by latent homophily.

The syntax below provides the sensitivity analyses conducted by Young (2014) on two prominent studies of peer delinquency and social influence (i.e. Haynie 2001; Meldrum, Young, and Weerman 2009).

sensitivity_analysis_haynie_2001_syntax.r |

sensitivity_analysis_meldrum_2009_syntax.r |

**Roster to Adjacency**This function takes network data in roster format and creates an adjacency matrix from the data.

roster.to.adjacency.r |

**Egocentric Stats**These functions take an adjacency matrix and a variable and creates the egocentric means and standard deviation for the variable. The functions require the adjacency matrix ("adj") and a variable ("var"). There are three types of networks to call: send, receive, and send and receive. So, there are six functions (3 for mean, 3 for sd). The end of the function gives an example of how this works.

egocentric.stats.r |