There are many ways to numerically summarize data. The fundamental idea is to describe the center, or most *probable* values of the data, as well as the spread, or the *possible* values of the data.

\[ \bar{x} = \frac{\sum_{i=1}^n x_i}{n} \]

**Measure of Center | 1 Quantitative Variable**

The “balance point” or “center of mass” of quantitative data. It is calculated by taking the numerical sum of the values divided by the number of values. Typically used in tandem with the standard deviation. Most appropriate for describing the most typical values for relatively normally distributed data. Influenced by outliers, so it is not appropriate for describing strongly skewed data.

To calculate a mean in R use the code:

`mean(object)`

`object`

must be a quantitative variable, what R calls a “numeric vector.”

If using `library(mosaic)`

then,

`mean(object ~ group, data=NameOfData)`

`object`

is a quanitative variable, which R calls a “numeric vector”.`group`

is a qualitative variable, which R calls a “character vector”, “factor”, and sometimes a “numeric vector”.`NameOfData`

is the name of the R dataset containing`object`

and`group`

.

**Example Code**

Hover your mouse over the example codes to learn more.

mean “mean” is an R function used to calculate the mean of data. ( Parenthesis to begin the function. Must touch the last letter of the function. airquality “airquality” is a dataset. Type “View(airquality)” in R to see it. $ The $ allows us to access any variable from the airquality dataset. Temp “Temp” is a quantitative variable (numeric vector) from the “airquality” dataset. )

Closing parenthsis for the mean function.

Press Enter to run the code if you have typed it in yourself. You can also click here to view the output. … Click to View Output.

library(mosaic) mosaic is an R Package that overlaods many R functions to improve their usefulness. The command: library(mosaic) loads the mosaic package.

mean( “mean” is an R function used to calculate the mean. Temp Temp is a quantitative variable (numeric vector) from the airquality dataset. ~ ~ is the tilde symbol. It is used to create a “forumla” in R. The quantitative variable is always on the left of the tilde. The grouping variable is on the right of the tilde. Month Month is a qualitative variable (technically a numeric vector) from the airquality dataset. May is 5, June is 6, and so on. , The comma allows us to specify optional commands to the “mean” function. The space after the comma is not required. It just looks nice. data=airquality data= is used to tell R to find the Temp and Month variables in the airquality dataset. ) Functions must always end with a closing parenthesis.

Press Enter to run the code. … Click to View Output.

The mathematical formula used to compute the mean of data is given by the formula to the left. Although the formula looks complicated, all it states is “add all the data values up and divide by the total number of values.” Read on to learn what all the symbols in the formula represent.

\(\bar{x}\) is read “x-bar” and is the symbol typically used for the

**sample mean**, the mean computed on a*sample*of data from a population.\(\Sigma\), the capital Greek letter “sigma,” is the symbol used to imply “add all of the data values up.”

The \(x_i\)’s are the data values. The \(i\) in the \(x_i\) is stated to go from \(i=1\) all the way up to \(n\). In other words, data value 1 is represented by \(x_1\), data value 2: \(x_2\), \(\ldots\), up through the last data value \(x_n\). In general, we just write \(x_i\).

\(n\) represents the sample size, or number of data values.

When **all** of the data from a population is available, the **population mean** is calculated instead of the sample mean. The mathematical formula for the **population mean** is the same as the formula for the sample mean, but is written with slightly different notation. \[
\mu = \frac{\sum_{i=1}^N x_i}{N}
\] Notice that the symbol for the population mean is \(\mu\), pronounced “mew,” another Greek letter. (Review your Greek alphabet.) The only other difference between the two formulas is that the sample mean uses a sample of data, denoted by \(n\), while the population mean uses all the population data, denoted by \(N\).

The mean is sometimes described as the “balance point” of the data. The following example will demonstrate.

Say there are \(n=5\) data points with the following values.

- \(x_1 = 2\)
- \(x_2 = 5\)
- \(x_3 = 6\)
- \(x_4 = 7\)
- \(x_5 = 10\)

