Skip to content

Commit 39a77d3

Browse files
authored
Merge pull request #61 from jhollway/develop
* Renamed twomode_netlm() to netlm2() * Fixed various printing issues with netlm2() * Added tests for netlm2() * Added tests for create_random() * Added opensecrets data * Added powerelite data
2 parents 9a625f3 + 6cafc9e commit 39a77d3

22 files changed

+101
-61
lines changed

.Rbuildignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
^LICENSE\.md$
33
^.*\.Rproj$
44
^\.Rproj\.user$
5+
^working$

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.5
3+
Version: 0.2.6
44
Description: This package assembles a number of utility functions for
55
loading, visualising, and analysing multimode, multiplex, and multilevel networks.
66
URL: https://github.com/jhollway/roctopus

NAMESPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export(create_nest)
77
export(create_poles)
88
export(create_random)
99
export(df_to_mat)
10+
export(netlm2)
1011
export(plot_2x2)
1112
export(plot_globalnet)
1213
export(plot_multilevel)
@@ -23,7 +24,6 @@ export(twomode_components)
2324
export(twomode_constraint)
2425
export(twomode_dominance)
2526
export(twomode_modularity)
26-
export(twomode_netlm)
2727
export(twomode_smallworld)
2828
import(geosphere)
2929
import(ggplot2)

NEWS.md

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
# roctopus 0.2.6
2+
3+
2020-08-18
4+
5+
## Analysis
6+
7+
* Renamed `twomode_netlm()` to `netlm2()`
8+
* Fixed various printing issues with `netlm2()`
9+
10+
## Package
11+
12+
* Added tests for `netlm2()`
13+
* Added tests for `create_random()`
14+
15+
## Data
16+
17+
* Added `opensecrets` data
18+
* Added `powerelite` data
19+
120
# roctopus 0.2.5
221

322
2020-07-21

R/data_opensecrets.R

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#' Open Secrets
2+
#'
3+
#' This data is based on 26 elites who sat on the boards of directors
4+
#' for at least two of six economic policy making organizations (Domhoff 2016),
5+
#' and also made campaign contributions to one or more of six candidates
6+
#' running in the primary election contests for the 2008 Presidential nominations
7+
#' of the Republican Party (Rudy Giuliani, John McCain, Mitt Romney)
8+
#' or the Democratic Party (Hillary Clinton, Christopher Dodd, Barack Obama).
9+
#'
10+
#' @docType data
11+
#' @keywords datasets
12+
#' @name opensecrets
13+
#' @usage data(opensecrets)
14+
#' @format Matrix with 26 rows and 6+6 columns
15+
#' @source Domhoff, G William. 2016.
16+
#' “Who Rules America? Power Elite Database.” http://www2.ucsc.edu/whorulesamerica/power_elite/.
17+
#'
18+
#' The Center for Responsive Politics. 2019. “OpenSecrets.” http://www.opensecrets.org.
19+
#'
20+
#' Knoke, Christopoulos, Diani, and Hollway. 2020.
21+
#' \emph{Multimodal Political Networks: The Structural Perspective}.
22+
#' Cambridge University Press: Cambridge.
23+
"opensecrets"

R/data_powerelite.R

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#' Power Elite
2+
#'
3+
#' A 2-mode network of persons serving as directors or trustees of think tanks.
4+
#' Think tanks are “public-policy research analysis and engagement organizations
5+
#' that generate policy-oriented research, analysis, and advice on domestic and international issues,
6+
#' thereby enabling policymakers and the public to make informed decisions about public policy” (McGann 2016: 6).
7+
#' The Power Elite Database (Domhoff 2016) includes information on the directors of 33 prominent think tanks in 2012.
8+
#' Here we include only 14 directors who held three or more seats among 20 think tanks.
9+
#'
10+
#' @docType data
11+
#' @keywords datasets
12+
#' @name powerelite
13+
#' @usage data(powerelite)
14+
#' @format Matrix with 14 rows and 20 columns
15+
#' @source Domhoff, G William. 2016.
16+
#' “Who Rules America? Power Elite Database.” http://www2.ucsc.edu/whorulesamerica/power_elite/.
17+
#'
18+
#' Knoke, Christopoulos, Diani, and Hollway. 2020.
19+
#' \emph{Multimodal Political Networks: The Structural Perspective}.
20+
#' Cambridge University Press: Cambridge.
21+
"powerelite"

R/mm_qap.R

