Create a correlation matrix with GGally package in R

We can create very informative correlation matrix graphs with one function. Packages we will need: First, choose some nice hex colors. Next, we can go create a dichotomous factor variable and divide the continuous “freedom from torture scale” variable into either above the median or below the median score. It’s a crude measurement but it serves to highlight trends. Blue means the country enjoys high … Continue reading Create a correlation matrix with GGally package in R

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

Analyse Pseudo-R2, VIF scores and robust standard errors for generalised linear models in R

This blog post will introduce a simple function from the jtools package that can give us two different pseudo R2 scores, VIF score and robust standard errors for our GLM models in R Packages we need: From the Varieties of Democracy dataset, we can examine the v2regendtype variable, which codes how a country’s governing regime ends. It turns out that 1994 was a very coup-prone … Continue reading Analyse Pseudo-R2, VIF scores and robust standard errors for generalised linear models 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: ” 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.

Check for multicollinearity with the car package in R

Packages we will need: When one independent variable is highly correlated with another independent variable (or with a combination of independent variables), the marginal contribution of that independent variable is influenced by other predictor variables in the model. And so, as a result: Estimates for regression coefficients of the independent variables can be unreliable. Tests of significance for regression coefficients can be misleading. To check for multicollinearity … Continue reading Check for multicollinearity with the car package in R