Uses of this package

persnet is a survey instrument to collect ego-net data from the Personal Network Survey for Clinical Research instrument. This R package automates the analysis of those data. Two important references on the development of this instrument:

For more information on the instrument: https://redcap.partners.org/redcap/surveys/?s=8X4N3J7LY4

Installing the package

This package requires the following versions of R and other packages:

The package must be installed from Github using the devtools package. This can be done by executing this code:

#install.packages("tidygraph")
#install.packages("igraph")
#install.packages("dplyr")
#install.packages("ggraph")
#install.packages('devtools')
devtools::install_github("https://github.com/zwehrwein/persnet",force = TRUE)
## Downloading GitHub repo zwehrwein/persnet@HEAD

The package itself comes with a fake dataset (‘fd_df’), which we can use to explore the package’s functions.

Importance of the default variable names

library(persnet)
df_example <- persnet::fd_df
skimr::skim(df_example)
colnames(df_example)

The package works off of the default names of variables in the instrument. If you have modified those names, then you must change them back to the default name. We recommend using tidyverse’s rename_with command to do so, but so long as the variable names match, then the package will work as intended.

Network descriptives

The first important command (net_desc_pnd) will organize a persnet dataframe. It takes in a tibble dataframe and outputs tibble dataframe.

desc_df <- net_desc_pnd(df_example)
desc_df
## # A tibble: 3 × 9
##   record_id alter_count edges density net_cons…¹ net_e…² max_d…³ min_d…⁴ avg_p…⁵
##       <int>       <int> <dbl>   <dbl>      <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
## 1         1           4     8   0.667      0.612    2.79       3       1    1.6 
## 2         2          14    41   0.689      0.355    5.82       8       5    1.51
## 3         3           4     8   0.667      0.633    2.5        2       2    1.4 
## # … with abbreviated variable names ¹​net_constraint, ²​net_effect_size,
## #   ³​max_degree, ⁴​min_degree, ⁵​avg_path_length

