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:
Prust M, Halm A, Nedelcu S, Nieves A, Dhand A. Head-to-head comparison of social network assessments in stroke survivors. Neurohospitalist. (2020) 11:18–24. doi: 10.1177/1941874420945889
Dhand A, White CC, Johnson C, Xia Z, De Jager PL. A scalable online tool for quantitative social network assessment reveals potentially modifiable social environmental risks. Nat Comm. (2018) 9:3930. doi: 10.1038/s41467-018-06408-6
For more information on the instrument: https://redcap.partners.org/redcap/surveys/?s=8X4N3J7LY4
This package requires the following versions of R and other packages:
R
(>= 3.6.0)dplyr
(>= 1.0.7)ggraph
(>= 2.0.5)tidygraph
(>= 1.2.0)igraph
(>= 1.3.1)gridExtra
(>= 2.3.0)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.
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.
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:
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)
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, …
\(record\_id\) which is the same as the REDcap_id.
\(alter\_support\_per\) - The proportion of alters that the respondent said provided some support and encouraged them to stay healthy.
\(alter_neg_per\) - The proportion of alters that the respondent said had a negative influence on their health.
\(support\_emotional\_per\) - The proportion of alters that the respondent said provided emotional support and helped ``manage personal situations.’’
\(support\_advice\_per\) - The proportion of alters that the respondent said provided advice on things like career choices or where to live.
\(support\_finance\_per\) - The proportion of alters that the respondent said provided advice or direct help with personal finances.
\(support\_health\_per\) - The proportion of alters that the respondent said provided help with regards to medical treatment.
\(support\_camaraderie\_per\) - The proportion of alters that the respondent said provided ``support through understanding important experiences that you have had together.’’
\(gender\_male\_per\) - The proportion of alters that the respondent said are male.
\(race\_white\_per\) - The proportion of alters that the respondent said are, in terms of their race, white.
\(edu\_hs\_per\) - The proportion of alters that the respondent said have a high school diploma.
\(relation\_spouse\_per\) - The propotion of alters that the respondent classified as their spouse.
\(relation\_family\_per\) - The propotion of alters that the respondent classified as a family member.
\(relation\_friend\_per\) - The propotion of alters that the respondent classified as a friend.
\(relation\_advice\_per\) - The propotion of alters that the respondent classified as an adviser.
\(relat\_coworker\_per\) - The propotion of alters that the respondent classified as a coworker.
\(relat\_other\_per\) - The propotion of alters that the respondent classified in the ``other’’ category.
\(less15miles\_per\) - The propotion of alters that the respondent said live less than 15 miles from them.
\(fewer6years\_per\) - The propotion of alters that the respondent said they have known for less than six years.
\(speakweekly\_per\) - The propotion of alters that the respondent said they speak on average weekly with.
We are grateful for any feedback or suggestions! Please email
zwehrwein@bwh.harvard.edu
.