| Title: | Political Science Academic Research Gears |
|---|---|
| Description: | Using these tools to simplify the research process of political science and other social sciences. The current version can create folder system for academic project in political science, calculate psychological trait scores, visualize experimental and spatial data, set up color-blind palette, and test for Type I error (false positives) in Qualitative Comparative Analysis (QCA) for crisp-set, multi-value, and fuzzy-set variants. |
| Authors: | Yue Hu [aut, cre], Qian Qiu [ctb], Wen Deng [ctb], Bear Braumoeller [ctb] (QCAfalsePositive functions) |
| Maintainer: | Yue Hu <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.1.9999 |
| Built: | 2026-06-08 05:39:48 UTC |
| Source: | https://github.com/sammo3182/drhutools |
A dataset containing fuzzy-set membership scores for ten sets of state characteristics across 20 states in northern Africa and the Arab Peninsula at the time of the Arab Spring uprisings of 2010–12.
Arab.SpringArab.Spring
A data frame with 20 rows and 10 variables, measured as fuzzy-set membership scores:
Per-capita GDP.
Economic inequality.
Unemployment.
Degree of urbanization.
Size of youth bulge.
Mobile phone usage.
Internet penetration.
Fuel-dependence of economy.
Regime fragility.
Social movement success.
A data.frame object
Hussain, Muzammil M., and Philip N. Howard. 2013. "What Best Explains Successful Protest Cascades? ICTs and the Fuzzy Causes of the Arab Spring." International Studies Review 15(1): 48–66.
Packed ggplot2 function to compare the empirical cumulative distribution functions (ECDF) between the treatment and control groups in an experiment or quasi-experiment.
data |
A data.frame including two columns, one recording the outcome and the other recording the assignment. The assignment column must be named as |
ks_test |
A logical option to indicate whether to show the Kolmogorov-Smirnov test result in the bottom-right corner. The default value is FALSE. |
point_size |
An integer to indicate the size of the points at the largest difference. The default value is 3. |
point_color |
An character or function to indicate the color of the points at the largest difference. The default value is |
link_color |
An character or function to indicate the color of the link at the largest difference. The default value is |
A list of ggplot2 objects comparing the ECDFs between the control and treatment groups and identifying at most three largest differences.
data("PlantGrowth") plot_plant <- cdplot(PlantGrowth, ks_test = TRUE) plot_plantdata("PlantGrowth") plot_plant <- cdplot(PlantGrowth, ks_test = TRUE) plot_plant
A Binomial test for crisp-set qualitative comparative analysis (csQCA), designed to calculate the probability of a false positive given the number of hypotheses implicitly tested and the number of confirming cases.
csQCAbinTest(freq.y, configs, total.configs, adj.method = "holm")csQCAbinTest(freq.y, configs, total.configs, adj.method = "holm")
freq.y |
The frequency with which the dependent variable occurs in the sample (the number of 1s divided by the total number of cases). |
configs |
A list of configurations and the number of cases in which each configuration occurs. |
total.configs |
The total number of configurations used in the original csQCA analysis. This will generally equal the number of lines in the truth table used for Boolean minimization. |
adj.method |
The method used to calculate adjusted p-values (see
|
An object containing the results of the Binomial test.
Adopted from the archived CRAN package QCAfalsePositive by Bear Braumoeller. The original package has been removed from CRAN and is no longer maintained. It is included in drhutools for continued accessibility.
test <- csQCAbinTest(freq.y=0.7, configs=list(aB=5, bCD=3, Ce=2), total.configs=20) summary(test)test <- csQCAbinTest(freq.y=0.7, configs=list(aB=5, bCD=3, Ce=2), total.configs=20) summary(test)
Folder hierarchy creator for academic research
folderSystem( overwrite = FALSE, language = NULL, format = NULL, bibliography = NULL, csl = NULL )folderSystem( overwrite = FALSE, language = NULL, format = NULL, bibliography = NULL, csl = NULL )
overwrite |
Logical. Should existing template files in |
language |
Character or |
format |
Character or |
bibliography |
Character or |
csl |
Character or |
The function constructs a standardized folder hierarchy encompassing codes/, data/, output/, paper/, and document/. These directories are designated for storing programming scripts, data sets, processed outputs, manuscript drafts (including related images and submission documents), and assorted materials, respectively. This organization facilitates easy retrieval of project components, ensuring that members of Dr. Hu's Amazing Team can efficiently navigate and manage shared resources. This structure is advocated for collaborative projects to maintain uniformity across team operations.
In addition, the function assembles a ready-to-write manuscript template under paper/ from the choices below. When an argument is left NULL and the session is interactive, the function asks for the choice; otherwise it falls back to the first option.
language — "english" writes paper_en.qmd; "chinese" writes paper_cn.qmd (Chinese heading numbering, dual abstract, online appendix; modelled on the bundled organizedParticipation.qmd).
format — "typst" (PDF via Typst) or "word" (.docx).
bibliography — "single" produces one reference list via Quarto's citeproc; "separate" produces separate main-text and appendix lists via the Alexandria Typst package (Typst only; Word output is forced to "single").
csl — "apsa" (American Political Science Association) or "apa" (APA 7th edition).
Only the support files required by the chosen configuration are copied into paper/ (the selected .csl, the matching .bib file(s), and the relevant Lua filters).
Invisibly returns NULL. Called for its side effect of creating local folders, placeholder files, a default .gitignore, and the configured manuscript template under the project's working directory.
A permutation test for fuzzy-set qualitative comparative analysis (fsQCA), designed to calculate the probability of a false positive given the number of hypotheses implicitly tested and the distribution of the data.
fsQCApermTest( y, configs, total.configs, num.iter = 10000, my.seed = 123, adj.method = "holm" )fsQCApermTest( y, configs, total.configs, num.iter = 10000, my.seed = 123, adj.method = "holm" )
y |
The outcome variable of interest. |
configs |
A list of configurations to be tested against |
total.configs |
The total number of configurations used in the original fsQCA analysis. This will generally equal the number of lines in the truth table used for Boolean minimization. |
num.iter |
The number of iterations to use for the permutation test. Larger numbers of iterations result in more precise p-values. |
my.seed |
The seed used to generate random numbers. |
adj.method |
The method used to calculate adjusted p-values (see
|
An object containing the aggregate results of the permutation test as well as the individual permutations.
Adopted from the archived CRAN package QCAfalsePositive by Bear Braumoeller. The original package has been removed from CRAN and is no longer maintained. It is included in drhutools for continued accessibility.
intersect <- pmin(social.revolutions$breakdown, social.revolutions$pop.ins) intersect2 <- pmin(social.revolutions$breakdown, (1 - social.revolutions$pop.ins)) intersect3 <- pmin((1 - social.revolutions$breakdown), social.revolutions$pop.ins) intersect4 <- pmin((1 - social.revolutions$breakdown), (1 - social.revolutions$pop.ins)) test <- fsQCApermTest(y = social.revolutions$soc.rev, configs = list(BI = intersect, Bi = intersect2, bI = intersect3, bi = intersect4), total.configs = 4) summary(test) plot(test)intersect <- pmin(social.revolutions$breakdown, social.revolutions$pop.ins) intersect2 <- pmin(social.revolutions$breakdown, (1 - social.revolutions$pop.ins)) intersect3 <- pmin((1 - social.revolutions$breakdown), social.revolutions$pop.ins) intersect4 <- pmin((1 - social.revolutions$breakdown), (1 - social.revolutions$pop.ins)) test <- fsQCApermTest(y = social.revolutions$soc.rev, configs = list(BI = intersect, Bi = intersect2, bI = intersect3, bi = intersect4), total.configs = 4) summary(test) plot(test)
Function to extract colors as hex codes.
gb_cols(...)gb_cols(...)
... |
A character vector indicating the names of colors. Options includes "gold", "black", "orange", "red", "light green", "green", "light blue", "blue", "light grey", "grey", and "dark grey". |
A character of hex codes.
Function to interpolate a gold-black color palette.
gb_pal(palette = "main", reverse = FALSE, ...)gb_pal(palette = "main", reverse = FALSE, ...)
palette |
A character vector indicating the name of palette in gb_palettes. Available palettes:
|
reverse |
A logic vector indicating whether the palette should be reversed; the default is FALSE. |
... |
Additional arguments to pass to |
A function that takes an integer argument (the required number of colors) and returns a character vector of colors interpolating the given sequence.
goodmap function is designed to create interactive PNG Map or GIF Map from a provided data file.
It supports two types of maps: point and polygon.
The function can visualize data by either plotting points based on geographical coordinates
or highlighting regions polygon based on their administrative boundaries (province or city level).
Additionally, the function can generate animated that showcase the change of data.If the map type is point, the color and size of the points will be determined by the
value_set column in the data file, which means the different value of each point.
If the map type is polygon, the color of the polygons will be determined by the average
value of the value_set column for each city or province in the data file.
goodmap( data_file, type = "point", level = NULL, animate = FALSE, animate_var = NULL, map_center = c(35.8617, 104.1954), zoom_level = 4, tile_source = "amap", coord = "WGS-84", color_type = "numeric", custom_colors = NULL, point_radius = 5, legend_opacity = 0.7, legend_name = NULL, width = 800, height = 900 )goodmap( data_file, type = "point", level = NULL, animate = FALSE, animate_var = NULL, map_center = c(35.8617, 104.1954), zoom_level = 4, tile_source = "amap", coord = "WGS-84", color_type = "numeric", custom_colors = NULL, point_radius = 5, legend_opacity = 0.7, legend_name = NULL, width = 800, height = 900 )
data_file |
Dataframe.
When generate point map, |
type |
A string specifying the type of map to generate. Options are |
level |
A string specifying the level of administrative boundaries for polygon maps.
Acceptable values are |
animate |
A logical value indicating whether to generate an animation from the maps. The default is FALSE. If animate is FALSE, the whole data will be generated as a PNG file. If animate is TRUE, an animation will be generated from all panel data, the animate_var must be assigned. |
animate_var |
A string specifying the variable to animate over.
The default is |
map_center |
A numeric vector of length 2 specifying the latitude and longitude
for the center of the map view. Default is |
zoom_level |
A numeric value specifying the zoom level for the map. Default is 3. |
tile_source |
A string specifying the basemap tile provider. Options are |
coord |
A string giving the coordinate system of the point input data
( |
color_type |
If the data is discrete, such as types or categories, choose |
custom_colors |
A vector of colors for customizing the color gradient. Default is |
point_radius |
A numeric value specifying the radius for point markers on point maps. Default is 5. |
legend_opacity |
A numeric value specifying the opacity of the legend. Default is 0.7. |
legend_name |
The name of the legend. Default is |
width |
A numeric value specifying the width of the map images. Default is 800. |
height |
A numeric value specifying the height of the map images. Default is 900. |
Image in the viewer.
## Not run: goodmap( toy_poly, type = "polygon", level = "province" ) ## End(Not run)## Not run: goodmap( toy_poly, type = "polygon", level = "province" ) ## End(Not run)
A internal dataset providing city names and corresponding file names for mapping with Leaflet.
leafletcn.map.namesleafletcn.map.names
A data frame with city names and file names.
A data.frame object
A Binomial test for multi-value qualitative comparative analysis (mvQCA), designed to calculate the probability of a false positive given the number of hypotheses implicitly tested and the number of confirming cases.
mvQCAbinTest(freq.y, configs, total.configs, adj.method = "holm")mvQCAbinTest(freq.y, configs, total.configs, adj.method = "holm")
freq.y |
The frequency with which the dependent variable occurs in the sample (the number of 1s divided by the total number of cases). |
configs |
A list of configurations and the number of cases in which each configuration occurs. |
total.configs |
The total number of configurations used in the original mvQCA analysis. This will generally equal the number of lines in the truth table used for Boolean minimization. |
adj.method |
The method used to calculate adjusted p-values (see
|
An object containing the results of the Binomial test.
Adopted from the archived CRAN package QCAfalsePositive by Bear Braumoeller. The original package has been removed from CRAN and is no longer maintained. It is included in drhutools for continued accessibility.
test <- mvQCAbinTest(freq.y=0.7, configs=list(aB=5, bCD=3, Ce=2), total.configs=20) summary(test)test <- mvQCAbinTest(freq.y=0.7, configs=list(aB=5, bCD=3, Ce=2), total.configs=20) summary(test)
Internal function. Calculates the adjusted thresholds for multiple significance
tests, assuming that the original threshold for a single test is p<0.05.
Used by fsQCApermTest() to calculate confidence intervals.
p.threshold.adjust(total.configs, my.method)p.threshold.adjust(total.configs, my.method)
total.configs |
The total number of hypotheses tested, or the number of configurations utilized by the Quine-McCluskey algorithm in fsQCA (including logical remainders, if they are used in the analysis). |
my.method |
The adjustment method used to calculate p-values (see
|
Numeric vector giving adjusted p-value thresholds, from smallest to largest.
Adopted from the archived CRAN package QCAfalsePositive by Bear Braumoeller. The original package has been removed from CRAN and is no longer maintained. It is included in drhutools for continued accessibility.
p.threshold.adjust(10, "holm")p.threshold.adjust(10, "holm")
Plots distributions of consistencies and counterexamples from permutation tests of fsQCA data, including confidence intervals adjusted to account for multiple inference. Also prints observed consistency values and number of counterexamples as black dots along the x-axis, for comparison.
## S3 method for class 'fsQCApt' plot(x, y = x$config.names, statistic = "both", ...)## S3 method for class 'fsQCApt' plot(x, y = x$config.names, statistic = "both", ...)
x |
Object returned by |
y |
A vector of configurations to examine. Default behavior is to examine all configurations. |
statistic |
The statistic to examine ( |
... |
Additional parameters to pass on. |
Plots of distributions of consistencies, counterexamples, or both.
Adopted from the archived CRAN package QCAfalsePositive by Bear Braumoeller. The original package has been removed from CRAN and is no longer maintained. It is included in drhutools for continued accessibility.
intersect <- pmin(social.revolutions$breakdown, social.revolutions$pop.ins) intersect2 <- pmin(social.revolutions$breakdown, (1 - social.revolutions$pop.ins)) intersect3 <- pmin((1 - social.revolutions$breakdown), social.revolutions$pop.ins) intersect4 <- pmin((1 - social.revolutions$breakdown), (1 - social.revolutions$pop.ins)) test <- fsQCApermTest(y = social.revolutions$soc.rev, configs = list(BI = intersect, Bi = intersect2, bI = intersect3, bi = intersect4), total.configs = 4) plot(test) plot(test, "bi", statistic = "consistency") plot(test, c("BI", "Bi"), statistic = "both") plot(test, statistic = "consistency") plot(test, "BI")intersect <- pmin(social.revolutions$breakdown, social.revolutions$pop.ins) intersect2 <- pmin(social.revolutions$breakdown, (1 - social.revolutions$pop.ins)) intersect3 <- pmin((1 - social.revolutions$breakdown), social.revolutions$pop.ins) intersect4 <- pmin((1 - social.revolutions$breakdown), (1 - social.revolutions$pop.ins)) test <- fsQCApermTest(y = social.revolutions$soc.rev, configs = list(BI = intersect, Bi = intersect2, bI = intersect3, bi = intersect4), total.configs = 4) plot(test) plot(test, "bi", statistic = "consistency") plot(test, c("BI", "Bi"), statistic = "both") plot(test, statistic = "consistency") plot(test, "BI")
Fill scale constructors for gold & black colors
scale_color_gb(palette = "main", discrete = TRUE, reverse = FALSE, ...)scale_color_gb(palette = "main", discrete = TRUE, reverse = FALSE, ...)
palette |
A character vector indicating the name of palette in
|
discrete |
A logic vector indicating whether color aesthetic is discrete or not; the default is "main". |
reverse |
A logic vector indicating whether the palette should be reversed. |
... |
Additional arguments passed to |
No return value, called for modifying the appearance of the plot.
Color scale constructors for gold & black colors
scale_fill_gb(palette = "main", discrete = TRUE, reverse = FALSE, ...)scale_fill_gb(palette = "main", discrete = TRUE, reverse = FALSE, ...)
palette |
A character vector indicating the name of palette in
|
discrete |
A logic vector indicating whether color aesthetic is discrete or not; the default is "main". |
reverse |
A logic vector indicating whether the palette should be reversed. |
... |
Additional arguments passed to |
No return value, called for modifying the appearance of the plot.
Displays number of confirming cases and raw and adjusted p-scores following Binomial test of csQCA data.
## S3 method for class 'csQCAbt' summary(object, ...)## S3 method for class 'csQCAbt' summary(object, ...)
object |
Object returned by |
... |
Additional parameters to pass on. |
Matrix of values for counterexamples and consistency.
Adopted from the archived CRAN package QCAfalsePositive by Bear Braumoeller. The original package has been removed from CRAN and is no longer maintained. It is included in drhutools for continued accessibility.
test <- csQCAbinTest(freq.y=0.7, configs=list(aB=5, bCD=3, Ce=2), total.configs=20) summary(test)test <- csQCAbinTest(freq.y=0.7, configs=list(aB=5, bCD=3, Ce=2), total.configs=20) summary(test)
Displays observed values, confidence intervals, and raw and adjusted p-scores for both consistency and counterexamples following permutation test of fsQCA data.
## S3 method for class 'fsQCApt' summary(object, ...)## S3 method for class 'fsQCApt' summary(object, ...)
object |
Object returned by |
... |
Additional parameters to pass on. |
Two matrices of values for counterexamples and consistency.
Adopted from the archived CRAN package QCAfalsePositive by Bear Braumoeller. The original package has been removed from CRAN and is no longer maintained. It is included in drhutools for continued accessibility.
intersect <- pmin(social.revolutions$breakdown, social.revolutions$pop.ins) intersect2 <- pmin(social.revolutions$breakdown, (1 - social.revolutions$pop.ins)) intersect3 <- pmin((1 - social.revolutions$breakdown), social.revolutions$pop.ins) intersect4 <- pmin((1 - social.revolutions$breakdown), (1 - social.revolutions$pop.ins)) test <- fsQCApermTest(y = social.revolutions$soc.rev, configs = list(BI = intersect, Bi = intersect2, bI = intersect3, bi = intersect4), total.configs = 4) summary(test)intersect <- pmin(social.revolutions$breakdown, social.revolutions$pop.ins) intersect2 <- pmin(social.revolutions$breakdown, (1 - social.revolutions$pop.ins)) intersect3 <- pmin((1 - social.revolutions$breakdown), social.revolutions$pop.ins) intersect4 <- pmin((1 - social.revolutions$breakdown), (1 - social.revolutions$pop.ins)) test <- fsQCApermTest(y = social.revolutions$soc.rev, configs = list(BI = intersect, Bi = intersect2, bI = intersect3, bi = intersect4), total.configs = 4) summary(test)
Displays number of confirming cases and raw and adjusted p-scores following Binomial test of mvQCA data.
## S3 method for class 'mvQCAbt' summary(object, ...)## S3 method for class 'mvQCAbt' summary(object, ...)
object |
Object returned by |
... |
Additional parameters to pass on. |
Matrix of values for counterexamples and consistency.
Adopted from the archived CRAN package QCAfalsePositive by Bear Braumoeller. The original package has been removed from CRAN and is no longer maintained. It is included in drhutools for continued accessibility.
test <- mvQCAbinTest(freq.y=0.7, configs=list(aB=5, bCD=3, Ce=2), total.configs=20) summary(test)test <- mvQCAbinTest(freq.y=0.7, configs=list(aB=5, bCD=3, Ce=2), total.configs=20) summary(test)
goodmap
A sample dataset designed to illustrate the functionality of the goodmap function.
toy_polytoy_poly
A geographic data frame with 6 rows and 5 variables:
Optional data identifier.
Prefectural names, required for city-level map plotting.
Provincial names, required for provincial-level map plotting.
A numeric vector used to group data for animated plotting.
Values used to fill each polygon in the map.
A data.frame object
Calculate psychological traits based on
traits(survey)traits(survey)
survey |
Psychological survey data as a |
The current version can calculate the TOSCA-3SC scores and Grit-O score.
A data frame with trait scores for each observations
Duckworth, Angela L., Christopher Peterson, Michael D. Matthews, and Dennis R. Kelly. 2007. "Grit: Perseverance and Passion for Long-Term Goals." Journal of Personality and Social Psychology 92(6): 1087-1101. doi:10.1037/0022-3514.92.6.1087.
Tangney, June P. 1990. "Assessing Individual Differences in Proneness to Shame and Guilt: Development of the Self-Conscious Affect and Attribution Inventory." Journal of Personality and Social Psychology 59(1): 102-11. doi:10.1037/0022-3514.59.1.102.
column_names <- c("Q3|R3", "Q3|R4", "Q4|R3", "Q4|R4", "Q5|R5", "Q5|R6", "Q6|R3", "Q6|R4", "Q7|R3", "Q7|R4", "Q8|R5", "Q8|R6", "Q9|R5", "Q9|R6", "Q10|R5", "Q10|R6", "Q11|R5", "Q11|R6", "Q12|R3", "Q12|R4", "Q13|R3", "Q13|R4", "Q14|1", "Q15|1", "Q16|1", "Q17|1", "Q18|1", "Q19|1", "Q20|1", "Q21|1", "Q22|1", "Q23|1", "Q24|1", "Q25|1") toy_data <- data.frame(matrix(sample(1:5, 10 * length(column_names), replace = TRUE), ncol = length(column_names))) names(toy_data) <- column_names traits(toy_data)column_names <- c("Q3|R3", "Q3|R4", "Q4|R3", "Q4|R4", "Q5|R5", "Q5|R6", "Q6|R3", "Q6|R4", "Q7|R3", "Q7|R4", "Q8|R5", "Q8|R6", "Q9|R5", "Q9|R6", "Q10|R5", "Q10|R6", "Q11|R5", "Q11|R6", "Q12|R3", "Q12|R4", "Q13|R3", "Q13|R4", "Q14|1", "Q15|1", "Q16|1", "Q17|1", "Q18|1", "Q19|1", "Q20|1", "Q21|1", "Q22|1", "Q23|1", "Q24|1", "Q25|1") toy_data <- data.frame(matrix(sample(1:5, 10 * length(column_names), replace = TRUE), ncol = length(column_names))) names(toy_data) <- column_names traits(toy_data)
Determinants of Social Revolutions
Description
A data frame containing hypothetical fuzzy-set membership scores for three sets of state characteristics across twenty cases.
Usage
Format
A data frame with 20 rows and 3 variables, measured as degree of fuzzy-set membership:
Presence of social revolution.
Degree of state breakdown.
Presence of popular insurrection.
Value
A data.frame object
Source
Ragin, Charles C. 2000. Fuzzy-Set Social Science. Chicago: University of Chicago Press, p. 220.