The output tibble contains the following information:

  1. \(record\_id\) which is the same as the REDcap_id.
  2. \(alter\_count\) which is the total number of unique names (specifically unique strings) the observation reported, including both in the name1:name15 personal matters name generator questions and the more_names_1:more_names_3 questions.
  3. \(edges\) refers to the total number of ties within observation’s egonet.
  4. \(density\) is the ratio of ties actually realized over total possible ties. A score of 1 indicates that every person is tied to every other person while a score of 0 indicates that no ties are present in the network.
  5. \(net\_constraint\) is a measure developed first by Burt (1992) to measure the extent to which an ego’s alters are connected with each other. Constraint increases as a function of density and hierarchical network structures and decreases as a function of additional ties. A useful reference:
  1. \(net\_effect\_size\) The effective network size is the number of alters that the ego has, less the mean number of ties that each alter has to the other alters. It is, like network constraint, a measure of sources of novel information for the ego.
  2. \(max\_degree\) is the maximum number of ties that any node in the ego-net has.
  3. \(min\_degree\) is the minimum number of ties that any node in the ego-net has.
  4. \(avg\_path\_length\) The average path length is the number of geodesic steps it takes to `travel’ from the most distant node to the other.

Visualizing the egonets

The command organize_pnd takes in a tibble dataframe and outputs a list of igraph graph objects. These graph objects can in turn be subselected by their index in the list.

tgra <- organize_pnd(df_example)
tgra
## [[1]]
## IGRAPH 46d32f4 UNW- 5 8 -- 
## + attr: redcap_id (g/n), name (v/c), node_id (v/c), alter_dummy (v/n),
## | weight (e/n)
## + edges from 46d32f4 (vertex names):
## [1] EGO --ALT1  EGO --ALT2  EGO --ALT8  EGO --ALT11 ALT1--ALT2  ALT1--ALT8 
## [7] ALT1--ALT11 ALT2--ALT8 
## 
## [[2]]
## IGRAPH 6440694 UNW- 11 41 -- 
## + attr: redcap_id (g/n), name (v/c), node_id (v/c), alter_dummy (v/n),
## | weight (e/n)
## + edges from 6440694 (vertex names):
##  [1] EGO --ALT1  EGO --ALT2  EGO --ALT3  EGO --ALT4  EGO --ALT5  EGO --ALT6 
##  [7] EGO --ALT7  EGO --ALT8  EGO --ALT9  EGO --ALT10 ALT1--ALT2  ALT1--ALT4 
## [13] ALT1--ALT5  ALT1--ALT6  ALT1--ALT8  ALT1--ALT9  ALT1--ALT10 ALT2--ALT4 
## [19] ALT2--ALT5  ALT2--ALT6  ALT2--ALT7  ALT2--ALT8  ALT2--ALT10 ALT3--ALT4 
## [25] ALT3--ALT6  ALT3--ALT7  ALT3--ALT9  ALT3--ALT10 ALT4--ALT5  ALT4--ALT6 
## [31] ALT4--ALT7  ALT4--ALT8  ALT5--ALT6  ALT5--ALT9  ALT6--ALT7  ALT6--ALT8 
## [37] ALT6--ALT9  ALT7--ALT8  ALT8--ALT9  ALT8--ALT10 ALT9--ALT10
## 
## [[3]]
## IGRAPH 771988e UNW- 5 8 -- 
## + attr: redcap_id (g/n), name (v/c), node_id (v/c), alter_dummy (v/n),
## | weight (e/n)
## + edges from 771988e (vertex names):
## [1] EGO --ALT1  EGO --ALT2  EGO --ALT3  EGO --ALT11 ALT1--ALT2  ALT1--ALT11
## [7] ALT2--ALT3  ALT3--ALT11
#tgra[[2]]

The command viz_single_pnd visualizes a single persnet ego-net. It takes in an igraph object and returns a ggplot (n.b. the output of organize_pnd is a list of lists, so the double bracket selector [[]] must be used).

viz_single_pnd(tgra[[2]])

The command viz_grid_pnd visualizes all of the egonets. This command takes in a list of a list of igraph objects and returns a ggplot plot that can be modified. For clarity’s sake, the \(record\_id\) is not shown, but the plots are ordered according to \(record\_id\).

viz_grid_pnd(tgra)

We can save this output using the ggsave command, which will place a .png in the working directory of the plot.

ggsave(viz_grid_pnd(tgra),
       file="fd_netviz_grid.png",
       width = 12, height = 6)

Alter composition descriptives

Finally, alter_desc_pnd takes in a persnet dataframe and returns summary descriptives of the ego’s alters. The output is a tibble. The persnet package computes simple proportions, but there are many other ways to analyze and represent these data. Additional code that can be publicly modified that works with persnet data is available at: https://github.com/AmarDhand/PersonalNetworks

alter_desc_pnd(df_example)
## # A tibble: 3 × 20
##   redcap_id alter_supp…¹ alter…² suppo…³ suppo…⁴ suppo…⁵ suppo…⁶ suppo…⁷ gende…⁸
##       <int>        <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
## 1         1            1     0      0.13    0.13    0.07    0       0.07     0.5
## 2         2            1     0.7    0.07    0.2     0.2     0.07    0.07     0.8
## 3         3            1   NaN      0       0.07    0.2     0       0      NaN  
## # … with 11 more variables: race_white_per <dbl>, edu_hs_per <dbl>,
## #   relation_spouse_per <dbl>, relation_family_per <dbl>,
## #   relation_friend_per <dbl>, relation_advice_per <dbl>,
## #   relat_coworker_per <dbl>, relat_other_per <dbl>, less15miles_per <dbl>,
## #   fewer6years_per <dbl>, speakweekly_per <dbl>, and abbreviated variable
## #   names ¹​alter_support_per, ²​alter_neg_per, ³​support_emotional_per,
## #   ⁴​support_advice_per, ⁵​support_finance_per, ⁶​support_health_per, …
  1. \(record\_id\) which is the same as the REDcap_id.

  2. \(alter\_support\_per\) - The proportion of alters that the respondent said provided some support and encouraged them to stay healthy.

  3. \(alter_neg_per\) - The proportion of alters that the respondent said had a negative influence on their health.

  4. \(support\_emotional\_per\) - The proportion of alters that the respondent said provided emotional support and helped ``manage personal situations.’’

  5. \(support\_advice\_per\) - The proportion of alters that the respondent said provided advice on things like career choices or where to live.

  6. \(support\_finance\_per\) - The proportion of alters that the respondent said provided advice or direct help with personal finances.

  7. \(support\_health\_per\) - The proportion of alters that the respondent said provided help with regards to medical treatment.

  8. \(support\_camaraderie\_per\) - The proportion of alters that the respondent said provided ``support through understanding important experiences that you have had together.’’

  9. \(gender\_male\_per\) - The proportion of alters that the respondent said are male.

  10. \(race\_white\_per\) - The proportion of alters that the respondent said are, in terms of their race, white.

  11. \(edu\_hs\_per\) - The proportion of alters that the respondent said have a high school diploma.

  12. \(relation\_spouse\_per\) - The propotion of alters that the respondent classified as their spouse.

  13. \(relation\_family\_per\) - The propotion of alters that the respondent classified as a family member.

  14. \(relation\_friend\_per\) - The propotion of alters that the respondent classified as a friend.

  15. \(relation\_advice\_per\) - The propotion of alters that the respondent classified as an adviser.

  16. \(relat\_coworker\_per\) - The propotion of alters that the respondent classified as a coworker.

  17. \(relat\_other\_per\) - The propotion of alters that the respondent classified in the ``other’’ category.

  18. \(less15miles\_per\) - The propotion of alters that the respondent said live less than 15 miles from them.

  19. \(fewer6years\_per\) - The propotion of alters that the respondent said they have known for less than six years.

  20. \(speakweekly\_per\) - The propotion of alters that the respondent said they speak on average weekly with.

Contact

We are grateful for any feedback or suggestions! Please email zwehrwein@bwh.harvard.edu.