SEO News
SEO Expert #1 In Online Marketing
  • Home
  • Houston SEO Expert
  • Houston SEO
  • SEO Houston
  • San Antonio SEO Expert
  • SEO Houston Pros
  • SEO
  • Blog
  • Texas SEO Expert
  • Houston SEO Consultant
  • The Single Best Strategy To Use For SEO Expert
  • Fascination About SEO Expert
  • A Review Of San Antonio SEO Consultant
  • The Fact About San Antonio SEO Company That No One Is Suggesting
  • Austin SEO Expert
  • Dallas SEO Expert

How to use RStudio to create traffic forecasting models

11/30/2022

0 Comments

 

There is a lot of fervor in the SEO industry for Python right now.

It is a comparably easier programming language to learn and has become accessible to the SEO community through guides and blogs.

But if you want to learn a new language for analyzing and visualizing your search data, consider looking into R.

This article covers the basics of how you can produce time series forecasts in RStudio from your Google Search Console click data.

But first, what is R?

R is “a language and environment for statistical computing and graphics,” according to The R Project for Statistical Computing. 

R isn’t new and has been around since 1993. Still, learning some of the basics of R – including how to interact with Google’s various APIs – can be advantageous for SEOs.

If you want to pick up R as a new language, good courses to learn from are:

  • Data Analysis with R Programming (Offered by Google)
  • R Programming (Offered by Johns Hopkins University)

But if you grasp the basics and want to learn data visualization fundamentals in R, I recommend Coursera’s guided project, Application of Data Analysis in Business with R Programming.

And then you also need to install:

  • R (through the Comprehensive R Archive Network).
  • Posit’s RStudio integrated development environment (IDE) – which is to R as PyCharm is to Python.

What follows are the steps for creating traffic forecasting models in RStudio using click data.

Step 1: Prepare the data

The first step is to export your Google Search Console data. You can either do this through the user interface and exporting data as a CSV:

GSX exports

Or, if you want to pull your data via RStudio directly from the Google Search Console API, I recommend you follow this guide from JC Chouinard.

If you do this via the interface, you’ll download a zip file with various CSVs, from which you want the workbook named “Dates”:

Your date range can be from a quarter, six months, or 12 months – all that matters is that you have the values in chronological order, which this export easily produces. (You just need to sort Column A, so the oldest values are at the top.)


Get the daily newsletter search marketers rely on.

Processing…Please wait.

See terms.


Step 2: Plot the time series data in RStudio

Now we need to import and plot our data. To do this, we must first install four packages and then load them.

The first command to run is:

## Install packages
install.packages("tidyverse")
install.packages("tsibble")
install.packages("fabletools")
install.packages("bsts")

Followed by:

## Load packages
library("tidyverse")
library("tsibble")
library("fabletools")
library("bsts")

You then want to import your data. The only change you need to make to the below command is the file type name (maintaining the CSV extension) in red:

## Read data
mdat <- read_csv("example data csv.csv",
col_types = cols(Date = col_date(format = "%d/%m/%Y")))

Then the last two commands in plotting your data are to make the time series the object, then to plot the graph itself:

## Make time series object
ts_data <- mdat %>%
as_tsibble(index = "Date")

Followed by:

## Make plot
autoplot(ts_data) +
labs(x = "Date", subtitle = "Time series plot")

And in your RStudio interface, you will have a time series plot appear:

Step 3: Model and forecast your data in RStudio

At this stage, it’s important to acknowledge that forecasting is not an exact science and relies on several truths and assumptions. These being:

  • Assumptions that historical trends and patterns shall continue to replicate with varying degrees over time.
  • Forecasting will contain errors and anomalies because your data set (your real-world clicks data) will contain anomalies that could be construed as errors.
  • Forecasts typically revolve around the average, making group forecasts more reliable than running a series of micro-forecasts.
  • Shorter-range forecasting is typically more accurate than longer-range forecasting.

With this out of the way, we can begin to model and forecast our traffic data.

For this article, I will visualize our data as a Bayesian Structural Time Series (BSTS) forecast, one of the packages we installed earlier. This graph is used by most forecasting methods. 

Most marketers will have seen or at least be familiar with the model as it is commonly used across many industries for forecasting purposes.

The first command we need to run is to make our data fit the BSTS model:

ss <- AddLocalLinearTrend(list(), ts_data$Clicks)
ss <- AddSeasonal(ss, ts_data$Clicks, nseasons = 52)
model1 <- bsts(ts_data$Clicks,
state.specification = ss,
niter = 500)

And then plot the model components:

plot(model1, "comp")

And now we can visualize one- and two-year forecasts.

Going back to the previously mentioned general forecasting rules, the further into the future you forecast, the less accurate it becomes. Thus, I stick to two years when doing this.

And as BSTS considers an upper and lower bound, it also becomes pretty pointless past a certain point.

The below command will produce a one-year future BSTS forecast for your data:

# 1-year
pred1 <- predict(model1, horizon = 365)
plot(pred1, plot.original = 200)

And you’ll return a graph like this:

1-year forecast graph

To produce a two-year forecasting graph from your data, you want to run the below command:

pred2 <- predict(model1, horizon = 365*2)
plot(pred2, plot.original = 365)

And this will produce a graph like this:

2-year forecast graph

As you can see, the upper and lower bounds in the one-year forecast had a range of -50 to +150, whereas the 2-year forecast has -200 to +600.

The further into the future you forecast, the greater this range becomes and, in my opinion, the less useful the forecast becomes.

The post How to use RStudio to create traffic forecasting models appeared first on Search Engine Land.



a message brought to you by Wayne Vass SEO

This article first appeared on: The post %%POSTLINK%% appeared first on %%BLOGLINK%%.
0 Comments



Leave a Reply.

    Author

    Write something about yourself. No need to be fancy, just an overview.

    Archives

    April 2023
    March 2023
    February 2023
    January 2023
    December 2022
    November 2022
    October 2022
    September 2022
    August 2022
    July 2022
    June 2022
    May 2022
    April 2022
    March 2022
    February 2022
    January 2022
    December 2021
    November 2021
    October 2021
    September 2021
    August 2021
    July 2021
    June 2021
    May 2021
    April 2021
    March 2021
    February 2021
    January 2021
    December 2020
    November 2020
    October 2020
    September 2020
    August 2020
    July 2020
    June 2020
    May 2020
    April 2020
    March 2020
    February 2020
    January 2020
    December 2019
    November 2019
    October 2019
    September 2019
    August 2019
    July 2019
    June 2019
    May 2019
    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    July 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017
    September 2017
    August 2017
    July 2017
    June 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016

    Categories

    All

    RSS Feed

Powered by Create your own unique website with customizable templates.