The sample mean is calculated as follows. \[ \bar{x} = \frac{\sum_{i=1}^n x_i}{n} = \frac{2 + 5 + 6 + 7 + 10}{5} = 6 \] If these values were plotted, and an “infinitely thin bar” connected the points, then the bar would “balance” at the mean (the triangle) as shown below.

The above plot demonstrates that there are equal, but opposite, “sums of deviations” to either side of the mean. Note that a deviation is defined as the distance from the mean to a given point. Thus, \(x_1\) has a deviation of -4 from the mean, \(x_2\) a deviation of -1, \(x_3\) a deviation of 0, \(x_4\) a deviation of 1, and \(x_5\) a deviation of 4. To the left there is a sum of deviations equal to -5 and on the right, a sum of deviations equal to 5. This can be verified to hold for any scenario.

The mean can be strongly influenced by *outliers*, points that deviate abnormally from the mean. This is shown below by changing \(x_5\) to be 20. Note that the deviation of \(x_5\) is 12, and the sum of deviations to the left of the mean (\(\bar{x}=8\)) is \(-1 + -2 + -3 + -6 = -12\).

The mean of the altered data

- \(x_1 = 2\)
- \(x_2 = 5\)
- \(x_3 = 6\)
- \(x_4 = 7\)
- \(x_5 = 20\)

is now \(\bar{x} = \frac{\sum_{i=1}^n x_i}{n} = \frac{2 + 5 + 6 + 7 + 20}{5} = 8\).

\[
\frac{x_{(n/2)}+x_{(n/2+1)}}{2}
\]
\(\uparrow\) **even** \(n\) **odd** \(\downarrow\)

\[ x_{((n+1)/2)} \]

**Measure of Center | 1 Quantitative Variable**

The “middle data point,” i.e., the 50\(^{th}\) percentile. Half of the data is below the median and half is above the median. Typically used in tandem with the five-number summary to describe skewed data because it is not heavily influenced by outliers, i.e., it is *robust*. Can also be used with normally distributed data, but the mean and standard deviation are more useful measures in such cases.

To calculate a median in R use the code:

`median(object)`

`object`

must be a quantitative variable, what R calls a “numeric vector.”

If using `library(mosaic)`

then,

`median(object ~ group, data=NameOfData)`

`object`

is a quanitative variable, which R calls a “numeric vector”.`group`

is a qualitative variable, which R calls a “character vector”, “factor”, and sometimes a “numeric vector”.`NameOfData`

is the name of the R dataset containing`object`

and`group`

.

**Example Code**

Hover your mouse over the example codes to learn more.

median “median” is an R function used to calculate the median of data. ( Parenthesis to begin the function. Must touch the last letter of the function. airquality “airquality” is a dataset. Type “View(airquality)” in R to see it. $ The $ allows us to access any variable from the airquality dataset. Temp “Temp” is a quantitative variable (numeric vector) from the “airquality” dataset. )

Closing parenthsis for the median function.

Press Enter to run the code if you have typed it in yourself. You can also click here to view the output. … Click to View Output.

library(mosaic) mosaic is an R Package that overlaods many R functions to improve their usefulness. The command: library(mosaic) loads the mosaic package.

median( “median” is an R function used to calculate the median Temp Temp is a quantitative variable (numeric vector) from the airquality dataset. ~ ~ is the tilde symbol. It is used to create a “forumla” in R. The quantitative variable is always on the left of the tilde. The grouping variable is on the right of the tilde. Month Month is a qualitative variable (technically a numeric vector) from the airquality dataset. May is 5, June is 6, and so on. , The comma allows us to specify optional commands to the “median” function. The space after the comma is not required. It just looks nice. data=airquality data= is used to tell R to find the Temp and Month variables in the airquality dataset. ) Functions must always end with a closing parenthesis.

Press Enter to run the code. … Click to View Output.

The mathematical formula used to compute the median of data depends on whether \(n\), the number of data points in the sample, is even or odd.

If \(n\) is even, then there is no “middle” data point, so the middle two values are averaged. \[ \text{Median} = \frac{x_{(n/2)}+x_{(n/2+1)}}{2} \]