+11-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
#' @export
1010
#' @examples
1111
#' \dontrun{
12-
#' twomode_netlm(matrix, list(matrix2, matrix3),
13-
#' c("Intercept", "Explainer"))
12+
#' netlm2(matrix, list(matrix2, matrix3),
13+
#' c("Explanatory Variable", "Control Variable"))
1414
#' }
15-
twomode_netlm <- function(DV, IV, names, rep = 1000){
15+
netlm2 <- function(DV, IV, names, rep = 1000){
1616

17-
# if(missing(names)) names <- c("Intercept", lapply(IV, function(x) names(x))
17+
if(missing(names)){
18+
names <- paste0("x", 1:length(IV))
19+
}
1820
# Consider converting to formula
1921

2022
rbperm <- function (m) {
@@ -50,15 +52,17 @@ twomode_netlm <- function(DV, IV, names, rep = 1000){
5052
ifelse(as.numeric(lapply(1:(nIV+1),
5153
function(x) ecdf(permDist[,x])(M.coeff[x])))<0.001,
5254
"***", "**"), "*"), ""))
55+
rownames(resTable) <- NULL
5356
print(resTable)
57+
# Turn this into a print function
5458

5559
cat("\nMultiple R-squared: ", formatC(summary(M.fit)$r.squared),
5660
",\tAdjusted R-squared: ", formatC(summary(M.fit)$adj.r.squared),
5761
"\n", sep="")
5862

5963
obj <- list()
6064
obj$results <- data.frame(Effect = c("Intercept", names),
61-
Coefficients = formatC(M.coeff, format="f", digits = 2),
65+
Coefficients = as.numeric(formatC(M.coeff, format="f", digits = 2)),
6266
Pvalue = signif(as.numeric(lapply(1:(nIV+1),
6367
function(x) ecdf(permDist[,x])(M.coeff[x]))),
6468
digits=2),
@@ -69,7 +73,8 @@ print(resTable)
6973
ifelse(as.numeric(lapply(1:(nIV+1),
7074
function(x) ecdf(permDist[,x])(M.coeff[x])))<0.001,
7175
"***", "**"), "*"), ""))
76+
rownames(obj$results) <- NULL
7277
obj$r.squared <- formatC(summary(M.fit)$r.squared)
7378
obj$adj.r.squared <- formatC(summary(M.fit)$adj.r.squared)
74-
return(obj)
79+
invisible(obj)
7580
}

R/vis.R

-4
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ plot_multilevel <- function(mat,levels=NULL){
102102
vertex.shape=c(rep("square",ncol(mat)),rep("circle",nrow(mat))),
103103
layout = f)
104104

105-
106-
107-
108-
109105
}
110106

111107
#' Plotting multilevel networks on a globe

data/opensecrets.rda

420 Bytes
Binary file not shown.

data/powerelite.rda

372 Bytes
Binary file not shown.

man/twomode_2x2.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/twomode_clustering.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/twomode_coherence.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/twomode_components.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/twomode_constraint.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/twomode_dominance.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/twomode_modularity.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/twomode_netlm.Rd

-38
This file was deleted.

man/twomode_smallworld.Rd

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-create.R

+4
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ test_that("match creation works", {
1313
test_that("nest creation works", {
1414
expect_equal(create_nest(2,4), matrix(c(1,1,0,1,0,0,0,0),2,4))
1515
})
16+
17+
test_that("random creation works", {
18+
expect_false(isTRUE(all.equal(create_random(2,4,.3), create_random(2,4,.3))))
19+
})

tests/testthat/test-qap.R

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
mat1 <- matrix(c(0,1,1,0,0,1,1,1),4,2)
2+
mat2 <- matrix(c(0,1,0,1,0,1,0,1),4,2)
3+
mat3 <- matrix(c(0,0,1,1,0,0,1,1),4,2)
4+
5+
test_that("coefficients calculated correctly",{
6+
expect_equal(netlm2(mat1, IV = list(mat2, mat3))$results$Coefficients, c(0.37, 0.25, 0.25), tolerance = .011)
7+
})
8+
9+
test_that("p-values calculated correctly",{
10+
expect_equal(netlm2(mat1, IV = list(mat2, mat3))$results$Pvalue, c(0.38, 0.84, 0.79), tolerance = .03)
11+
})

working/inst.cent.R

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
devtools::install_bitbucket("jhollway/roctopus", auth_user = "jhollway", password = "VQaKN0TmGD8w")
2-
31
library(igraph)
42
# pdf("~/Desktop/dombycoh.pdf", width=11, height=8)
53
par(mfrow = c(2,3))

0 commit comments

Comments
 (0)