Home

How to automate panel data modelling with dynamic formulas in R

Packages we will need: First we create our panel regression function. A plm takes in many parts including the formula, the data and the model type, for example. Here we can change the formula of independent variables that we can plug into the model We type in the specific model formulas using paste We feed…

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 decision tree analysis with xgboost in R (Tidymodels Series PART 3)

Packages we will need: In this blog post, we are going to run boosted decision trees with xgboost in tidymodels. Boosted decision trees are a type of ensemble learning technique. Ensemble learning methods combine the predictions from multiple models to create a final prediction that is often more accurate than any single model’s prediction. The…

How to run linear regression analysis with tidymodels in R for temporal prediction (Tidymodels Series PART 2)

Packages we will need: We will look at Varieties of Democracy dataset We will create two datasets: one for all years EXCEPT 2020 and one for only 2020 First we build the model. We will look at whether level of public sector theft can predict the judicial corruption levels. The model will have three parts…

How to run regressions with the tidymodels package in R: PART 1

The tidymodels framework in R is a collection of packages for modeling. Within tidymodels, the parsnip package is primarily responsible for specifying models in a way that is independent of the underlying modeling engines. The set_engine() function in parsnip allows users to specify which computational engine to use for modeling, enabling the same model specification…

How to use the mget() function in R

The mget() fuction is a multiple get() function We use mget() to retrieve multiple objects by their names I have found this helpful when I want to perform operations on many df (with similar names) without having to type out each name. For example, I can create four data.frames. They all have similar name patterns.…

How to analyse Afrobarometer survey data with R. PART 3: Cronbach’s Alpha, Exploratory Factor Analysis and Correlation Matrices

Packages we will need: How do people view the state of the economy in the past, present and future for the country and how they view their own economic situation? Are they highly related concepts? In fact, are all these questions essentially asking about one thing: how optimistic or pessimistic a person is about the…

How to calculate a linguistic Herfindahl-Hirschman Index (HHI) with Afrobarometer survey data in R PART 2

Packages we will need: In this blog, we will look at calculating a variation of the Herfindahl-Hirschman Index (HHI) for languages. This will give us a figure that tells us how diverse / how concentrated the languages are in a given country. We will continue using the Afrobarometer survey in the post! Click here to…