If \(n\) is odd, then the middle data point is the median. \[ \text{Median} = x_{((n+1)/2)} \]

There is no generally accepted symbol for the median. Sometimes a capital \(M\) or even lower-case \(m\) is used, but generally the word median is just written out.

\(x_{(n/2)}\) represents the data value that is in the \((n/2)^{th}\) position in the ordered list of values. It only exists when \(n\) is even.

\(x_{(n/2+1)}\) represents the data value that immediately follows the \((n/2)^{th}\) value in the ordered list of values. It only exists when \(n\) is even.

\(x_{((n+1)/2)}\) represents the data value that is in the \(((n+1)/2)^{th}\) position in the ordered list of values. It only exists when \(n\) is odd.

\(n\) represents the sample size, or number of data values in the sample.

When **all** of the data from a population is available, the **population median** is calculated by the above formulas with the slight change that \(N\), the total number of data values in the population, instead of \(n\), the number of values in the sample, is used.

If \(N\) is even, then there is no “middle” data point, so the middle two values are averaged. \[ \text{Median} = \frac{x_{(N/2)}+x_{(N/2+1)}}{2} \]

If \(N\) is odd, then the middle data point is the median. \[ \text{Median} = x_{((N+1)/2)} \]

The median is the \(50^{th}\) percentile of the data.

Say there are \(n=5\) data points in the sample with the following values.

- \(x_1 = 2\)
- \(x_2 = 5\)
- \(x_3 = 6\)
- \(x_4 = 7\)
- \(x_5 = 10\)

The sample median is calculated as follows. Note that \(n=5\) is odd. \[ \text{Median} = x_{((n+1)/2)} = x_{((5+1)/2)} = x_{(3)} = 6 \] When these values are plotted it is clear that exactly 50% of the data (excluding the median) is to either side of the median.

Say there was a sixth value in the data set equal to 10, so that \(n=6\) is even.

- \(x_1 = 2\)
- \(x_2 = 5\)
- \(x_3 = 6\)
- \(x_4 = 7\)
- \(x_5 = 10\)
- \(x_6 = 10\)

\[ \text{Median} = \frac{x_{(n/2)}+x_{(n/2+1)}}{2} = \frac{x_{(6/2)}+x_{(6/2+1)}}{2} = \frac{x_{(3)}+x_{(4)}}{2} = \frac{6+7}{2} = 6.5 \]

The median is not greatly influenced by *outliers*. It is said to be *robust*. This is shown below by changing \(x_6\) to be 20, which does not change the value of the median.

**Most**

**Frequent**

**Measure of Center | 1 Quantitative or Qualitative Variable**

The most commonly occurring value. There may be more than one mode. Seldom used, but sometimes useful.

R will not calculate a mode directly. However, to tabulate the number of times each value occurs in a dataset, use the code:

`table(object)`

`object`

can be quantitative or qualitative, but should contain at least one repeated value or`table()`

is not useful.

**Example Code**

Hover your mouse over the example codes to learn more.

table “table” is an R function used to count how many times each observation occurs in a list of data. ( Parenthesis to begin the function. Must touch the last letter of the function. airquality “airquality” is a dataset. Type “View(airquality)” in R to see it. $ The $ allows us to access any variable from the airquality dataset. Month “Month” is a qualitative variable (technically a numeric vector) from the “airquality” dataset that contains repeated values. )

Closing parenthsis for the function.

Press Enter to run the code if you have typed it in yourself. You can also click here to view the output. … Click to View Output.

\[ x_{(1)} \]

**Measure of Spread | 1 Quantitative Variable**

The smallest occurring data value. One of the numerical summaries in the five-number summary. Typically not useful on its own. Gives a good feel for the spread in the left tail of the distribution when used with the five-number summary.

To calculate a minimum in R use the code:

`min(object)`

`object`

must be a quantitative variable, what R calls a “numeric vector.”

If using `library(mosaic)`

then,

`min(object ~ group, data=NameOfData)`

`object`

