SEO and web marketing analysis almost always presents us with the same problem: we have too many metrics and we don’t know which ones really matter. Search volume, CPC, competition, CTR, bounce rate, time on page, conversions by source, average position — the list grows with every new tool we add to our stack.
The problem is not a lack of data: it’s that these metrics are often correlated with each other (more impressions lead to more clicks, which lead to more conversions, which increase costs). When variables move together, most of the information they contain is redundant. Principal Component Analysis (PCA) is the tool we have to cut through this redundancy: it reduces a set of many correlated variables to a few uncorrelated components that capture most of the original information.
In clearer terms: PCA finds the “directions” in which our data vary the most, and lets us project everything else onto those few dimensions. It is like looking at a three-dimensional object from its most informative angle instead of from a random viewpoint.
To grasp the idea of dimensionality reduction, picture a city with many interconnected streets. PCA works like an urban-planning system that identifies the main traffic arteries. By focusing on these “main roads”, we get a clear view of the city’s structure without having to analyse every single side street.
In the context of web marketing and data analysis, PCA is a powerful tool for several reasons. It is effective for visualising and exploring high-dimensional datasets, making it easy to spot trends, patterns or outliers. It is also commonly used in the data pre-processing stage for machine learning, extracting the most informative features from large datasets while preserving relevant information. Another advantage is its ability to *minimise or eliminate multicollinearity and overfitting***, frequent problems in web marketing datasets with many potentially correlated variables.
To understand how PCA works we need to familiarise ourselves with a few concepts. Nothing scary — we take them one at a time.
Variance and covariance. Variance measures how spread out a single variable is around its mean. Covariance measures how two variables move together: positive means they tend to increase or decrease together, negative means they move in opposite directions. PCA looks for directions (components) that maximise variance — because more variance means more information.
The covariance matrix summarises the covariances between all pairs of variables. It has the variances on the diagonal and the covariances off the diagonal. It is the starting point of PCA.
Eigenvalues and eigenvectors. This is the mathematical core. The principal components are simply the eigenvectors of the covariance matrix. An eigenvector identifies a direction in the data space; the associated eigenvalue tells us how much variance that direction captures.
The formula is straightforward:
\( \Sigma \mathbf{v} = \lambda \mathbf{v} \\ \)where \( \Sigma \) is the covariance matrix, \( \mathbf{v} \) is the eigenvector (the direction of the component), and \( \lambda \) is the eigenvalue (the variance along that direction). Finding the principal components means solving this equation for \( \Sigma \).
The figure makes the idea immediate. The grey dots are two correlated variables: as X increases, Y tends to increase too. The red arrow (PC1) is the direction in which the data vary the most — it is the principal axis. The green arrow (PC2) is orthogonal and captures the remaining variance. This is the geometric idea of PCA: finding the axes that “explain” most of the variability in the data.
Explained variance. This is the metric that tells us how valuable each component is. The proportion of variance explained by a component is:
\( \text{variance explained}_k = \frac{\lambda_k}{\sum_{i=1}^{p} \lambda_i} \\ \)where \( \lambda_k \) is the eigenvalue of the \( k \)-th component and \( p \) is the total number of components. The cumulative explained variance is the sum of the first \( k \) proportions: it tells us how much original information we keep by retaining only \( k \) components.
As a side note: criteria like the Kaiser rule (keep only components with eigenvalue > 1) and the scree plot (the ordered eigenvalues graph, with the “elbow” as the cut-off point) help choose the number of components to retain.
PCA is a versatile technique with a wide range of applications. In image processing, it is used for compression. In genomics, it helps identify the most critical genes. In finance, for risk analysis and portfolio optimisation. In healthcare, for medical image analysis. In security, for biometric systems. In climatology, for analysing large environmental datasets.
For data analysis and marketing specifically, PCA makes it possible to simplify complex datasets, reduce noise, extract the most significant features, and improve the performance of predictive models. Its ability to visualise high-dimensional data in two or three dimensions makes it easier to spot patterns, trends and outliers.
An important clarification: PCA does not eliminate some variables while keeping others. Instead, it builds new variables — the principal components — obtained as linear combinations of the original ones. It is not feature selection: it is feature extraction. The difference is subtle but crucial.
Let’s see how PCA applies to concrete problems in our daily work.
Keyword analysis. A keyword dataset has numerous metrics: search volume, competition, CPC, average position on Google and Bing. By applying PCA, we can condense these dimensions into a few components that capture the underlying themes. For example, we might find that one component captures the “potential value” of the keyword (high volume + high CPC) and another captures “competitiveness” (high competition + low ranking).
Traffic metric analysis. Sessions, bounce rate, time on page, conversions by source — PCA can reveal latent variables driving performance. One component might capture user engagement and another the effectiveness of different traffic sources.
User segmentation. By analysing behavioural data with many variables, PCA identifies natural groupings of users, enabling more defined segments.
Campaign performance analysis. Impressions, clicks, conversions, cost, CTR, CPA — PCA reveals the key factors that determine campaign success.
Let’s now run PCA on real data, with two examples that mirror the scenarios we just described.
First, let’s set up the keyword positioning data:
set.seed(123)
n_keywords <- 100
keywords <- paste0("keyword_", 1:n_keywords)
search_volume <- round(runif(n_keywords, min = 100, max = 10000))
competition <- runif(n_keywords, min = 0.1, max = 0.9)
cpc <- round(rnorm(n_keywords, mean = 2.5, sd = 1), 2)
ranking_google <- round(rnorm(n_keywords, mean = 15, sd = 10), 0)
ranking_bing <- round(rnorm(n_keywords, mean = 12, sd = 8), 0)
keyword_data <- data.frame(
Keyword = keywords,
Search_Volume = search_volume,
Competition = competition,
CPC = cpc,
Ranking_Google = ranking_google,
Ranking_Bing = ranking_bing
)
head(keyword_data) Result:
Keyword Search_Volume Competition CPC Ranking_Google Ranking_Bing
1 keyword_1 2947 0.5799912 1.79 37 6
2 keyword_2 7904 0.3662588 2.76 28 6
3 keyword_3 4149 0.4908904 2.25 12 4
4 keyword_4 8842 0.8635791 2.15 20 4
5 keyword_5 9411 0.4863219 1.55 11 9
6 keyword_6 551 0.8122802 2.45 10 15 Now the campaign performance data:
set.seed(456)
n_campaigns <- 50
campaign_ids <- paste0("campaign_", 1:n_campaigns)
impressions <- round(runif(n_campaigns, min = 1000, max = 100000))
clicks <- round(impressions * runif(n_campaigns, min = 0.01, max = 0.1))
conversions <- round(clicks * runif(n_campaigns, min = 0.005, max = 0.05))
cost <- round(clicks * runif(n_campaigns, min = 0.1, max = 2), 2)
ctr <- round((clicks / impressions) * 100, 2)
cpa <- round(cost / conversions, 2)
cpa[is.nan(cpa)] <- 0
campaign_data <- data.frame(
Campaign_ID = campaign_ids,
Impressions = impressions,
Clicks = clicks,
Conversions = conversions,
Cost = cost,
CTR = ctr,
CPA = cpa
)
head(campaign_data) Result:
Campaign_ID Impressions Clicks Conversions Cost CTR CPA
1 campaign_1 9866 873 14 1093.32 8.85 78.09
2 campaign_2 21841 1788 20 3360.17 8.19 168.01
3 campaign_3 73563 2866 66 2764.48 3.90 41.89
4 campaign_4 85361 4121 73 1422.12 4.83 19.48
5 campaign_5 79051 3432 133 1623.28 4.34 12.21
6 campaign_6 33864 3064 126 6047.70 9.05 48.00 Now run PCA with prcomp(). It is essential to scale the data (scale. = TRUE) before applying PCA: otherwise variables with larger scales (thousands of impressions vs fractions of CPC) would dominate the analysis.
If one variable is expressed in euros and another in percentages, PCA will be dominated almost entirely by the variable with the larger numerical scale. For this reason, in most cases it is essential to standardise the data before the analysis. It is the most common mistake made by those approaching PCA.
pca_keywords <- prcomp(keyword_data[, 2:6], scale. = TRUE)
summary(pca_keywords)
pca_campaigns <- prcomp(campaign_data[, 2:7], scale. = TRUE)
summary(pca_campaigns) Results:
# summary(pca_keywords) — keywords (5 variables, 5 components)
Importance of components:
PC1 PC2 PC3 PC4 PC5
Standard deviation 1.1381 1.0298 0.9894 0.9305 0.8941
Proportion of Variance 0.2591 0.2121 0.1958 0.1732 0.1599
Cumulative Proportion 0.2591 0.4712 0.6670 0.8401 1.0000
# summary(pca_campaigns) — campaigns (6 variables, 6 components)
Importance of components:
PC1 PC2 PC3 PC4 PC5 PC6
Standard deviation 1.7837 1.2229 0.9303 0.49392 0.4250 0.18138
Proportion of Variance 0.5303 0.2492 0.1442 0.04066 0.0301 0.00548
Cumulative Proportion 0.5303 0.7795 0.9238 0.96442 0.9945 1.00000 The figure tells the story better than the numbers. For keywords (left) the variance is fairly evenly distributed: the metrics are largely uncorrelated and PCA cannot compress them much without losing information. For campaigns (right), the first two components explain almost 80% of the variance — the metrics are strongly correlated and two dimensions suffice to describe nearly everything.
The enlarged plot on the campaign data confirms: PC1+PC2 exceed 80% cumulative variance. The dashed line at 80% is a common threshold — below it lie components that contribute little.
The loadings (pca_keywords\( rotation) show the correlation between original variables and components, helping interpret the meaning of each component. The scores (pca_keywords \)x) represent the projection of the original data onto the new space.
For further visualisation, you can use the scree plot (plot(pca_keywords)) and the biplot (biplot(pca_keywords)), which displays both scores and loadings in the plane of the first two components.
Interpreting principal components requires domain knowledge. If in the keyword data PCA the first component has high positive loadings for search volume and CPC, it might represent “high-potential keywords”. If the second component is dominated by ranking, it might represent “actual visibility”. Interpretation is always context-dependent.
Keep in mind that principal components do not have a “natural” meaning. They are mathematical constructs that we must interpret by looking at the loadings of the original variables. There is no predefined label for PC1: we have to build it, based on the data and the context.
It is important to keep PCA’s limitations in mind. It assumes linear relationships between variables, and it is sensitive to data scale (which is why we always scale before applying it). For non-linear relationships, techniques like t-SNE and UMAP may be more appropriate.
When does it make sense to use PCA?
When we have many correlated variables and want to reduce them to a few interpretable dimensions. It is ideal for exploration, visualisation, and pre-processing for machine learning. It does not make sense when variables are already few and independent.
How many components should I keep?
It depends on the cumulative explained variance. A rule of thumb: stop when the scree plot curve flattens (the “elbow”), or when cumulative variance reaches 70-80%. The Kaiser rule (eigenvalue > 1) is another criterion, but should be used flexibly.
Why do I need to scale the data before PCA?
Because PCA maximises variance. If one variable is measured in thousands (impressions) and another in hundredths (CTR), the first would artificially dominate the analysis. Scaling (mean 0, standard deviation 1) puts all variables on an equal footing.
Does PCA work with non-linear data?
No, standard PCA assumes linear relationships. For non-linear structures there are variants like Kernel PCA, or non-linear techniques such as t-SNE and UMAP.
Principal Component Analysis gives us an elegant way to untangle the complexity of our data. It reduces dimensionality, reveals hidden patterns, improves predictive models, and makes visualisable what would otherwise be a jumble of numbers.
Its power, however, also lies in its limitations: it works well when relationships are linear, requires scaling, and the interpretation of the components is our responsibility, not the algorithm’s. Used with awareness, it is one of the most versatile tools in the web marketing data analysis toolkit.
Principal Component Analysis is covered with exemplary clarity in An Introduction to Statistical Learning by James, Witten, Hastie and Tibshirani, alongside other unsupervised learning techniques.
It happens with every reasonably serious project: you export the keyword list from Search Console…
Anyone who spends their days inside Search Console knows that little nagging feeling: a page…
In the article on the multi-armed bandit we used Bayes to decide between variants: shifting…
In the article on Bayesian A/B testing we compared two variants at a fixed sample…
In the article on classic A/B testing we saw how to compare two variants with…
In the article on the foundations of Bayesian statistics, we saw how Bayesian updating works…