Add weights to survey data with survey package in R: Part 2

Click here to read why need to add pspwght and pweight to the ESS data in Part 1. Packages we will need: Click here to learn how to access and download ESS round data for the thirty-ish European countries (depending on the year). So with the essurvey package, I have downloaded and cleaned up the most recent round of the ESS survey, conducted in 2018. … Continue reading Add weights to survey data with survey package in R: Part 2

Add circular flags to maps and graphs with ggflags package in R

Packages we will need: Click here to add rectangular flags to graphs and click here to add rectangular flags to MAPS! Apropos of this week’s US news, we are going to graph the number of different or autocoups in South America and display that as both maps and bar charts. According to our pals at the Wikipedia, a self-coup, or autocoup (from the Spanish autogolpe), is a form of … Continue reading Add circular flags to maps and graphs with ggflags package in R

Interpret multicollinearity tests from the mctest package in R

Packages we will need : The mctest package’s functions have many multicollinearity diagnostic tests for overall and individual multicollinearity. Additionally, the package can show which regressors may be the reason of for the collinearity problem in your model. Click here to read the CRAN PDF for all the function arguments available. So – as always – we first fit a model. Given the amount of … Continue reading Interpret multicollinearity tests from the mctest package in R

Check linear regression assumptions with gvlma package in R

Packages we will need: gvlma stands for Global Validation of Linear Models Assumptions. See Peña and Slate’s (2006) paper on the package if you want to check out the math! Linear regression analysis rests on many MANY assumptions. If we ignore them, and these assumptions are not met, we will not be able to trust that the regression results are true. Luckily, R has many … Continue reading Check linear regression assumptions with gvlma package in R

Visualise panel data regression with ExPanDaR package in R

The ExPand package is an example of a shiny app. What is a shiny app, you ask? Click to look at a quick Youtube explainer. It’s basically a handy GUI for R. When we feed a panel data.frame into the ExPanD() function, a new screen pops up from R IDE (in my case, RStudio) and we can interactively toggle with various options and settings to … Continue reading Visualise panel data regression with ExPanDaR package in R

Choose model variables by AIC in a stepwise algorithm with the MASS package in R

Running a regression model with too many variables – especially irrelevant ones – will lead to a needlessly complex model. Stepwise can help to choose the best variables to add. Packages you need: First, choose a model and throw every variable you think has an impact on your dependent variable! I hear the voice of my undergrad professor in my ear: ” DO NOT go … Continue reading Choose model variables by AIC in a stepwise algorithm with the MASS package in R

Check linear regression residuals are normally distributed with olsrr package in R.

Packages we will need: One core assumption of linear regression analysis is that the residuals of the regression are normally distributed. When the normality assumption is violated, interpretation and inferences may not be reliable or not at all valid. So it is important we check this assumption is not violated. As well residuals being normal distributed, we must also check that the residuals have the … Continue reading Check linear regression residuals are normally distributed with olsrr package in R.

Create network graphs with igraph package in R

Packages we will use: First create a dataframe with the two actors in the dyad. Next, convert to matrix so it is suitable for the next function Feed the matrix into the graph.edgelist() function. We can see that it returns an igraph object: “Nodes” designate the vertices of a network, and “edges”  designate its ties. Vertices are accessed using the V() function while edges are … Continue reading Create network graphs with igraph package in R

Summarise data with skimr package in R

A nice way to summarise all the variables in a dataset. The data we’ll look at is from the Correlates of War . It provides dyadic records of militarized interstate disputes (MIDs) over the period of 1816-2010. n_missing : tells which variables have missing values complete_rate : the percentage of the variables which are missing Column 4 – 7 gives the mean, standard deviation, min, … Continue reading Summarise data with skimr package in R

Cluster Analysis with cluster package in R

Packages we will need: I am looking at 127 non-democracies on seeing how the cluster on measures of state capacity (variables that capture ability of the state to control its territory, collect taxes and avoid corruption in the executive). We want to minimise the total within sums of squares error from the cluster mean when determining the clusters. First, we need to find the optimal … Continue reading Cluster Analysis with cluster package in R