is a quanitative variable, which R calls a “numeric vector”.`group`

is a qualitative variable, which R calls a “character vector”, “factor”, and sometimes a “numeric vector”.`NameOfData`

is the name of the R dataset containing`object`

and`group`

.

**Example Code**

Hover your mouse over the example codes to learn more.

min “min” is an R function used to calculate the minimum of data. ( Parenthesis to begin the function. Must touch the last letter of the function. airquality “airquality” is a dataset. Type “View(airquality)” in R to see it. $ The $ allows us to access any variable from the airquality dataset. Temp “Temp” is a quantitative variable (numeric vector) from the “airquality” dataset. )

Closing parenthsis for the function.

Press Enter to run the code if you have typed it in yourself. You can also click here to view the output. … Click to View Output.

library(mosaic) mosaic is an R Package that overlaods many R functions to improve their usefulness. The command: library(mosaic) loads the mosaic package.

min( “min” is an R function used to calculate the minimum Temp Temp is a quantitative variable (numeric vector) from the airquality dataset. ~ ~ is the tilde symbol. It is used to create a “forumla” in R. The quantitative variable is always on the left of the tilde. The grouping variable is on the right of the tilde. Month Month is a qualitative variable (technically a numeric vector) from the airquality dataset. May is 5, June is 6, and so on. , The comma allows us to specify optional commands to the “min” function. The space after the comma is not required. It just looks nice. data=airquality data= is used to tell R to find the Temp and Month variables in the airquality dataset. ) Functions must always end with a closing parenthesis.

Press Enter to run the code. … Click to View Output.

\[ x_{(n)} \]

**Measure of Spread | 1 Quantitative Variable**

The largest occurring data value. One of the numerical summaries in the five-number summary. Typically not useful on its own. Gives a good feel for the spread in the right tail of the distribution when used in the five-number summary.

To calculate a maximum in R use the code:

`max(object)`

`object`

must be a quantitative variable, what R calls a “numeric vector.”

If using `library(mosaic)`

then,

`max(object ~ group, data=NameOfData)`

`object`

is a quanitative variable, which R calls a “numeric vector”.`group`

is a qualitative variable, which R calls a “character vector”, “factor”, and sometimes a “numeric vector”.`NameOfData`

is the name of the R dataset containing`object`

and`group`

.

**Example Code**

Hover your mouse over the example codes to learn more.

max “max” is an R function used to calculate the maximum of data. ( Parenthesis to begin the function. Must touch the last letter of the function. airquality “airquality” is a dataset. Type “View(airquality)” in R to see it. $ The $ allows us to access any variable from the airquality dataset. Temp “Temp” is a quantitative variable (numeric vector) from the “airquality” dataset. )

Closing parenthsis for the function.

Press Enter to run the code if you have typed it in yourself. You can also click here to view the output. … Click to View Output.

library(mosaic) mosaic is an R Package that overlaods many R functions to improve their usefulness. The command: library(mosaic) loads the mosaic package.

max( “max” is an R function used to calculate the maximum Temp Temp is a quantitative variable (numeric vector) from the airquality dataset. ~ ~ is the tilde symbol. It is used to create a “forumla” in R. The quantitative variable is always on the left of the tilde. The grouping variable is on the right of the tilde. Month Month is a qualitative variable (technically a numeric vector) from the airquality dataset. May is 5, June is 6, and so on. , The comma allows us to specify optional commands to the “max” function. The space after the comma is not required. It just looks nice. data=airquality data= is used to tell R to find the Temp and Month variables in the airquality dataset. ) Functions must always end with a closing parenthesis.

Press Enter to run the code. … Click to View Output.

**25**\(^{th}\), **50**\(^{th}\), **75**\(^{th}\)

*and* **100**\(^{th}\)

**Measure of Center & Spread | 1 Quantitative Variable**

Good for describing the spread of data, typically for skewed distributions. There are four quartiles. They make up the ** five-number summary** when combined with the minimum. The second quartile is the median (50\(^{th}\) percentile) and the fourth quartile is the maximum (100\(^{th}\) percentile). The first quartile (\(Q_1\) or lower quartile) and third quartile (\(Q_3\) or upper quartile) show the spread of the “middle 50%” of the data, which is often called the

