Skip to content

Commit f995465

Browse files
authored
Merge pull request #58 from jhollway/develop
Adding more data
2 parents ea2c200 + a6a06f2 commit f995465

19 files changed

+106
-5
lines changed

.github/pull_request_template.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ Closes #(issue no.)
1010

1111
# Checklist:
1212

13-
- [ ] I have added tests that prove my fix is effective or that my feature works
1413
- [ ] The package builds on my OS without issues (please add workstation details)
1514
- [ ] My changes generate no new warnings
1615
- [ ] My code follows the style guidelines of this project
1716
- [ ] I have commented my code, particularly in hard-to-understand areas
18-
- [ ] I have made corresponding changes to the documentation (.R, NEWS.md)
17+
- [ ] I have added tests that prove my fix is effective or that my feature works
18+
- [ ] I have documented any functions or data in an .R script
19+
- [ ] I have updated NEWS.md
1920
- [ ] I have bumped the version by the appropriate increment in the DESCRIPTION file (major, minor, patch)
2021
- [ ] PR checks all pass for latest commit

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: roctopus
22
Title: Utility functions for multimode and multilevel network analysis
3-
Version: 0.2.1
3+
Version: 0.2.3
44
Description: This package assembles a number of utility functions for
55
loading, visualising, and analysing multimode, multiplex, and multilevel networks.
66
URL: https://bitbucket.org/jhollway/roctopus/

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export(create_match)
55
export(create_nest)
66
export(create_poles)
77
export(create_random)
8+
export(df_to_mat)
89
export(plot_2x2)
910
export(plot_globalnet)
1011
export(plot_multilevel)

NEWS.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# roctopus 0.2.3
2+
3+
2020-07-19
4+
5+
## Data
6+
7+
* Added `mexicanpower` dataset
8+
* Added `senate112` datasets
9+
* Updated `evs` datasets to matrices
10+
11+
## Package
12+
13+
* Added `df_to_mat()` function for converting regular adjacency and incidence data frames into matrices
14+
115
# roctopus 0.2.1
216

317
2020-07-17

R/evs.R

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
#' @keywords datasets
1111
#' @name evs
1212
#' @usage data(IT_1990)
13-
#' @format Data frames with 15 variables:
13+
#' @format Matrices with 14 columns:
1414
#' \describe{
15-
#' \item{ID}{Anonymised individual identifiers}
1615
#' \item{Welfare}{1 if individual associated}
1716
#' \item{Religious}{1 if individual associated}
1817
#' \item{Education.culture}{1 if individual associated}

R/mexicanpower.R

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#' Mexican power network
2+
#'
3+
#' A network of 11 core members of the 1990s Mexican power elite (Knoke 2017),
4+
#' three of which were successively elected presidents of Mexico:
5+
#' José López Portillo (1976-82), Miguel de la Madrid (1982-88), and Carlos Salinas de Gortari (1988-94,
6+
#' who was also the son of another core member, Raúl Salinas Lozano).
7+
#' The undirected lines connecting pairs of men represent any formal, informal,
8+
#' or organizational relation between a dyad;
9+
#' for example, “common belonging (school, sports, business, political participation),
10+
#' or a common interest (political power)” (Mendieta et al. 1997: 37).
11+
#'
12+
#' @docType data
13+
#' @keywords datasets
14+
#' @name mexicanpower
15+
#' @usage data(mexicanpower)
16+
#' @format Matrix with 11 rows/columns
17+
#' @source Knoke, David. 1990. \emph{Political Networks}.
18+
#'
19+
#' Knoke, Christopoulos, Diani, and Hollway. 2020.
20+
#' \emph{Multimodal Political Networks: The Structural Perspective}.
21+
#' Cambridge University Press: Cambridge.
22+
"mexicanpower"

R/mm_conversion.R

