1.7 Summation
The summation of \(n\) numbers \(x_1, x_2, ..., x_n\) is represented by \(\sum_{i=1}^n {x_i} = x_1 + x_2 + \dotsb + x_n\), and reads ‘sum of x \(i\) from one to n’.
Example 1.6 (Number of steps) Suppose the variable \(X\): ‘number of steps to the nearest trash can’ was observed in the city of Porto Alegre on \(n = 6\) occasions, as shown in the table below.
\(x_{1}\) | \(x_{2}\) | \(x_{3}\) | \(x_{4}\) | \(x_{5}\) | \(x_{6}\) |
---|---|---|---|---|---|
186 | 402 | 191 | 20 | 7 | 124 |
This table indicates that on the first occasion, 186 steps were walked to locate a trash can (represented by \(x_1=186\)), on the second occasion, 402 steps were walked (represented by \(x_2=402\)), and so on. To calculate the total number of steps walked, you can do
\[\begin{equation} \sum_{i=1}^6 {x_i} = x_1 + x_2 + \dotsb + x_6 = 186+402+191+20+7+124 = 930 \tag{1.1} \end{equation}\]
## [1] 930
x <- c(186,402,191,20,7,124) # We can create a vector and assign it to x
sum(x) # Using the 'sum' function, presented in Equation (1.1)
## [1] 930
## [1] 248506
The Greek letter \(\sum\) is the capital sigma, as per Section 1.9.1. In many cases the summation symbology is simplified, using \(\sum\), \(\sum_{x}\) or \(\sum_{i}\). Below are some more advanced examples of more sophisticated use of summation, which can be omitted on a first read.
\[\begin{equation} \sum_{i=1}^n x_{i}^2 = x_{1}^2 + x_{2}^2 + \ldots + x_{n}^2 \tag{1.2} \end{equation}\]
Exercise 1.5 Consider the database available in the coronavirus
11 package as per the following code.
library(coronavirus) # calling the library 'coronavirus'
data(coronavirus) # leaving the database available
dim(coronavirus) # database dimensions (rows x columns)
## [1] 973836 15
## date province country lat long type cases uid iso2
## 1 2020-01-22 Alberta Canada 53.9333 -116.5765 confirmed 0 12401 CA
## 2 2020-01-23 Alberta Canada 53.9333 -116.5765 confirmed 0 12401 CA
## 3 2020-01-24 Alberta Canada 53.9333 -116.5765 confirmed 0 12401 CA
## 4 2020-01-25 Alberta Canada 53.9333 -116.5765 confirmed 0 12401 CA
## 5 2020-01-26 Alberta Canada 53.9333 -116.5765 confirmed 0 12401 CA
## 6 2020-01-27 Alberta Canada 53.9333 -116.5765 confirmed 0 12401 CA
## iso3 code3 combined_key population continent_name continent_code
## 1 CAN 124 Alberta, Canada 4413146 North America NA
## 2 CAN 124 Alberta, Canada 4413146 North America NA
## 3 CAN 124 Alberta, Canada 4413146 North America NA
## 4 CAN 124 Alberta, Canada 4413146 North America NA
## 5 CAN 124 Alberta, Canada 4413146 North America NA
## 6 CAN 124 Alberta, Canada 4413146 North America NA
- Get the sum of
cases
registered over the entire period.
- Obtain the squared sum of cases recorded over the entire period.
- Get the sum of cases registered over the entire period divided by
type
.
- Considering the variable \(X\): ‘number of registered cases’ in
nrow(coronavirus)
database rows, represent the items a. and b. using summation notation.
- Get the number of days between the first record available in
date
and the current date using thelubridate
package.
Johns Hopkins University Center for Systems Science and Engineering (JHU CCSE). https://systems.jhu.edu/research/public-health/ncov↩︎