To calculate a five-number summary (and mean) in R use the code:

`summary(object)`

`object`

must be a quantitative variable, what R calls a “numeric vector.”

If using `library(mosaic)`

then,

`favstats(object ~ group, data=NameOfData)`

`object`

is a quanitative variable, which R calls a “numeric vector”.`group`

is a qualitative variable, which R calls a “character vector”, “factor”, and sometimes a “numeric vector”.`NameOfData`

is the name of the R dataset containing`object`

and`group`

.

Note: `favstats()`

provides the five-number summary along with the mean, standard deviation, sample size (n), and number of missing values.

**Example Code**

Hover your mouse over the example codes to learn more.

summary “summary” is an R function used to calculate the five-number summary (and mean) of data. ( Parenthesis to begin the function. Must touch the last letter of the function. airquality “airquality” is a dataset. Type “View(airquality)” in R to see it. $ The $ allows us to access any variable from the airquality dataset. Temp “Temp” is a quantitative variable (numeric vector) from the “airquality” dataset. )

Closing parenthsis for the function.

Press Enter to run the code if you have typed it in yourself. You can also click here to view the output. … Click to View Output.

library(mosaic) mosaic is an R Package that provides new R functions to improve the usefulness of R. The command: library(mosaic) loads the mosaic package.

favstats( “favstats” is a library(mosaic) function used to calculate the five-number summary, mean, standard deviation, sample size, and number of missing values all at once. Temp Temp is a quantitative variable (numeric vector) from the airquality dataset. ~ ~ is the tilde symbol. It is used to create a “forumla” in R. The quantitative variable is always on the left of the tilde. The grouping variable is on the right of the tilde. Month Month is a qualitative variable (technically a numeric vector) from the airquality dataset. May is 5, June is 6, and so on. , The comma allows us to specify optional commands to the “favstats” function. The space after the comma is not required. It just looks nice. data=airquality data= is used to tell R to find the Temp and Month variables in the airquality dataset. ) Functions must always end with a closing parenthesis.

Press Enter to run the code. … Click to View Output.

\(s = \sqrt{\frac{\sum_{i=1}^n(x_i-\bar{x})^2}{n-1}}\)

**Measure of Spread | 1 Quantitative Variable**

Measures how spread out the data are from the mean. It is never negative and typically not zero. Larger values mean the data is highly variable. Smaller values mean the data is consistent and not as variable. It is typically used with the mean to describe the spread of relatively normally distributed data. The order of operations in the formula is important and for this reason it is sometimes called the “root mean squared error,” though the calculations are performed in reverse of that. (Study the formula on the left to understand.) The denominator \(n-1\) is called the ** degrees of freedom**.

To calculate the standard deviation in R use the code:

`sd(object)`

`object`

must be a quantitative variable, what R calls a “numeric vector.”

If using `library(mosaic)`

then,

`sd(object ~ group, data=NameOfData)`

`object`

is a quanitative variable, which R calls a “numeric vector”.`group`

is a qualitative variable, which R calls a “character vector”, “factor”, and sometimes a “numeric vector”.`NameOfData`

is the name of the R dataset containing`object`

and`group`

.

**Example Code**

Hover your mouse over the example codes to learn more.

sd “sd” is an R function used to calculate the standard deviation of data. ( Parenthesis to begin the function. Must touch the last letter of the function. airquality “airquality” is a dataset. Type “View(airquality)” in R to see it. $ The $ allows us to access any variable from the airquality dataset. Temp “Temp” is a quantitative variable (numeric vector) from the “airquality” dataset. )

Closing parenthsis for the function.

Press Enter to run the code if you have typed it in yourself. You can also click here to view the output. … Click to View Output.

library(mosaic) mosaic is an R Package that overlaods many R functions to improve their usefulness. The command: library(mosaic) loads the mosaic package.

