Download European Social Survey data with essurvey package in R

The European Social Survey (ESS) measure attitudes in thirty-ish countries (depending on the year) across the European continent. It has been conducted every two years since 2001. The survey consists of a core module and two or more ‘rotating’ modules, on social and public trust; political interest and participation; socio-political orientations; media use; moral, political and social values; social exclusion, national, ethnic and religious allegiances; well-being, … Continue reading Download European Social Survey data with essurvey package in R

Add rectangular flags to graphs with ggimage package in R

This quick function can add rectangular flags to graphs. Click here to add circular flags with the ggflags package. The data comes from a Wikipedia table on a recent report by OECD’s Overseas Development Aid (ODA) from donor countries in 2019. Click here to read about scraping tables from Wikipedia with the rvest package in R. In order to use the geom_flag() function, we need … Continue reading Add rectangular flags to graphs with ggimage package in R

Scrape NATO defense expenditure data from Wikipedia with the rvest package in R

We can all agree that Wikipedia is often our go-to site when we want to get information quick. When we’re doing IR or Poli Sci reesarch, Wikipedia will most likely have the most up-to-date data compared to other databases on the web that can quickly become out of date. So in R, we can scrape a table from Wikipedia and turn into a database with … Continue reading Scrape NATO defense expenditure data from Wikipedia with the rvest package in R

Download WorldBank data with WDI package in R

Use this package to really quickly access all the indicators from the World Bank website. With the WDIsearch() function we can look for the World Bank indicator that measures oil rents as a percentage of a country’s GDP. You can look at the World Bank website and browse all the indicators available. The output is: Copy the indicator string and paste it into the WDI() … Continue reading Download WorldBank data with WDI 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

Download economic and financial time series data with Quandl package in R

Packages we will need: The website Quandl.com is a great resource I came across a while ago, where you can download heaps of datasets for variables such as energy prices, stock prices, World Bank indicators, OECD data other random data. In order to download the data from the site, you need to first set up an account on the website, and indicate your intended use … Continue reading Download economic and financial time series data with Quandl 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: try not to 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.