How to automate panel data modelling with dynamic formulas in R
Packages we will need: Often when I am running a bunch of regressions, I can get bogged down with lines and lines of code. It is annoying if I want to change just one part of the formula. I have to go to EACH model and change the variable(or dates or lags or regions or…
How to improve graphs with themes and palettes: Top packages in R
In this blog, we can look at ways to make our plots and graphs more appealing to the eye. Before we go about working on the aesthetics, let’s build and save a typical political science graph. We will examine the inverted U shape between democracy and level of mass mobilization across six different regions. The…
How to download and animate the Varieties of Democracy (V-DEM) dataset in R
In this blog post, we will download the V-DEM datasets with their vdemdata package. It is still in development, so we will use the install_github() function from the devtools package And really quickly we can download the dataset with one line of code We can use the find_var function to get information on variables based…
Tips and code snippets to improve ggplot graphs and plots in R
Some code snippets to improve graph appearance and readability! Compare the first basic graph with the second more informative graph. Dealing with the z and y axes can be a pain. In this code: The breaks argument of scale_y_continuous() is set using a custom function that takes limits as input (which represents the range of…
How to only label the outliers in a ggplot graph with R
Another blog I will make to have easy access to code snippets for my own record. We will use an example with data from V-DEM. Click here to read more about downloading the V-DEM dataset v2x_jucon: To what extent does the executive respect the constitution and comply with court rulings, and to what extent is…
How to rowwise sum the variables that contain the same variable string pattern in R
This is another blog post so that I can keep a snippet of code for myself! And if you find it helpful too, all the better. We will be completing rowwise computations, which is not the default in R. Therefore, we need to explicitly state that is what we are hoping to do In this…
Removing variables from V-DEM according to string suffixes
In this blog, I just want to keep the code that removes the Varieties of Democracy variables that are not the continuous variables and the run exploratory correlation analysis. Click here to read more about downloading the V-DEM dataset directly into R via the vdemdata package in R Click here to download the V-DEM dataset…
How to run multiple t-tests in a function with the broom package in R
Packages we will need: We will use the Varieties of Democracy dataset again. We will use a t-test comparing democracies (boix == 1) and non-democracies (boix == 0) in the years 2000 to 2020. We need to remove the instances where boix is NA. I choose three t-tests to run simultaneously. Comparing democracies and non-democracies…
How to use the assign() function in R
We can use the assign function to create new variables. Most often I want to assign variables that I create to the Global Environment. assign particularly useful in loops, simulations, and scenarios involving conditional variable naming or creation. The basic syntax of the assign function is assign(x, value, pos = -1, envir = as.environment(pos), inherits…
How to run cross-validation of decision-tree models with xgboost in R (PART 4 Tidymodels series)
In this blog post, we will cross-validate different boosted tree models and find the one with best root mean square error (RMSE). Specifically, part 2 goes into more detail about RMSE as a way to choose the best model Click here to read part 1, part 2 or part 3 of this series on tidymodel…
Loading…
Something went wrong. Please refresh the page and/or try again.
Follow My Blog
Get new content delivered directly to your inbox.