sd( “sd” is an R function used to calculate the standard deviation. Temp Temp is a quantitative variable (numeric vector) from the airquality dataset. ~ ~ is the tilde symbol. It is used to create a “forumla” in R. The quantitative variable is always on the left of the tilde. The grouping variable is on the right of the tilde. Month Month is a qualitative variable (technically a numeric vector) from the airquality dataset. May is 5, June is 6, and so on. , The comma allows us to specify optional commands to the “sd” function. The space after the comma is not required. It just looks nice. data=airquality data= is used to tell R to find the Temp and Month variables in the airquality dataset. ) Functions must always end with a closing parenthesis.

Press Enter to run the code. … Click to View Output.

Data often varies. The values are not all the same. To capture, or measure how much data varies with a single number is difficult. There are a few different ideas on how to do it, but by far the most used measurement of the variability in data is the standard deviation.

The first idea in measuring the variability in data is that there must be a reference point. Something from which everything varies. The most widely accepted reference point is the mean.

A **deviation** is defined as the distance an observation lies from the reference point, the mean. This distance is obtained by subtraction in the order \(x_i - \bar{x}\), where \(x_i\) is the data point value and \(\bar{x}\) is the mean of the data. There are thus \(n\) deviations because there are \(n\) data points.

Unfortunately, because of the order of subtraction in obtaining deviations, the average deviation will always work out to be zero. This is because the mean by nature splits the deviations evenly. Click here for details.

One solution would be to take the absolute value of the deviations and obtain what is known as the “absolute mean deviation.” This is sometimes done, but a far more attractive choice (to mathematicians and statisticians) is to square each deviation. You’ll have to trust us that this is the better choice.

Squaring a deviation results in the expression \((x_i-\bar{x})^2\). **SQUARE**

Summing up all of the squared deviations results in the expression \(\sum_{i=1}^n (x_i-\bar{x})^2\).

Dividing the sum of the squared deviations by \(n\) would seem like an appropriate thing to do. Experience (and some fantastic statistical theory!) demonstrated that this is wrong. Dividing by \(n-1\), the *degrees of freedom* is right. **MEAN**

To undo the squaring of the deviations, the final results are square rooted. **ROOT**

The end result is the beautiful formula for \(s\), the standard deviation! (At least the symbol for standard deviation is a simple \(s\).) It is also know as the **ROOT-MEAN-SQUARED ERROR**. Error is another word for deviation.

\[ s = \sqrt{\frac{\sum_{i=1}^n(x_i-\bar{x})^2}{n-1}} \]

The *standard deviation* is thus the representative deviation of all deviations in a given data set. It is never negative and only zero if all values are the same in a data set. Larger values of \(s\) imply the data is highly variable, very spread out or very inconsistent. Smaller values mean the data is consistent and not as variable.

When **all** of the data from a population is available, the **population standard deviation** \(\sigma\) (the lower-case Greek letter “sigma”) is calculated by the following formula.

\[ \sigma = \sqrt{\frac{\sum_{i=1}^N(x_i-\mu)^2}{N}} \]

Note that \(N\) is the number of data points in the full population. In this formula the denominator is actually \(N\) and the deviations are calculated as the distance each data point is from the population mean \(\mu\).

Say there are five data points given by

- \(x_1 = 2\)
- \(x_2 = 5\)
- \(x_3 = 6\)
- \(x_4 = 7\)
- \(x_5 = 10\)

The mean of these values is \(\bar{x}=6\) as shown here.

The five deviations are

- \((x_1 - \bar{x}) = (2 - 6) = -4\)
- \((x_2 - \bar{x}) = (5 - 6) = -1\)
- \((x_3 - \bar{x}) = (6 - 6) = 0\)
- \((x_4 - \bar{x}) = (7 - 6) = 1\)
- \((x_5 - \bar{x}) = (10 - 6) = 4\)

The squared deviations are

