Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Removing Outliers Using Z-Score Method | Basic Statistical Analysis
Data Analysis with R

bookRemoving Outliers Using Z-Score Method

One common method for detecting and removing outliers is the z-score method. This technique identifies how far a data point is from the mean in terms of standard deviations. If a data point lies beyond a certain threshold (commonly Β±3), it is considered an outlier.

What Is a Z-Score?

A z-score (also known as a standard score) is calculated using the formula:

Z=Xβˆ’ΞΌΟƒZ = \frac{X - \mu}{\sigma}

Where:

  • XX: the original data point;
  • ΞΌ\mu: the mean of the dataset;
  • Οƒ\sigma: the standard deviation of the dataset.

Calculating Z-Scores

You can either compute z-scores manually by following the formula:

mean_cgpa <- mean(df$cgpa)
sd_cgpa <- sd(df$cgpa)
df$cgpa_zscore <- (df$cgpa - mean_cgpa) / sd_cgpa

Or you can use the built-in function:

df$cgpa_zscore <- scale(df$cgpa)

Identifying Outliers

After calculating the z-scores, you can choose a threshold (Β±3 in this case) and apply a simple filtering operation to select all entries outside of the range:

thresh_hold <- 3
outliers <- df[df$cgpa_zscore > thresh_hold | df$cgpa_zscore < -thresh_hold, ]

Or you can select all entries inside the range to create an outlier-free dataset:

df2 <- df[df$cgpa_zscore < thresh_hold & df$cgpa_zscore > -thresh_hold, ]
question mark

What happens to values with z-scores beyond Β±3?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 3

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Awesome!

Completion rate improved to 4

bookRemoving Outliers Using Z-Score Method

Swipe to show menu

One common method for detecting and removing outliers is the z-score method. This technique identifies how far a data point is from the mean in terms of standard deviations. If a data point lies beyond a certain threshold (commonly Β±3), it is considered an outlier.

What Is a Z-Score?

A z-score (also known as a standard score) is calculated using the formula:

Z=Xβˆ’ΞΌΟƒZ = \frac{X - \mu}{\sigma}

Where:

  • XX: the original data point;
  • ΞΌ\mu: the mean of the dataset;
  • Οƒ\sigma: the standard deviation of the dataset.

Calculating Z-Scores

You can either compute z-scores manually by following the formula:

mean_cgpa <- mean(df$cgpa)
sd_cgpa <- sd(df$cgpa)
df$cgpa_zscore <- (df$cgpa - mean_cgpa) / sd_cgpa

Or you can use the built-in function:

df$cgpa_zscore <- scale(df$cgpa)

Identifying Outliers

After calculating the z-scores, you can choose a threshold (Β±3 in this case) and apply a simple filtering operation to select all entries outside of the range:

thresh_hold <- 3
outliers <- df[df$cgpa_zscore > thresh_hold | df$cgpa_zscore < -thresh_hold, ]

Or you can select all entries inside the range to create an outlier-free dataset:

df2 <- df[df$cgpa_zscore < thresh_hold & df$cgpa_zscore > -thresh_hold, ]
question mark

What happens to values with z-scores beyond Β±3?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 3. ChapterΒ 3
some-alt