![]() |
Statistics plays an important role in data handling and analysis. Many such concepts are used to understand the nature of data, one of which is the Sum of Squared Deviations. It is a fundamental quantity in stats that helps in understanding the variability in our dataset. In this article, we will understand how to calculate SSD mathematically and in R Programming Language. Understanding Sum of Squared DeviationsThe Sum of Squared Deviation measures the deviation of data points from the mean data point. This helps us understand the dispersion of our data points. The mathematical formula to calculate SSD is: SSD= ∑ni=1 (xi -xmean )2
where:
Interpreting SSD
Need to calculate SSDThere are many objectives behind calculating SSD. They are mentioned below:
Verification of SSD using R and mathematicsConsider a simplified dataset: [2,4,4,4,5]. We will calculate SSD mathematically as well as using R language. Firstly, we need to calculate the mean.
We can also verify it using R: R
Output: [1] "Sum of Squared Deviations (SSD) for example data: 4.8"
Calculating SSD of TemperatureIn this example, we will use multiple ways to calculate SSD of a fictional dataset. This dataset represents daily temperature of a certain city over a month. R
Output: Day Temperature
1 1 72.19762
2 2 73.84911
3 3 82.79354
4 4 75.35254
5 5 75.64644
6 6 83.57532
Calculating SSD using formulaNow to calculate SSD with the help of formula we will consider the following given code. We can calculate SSD directly but here we will also print the mean values. R
Output: [1] "Mean Daily Temperature: 75.1593605854571"
[1] "Sum of Squared Deviations (SSD) for Daily Temperature: 8520.02456165882"
Calculating SSD using Matrix AlgebraWe can calculate SSD using matrix algebra as well, it will give the same value. R
Output: [1] "Matrix Algebra SSD: 8520.02456165883"
Calculating SSD of mtcars datasetWe can calculate the SSD of the famous in-built dataset in R. This dataset contains information about different cars and their models. R
Output: [1] "Sum of Squared Deviations (SSD): 1126.0471875"
Here, we calculated the SSD value for mpg column present in our dataset. We can also visualize these points on a scatter plot using ggplot2 library. R
Output: ![]() Calculating Sum Of Squared Deviations In R ConclusionIn this article, we calculated SSD using different datasets and we also verified it mathematically. |
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 16 |