- \((x_1 - \bar{x})^2 = (2 - 6)^2 = (-4)^2 = 16\)
- \((x_2 - \bar{x})^2 = (5 - 6)^2 = (-1)^2 = 1\)
- \((x_3 - \bar{x})^2 = (6 - 6)^2 = (0)^2 = 0\)
- \((x_4 - \bar{x})^2 = (7 - 6)^2 = (1)^2 = 1\)
- \((x_5 - \bar{x})^2 = (10 - 6)^2 = (4)^2 = 16\)

The sum of the squared deviations is

\[ \sum_{i=1}^n (x_i-\bar{x})^2 = 16 + 1 + 0 + 1 + 16 = 34 \]

Dividing this by the degrees of freedom, \(n-1\), gives

\[ \frac{\sum_{i=1}^n (x_i-\bar{x})^2}{n-1} = \frac{34}{5-1} = \frac{34}{4} = 8.5 \]

Finally, \(s\) is obtained by taking the square root

\[ s = \sqrt{\frac{\sum_{i=1}^n(x_i-\bar{x})^2}{n-1}} = \sqrt{8.5} \approx 2.915 \]

The red lines below show how the standard deviation represents all deviations in this data set. Recall that the magnitudes of the individual deviations were \(4, 1, 0, 1\), and \(4\). The representative deviation is \(2.915\).

Like the mean, the standard deviation is influenced by outliers. This is shown below by changing \(x_5\) to be 20. Note that the deviation of \(x_5\) is now 12 (instead of 4 like it was previously) and that the mean is now \(8\) (as shown here). The standard deviation of the altered data

- \(x_1 = 2\)
- \(x_2 = 5\)
- \(x_3 = 6\)
- \(x_4 = 7\)
- \(x_5 = 20\)

is now \(s \approx 6.964\). Not very “representative” of all the deviations. It is biased towards the largest deviation. It is important to be aware of outliers when reporting the standard deviation \(s\).

\[s^2 = \frac{\sum_{i=1}^n(x_i-\bar{x})^2}{n-1}\]

**Measure of Spread | 1 Quantitative Variable**

Great theoretical properties, but seldom used when describing data. Difficult to interpret in context of data because it is in squared units. The standard deviation is typically used instead because it is in the original units and is thus easier to interpret.

To calculate the variance in R use the code:

`var(object)`

`object`

must be a quantitative variable, what R calls a “numeric vector.”

If using `library(mosaic)`

then,

`var(object ~ group, data=NameOfData)`

`object`

is a quanitative variable, which R calls a “numeric vector”.`group`

is a qualitative variable, which R calls a “character vector”, “factor”, and sometimes a “numeric vector”.`NameOfData`

is the name of the R dataset containing`object`

and`group`

.

**Example Code**

Hover your mouse over the example codes to learn more.

var “var” is an R function used to calculate the variance of data. ( Parenthesis to begin the function. Must touch the last letter of the function. airquality “airquality” is a dataset. Type “View(airquality)” in R to see it. $ The $ allows us to access any variable from the airquality dataset. Temp “Temp” is a quantitative variable (numeric vector) from the “airquality” dataset. )

Closing parenthsis for the function.

Press Enter to run the code if you have typed it in yourself. You can also click here to view the output. … Click to View Output.

library(mosaic) mosaic is an R Package that overlaods many R functions to improve their usefulness. The command: library(mosaic) loads the mosaic package.

var( “var” is an R function used to calculate the variance. Temp Temp is a quantitative variable (numeric vector) from the airquality dataset. ~ ~ is the tilde symbol. It is used to create a “forumla” in R. The quantitative variable is always on the left of the tilde. The grouping variable is on the right of the tilde. Month Month is a qualitative variable (technically a numeric vector) from the airquality dataset. May is 5, June is 6, and so on. , The comma allows us to specify optional commands to the “var” function. The space after the comma is not required. It just looks nice. data=airquality data= is used to tell R to find the Temp and Month variables in the airquality dataset. ) Functions must always end with a closing parenthesis.

Press Enter to run the code. … Click to View Output.

\[x_{(n)}-x_{(1)}\]

**Measure of Spread | 1 Quantitative Variable**