+13
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,16 @@ project_list <- function(eventlist){
8181
out <- out %>% mutate(time = as.POSIXct(time), increment = as.numeric(increment))
8282
out
8383
}
84+
85+
86+
#' Transform a data frame to an adjacency or incidence matrix
87+
#'
88+
#' @param df a data frame, with the first column ID
89+
#' @return an adjacency or incidence matrix
90+
#' @export
91+
df_to_mat <- function(df){
92+
df <- as.data.frame(df)
93+
row.names(df) <- df[,1]
94+
df[,1] <- NULL
95+
as.matrix(df)
96+
}

R/senate112.R

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#' 112th Congress Senate Voting
2+
#'
3+
#' These datasets list the U.S. Senators who served in the 112th Congress,
4+
#' which met from January 3, 2011 to January 3, 2013.
5+
#' Although the Senate has 100 seats, 103 persons served during this period due to two resignations and a death.
6+
#' However, the third replacement occurred only two days before the end and cast no votes on the bills investigated here.
7+
#' Hence, the number of Senators we analyzed is 102.
8+
#'
9+
#' CQ Almanac identified 25 key bills on which the Senate voted during the 112th Congress,
10+
#' and which Democratic and Republican Senators voting “yea” and “nay” on each proposal.
11+
#'
12+
#' Lastly, we obtained data on campaign contributions made by 92 PACs from the Open Secrets Website.
13+
#' We recorded all contributions made during the 2008, 2010, and 2012 election campaigns
14+
#' to the 102 persons who were Senators in the 112th Congress.
15+
#' The vast majority of PAC contributions to a candidate during a campaign was for $10,000
16+
#' (the legal maximum is $5,000 each for a primary and the general election).
17+
#' We aggregated the contributions across all three electoral cycles, then dichotomized the sums into no contribution (0)
18+
#' and any contribution (1).
19+
#'
20+
#' @docType data
21+
#' @keywords datasets
22+
#' @name senate112
23+
#' @usage data(DemSxP)
24+
#' @format Matrix of 51 rows (Senators) and 63 columns (PACS)
25+
#' @source Knoke, Christopoulos, Diani, and Hollway. 2020.
26+
#' \emph{Multimodal Political Networks}.
27+
#' Cambridge University Press: Cambridge.
28+
"DemSxP"
29+
30+
#' @rdname senate112
31+
#' @usage data(RepSxP)
32+
#' @format Matrix of 62 rows (Senators) and 72 columns (PACS)
33+
"RepSxP"
34+
35+
#' @rdname senate112
36+
#' @usage data(OverSxP)
37+
#' @format Matrix of 20 rows (Senators) and 32 columns (PACS)
38+
"OverSxP"

data/DE_1990.rda

183 Bytes
Binary file not shown.

data/DE_2008.rda

-151 Bytes
Binary file not shown.

data/DemSxP.rda

1015 Bytes
Binary file not shown.

data/IT_1990.rda

-85 Bytes
Binary file not shown.

data/IT_2008.rda

-143 Bytes
Binary file not shown.

data/OverSxP.rda

445 Bytes
Binary file not shown.

data/RepSxP.rda

1.26 KB
Binary file not shown.

data/UK_1990.rda

-92 Bytes
Binary file not shown.

data/UK_2008.rda

-127 Bytes
Binary file not shown.

data/mexicanpower.rda

266 Bytes
Binary file not shown.

tests/testthat/test_df_to_mat.R

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
context('df_to_mat')
2+
3+
data1 <- data.frame(ID = LETTERS[1:3],
4+
G = c(0,1,1),
5+
H = c(0,0,1),
6+
I = c(1,1,0))
7+
mat1 <- matrix(c(0,1,1,0,0,1,1,1,0),3,3)
8+
rownames(mat1) <- LETTERS[1:3]
9+
colnames(mat1) <- LETTERS[7:9]
10+
11+
test_that("data frame converted to matrix correctly",{
12+
expect_equal(df_to_mat(data1), mat1)
13+
})

0 commit comments

Comments
 (0)