The difference between the maximum and minimum values. A general rule of thumb is that the range divided by four is roughly the standard deviation. Quick to obtain, but not as good as using the standard deviation. Was used more frequently before the advent of modern calculators.

R will not automatically compute the range. It is easiest to compute the `max()`

and `min()`

and perform the subtraction `max`

- `min`

yourself.

**Measure of Location | 1 Quantitative Variable**

The percent of data that is equal to or less than a given data point. Useful for describing the relative position of a data point within a data set. If the percentile is close to 100, then the observation is one of the largest. If it is close to zero, then the observation is one of the smallest.

To compute the quantile in R for a given percentile:

`quantile(object, percentile)`

`object`

must be a quantitative variable, or as R terms it, a “numeric vector”.`percentile`

must be a value between 0 and 1 or a “numeric vector” of such values.

quantile( “quantile” is an R function used to calculate the data value corresponding to a given percentile. airquality$Temp Temp is a quantitative variable (numeric vector) being accessed from the airquality dataset with the $ sign. , Comma separating the two commands of the quantile function. 0.8 The value of 0.8 specifies the 80th percentile. Any other value from 0 to 1 inclusive could be used. ) Functions must always end with a closing parenthesis.

Press Enter to run the code. … Click to View Output.

\[\hat{p}=\frac{x}{n}\]

**Measure of Center | 1 Qualitative Variable**

The percent of observations in the data that satisfy some requirement. Obtained by dividing the number of *successes* \(x\) by the number of total observations \(n\). Often referred to as a percentage.

\(r = \frac{\textstyle\sum\left(\frac{x-\bar{x}}{s_x}\right)\left(\frac{y-\bar{y}}{s_y}\right)}{n-1}\)

**Measure of Association | 2 Quantitative Variables**

Describes the strength and direction of the association between two quantitative variables. Restricted to values between -1 and 1. A value of zero denotes no association between the two variables. A value of 1 or -1 implies a perfect positive or perfect negative association, respectively.

To calculate the correlation in R use the code:

`cor(object1,object2)`

`object1`

and`object2`

must both be a quantitative variables, what R calls “numeric vectors.”

If using `library(mosaic)`

then,

`cor(object1 ~ object2, data=NameOfData)`

`object1`

and`object2`

are quanitative variables, which R calls a “numeric vectors”.`NameOfData`

is the name of the R dataset containing`object`

and`group`

.

**Example Code**

Hover your mouse over the example codes to learn more.

cor “cor” is an R function used to calculate the standard deviation of data. ( Parenthesis to begin the function. Must touch the last letter of the function. airquality “airquality” is a dataset. Type “View(airquality)” in R to see it. $ The $ allows us to access any variable from the airquality dataset. Temp “Temp” is a quantitative variable (numeric vector) from the “airquality” dataset. , The comma is needed to separate the two quantitative variables of the cor() function. The space after the comma is not required. It just looks nice. airquality “airquality” is a dataset. Type “View(airquality)” in R to see it. $ The $ allows us to access any variable from the airquality dataset. Month “Month” is a quantitative variable (numeric vector) from the “airquality” dataset. )

Closing parenthsis for the function.

Press Enter to run the code if you have typed it in yourself. You can also click here to view the output. … Click to View Output.

library(mosaic) mosaic is an R Package that overlaods many R functions to improve their usefulness. The command: library(mosaic) loads the mosaic package.

cor( “cor” is an R function used to calculate the correlation of two quantitative variables. Temp Temp is a quantitative variable (numeric vector) from the airquality dataset. ~ ~ is the tilde symbol. It is used to create a “forumla” in R. The quantitative variable is always on the left of the tilde. The grouping variable is on the right of the tilde. Month Month can be considered a quantitative variable because it is a numeric vector from the airquality dataset. May is 5, June is 6, and so on. , The comma allows us to specify optional commands to the “cor” function. The space after the comma is not required. It just looks nice. data=airquality data= is used to tell R to find the Temp and Month variables in the airquality dataset. ) Functions must always end with a closing parenthesis.

Press Enter to run the code. … Click to View Output.