Sunday, November 29, 2015

Two methods for finding outliers


There are two methods for finding outliers, numbers that are far away from "the middle". If we count the middle as the median, we use the five number summary to find the threshold for high and low outliers. If we have the average, we will need to calculate the standard deviation for a sample sx, and find the z-score. With a calculator, this is very simple, but it can also be done by hand with small sets.

The five number summary

 Here is a list of the number of win for the Pac-12 teams as of November 29, 2015. Obviously, the length of the list is 12.

8, 7, 6, 4, 4, 0, 6, 6, 5, 4, 3, 1

We need to put the list in order, either top-to-bottom or bottom-to-top. Since the 8 is the first number on the list, let's go top-to-bottom.

8, 7, 6, 6, 6, 5, 4, 4, 4, 3, 1, 0

The five number summary are the high and low values - very easy, and the Quartiles, Q3, Q2 and Q1. We already know how to get Q2, because it is the median. Q3 is the median of the top half of the data and Q1 is the median of the bottom half of the data. Because there are 12 items on the list, it splits into the top six and the bottom six, and the median is the average of the two middle values.

8, 7, 6, 6, 6, 5 || 4, 4, 4, 3, 1, 0

The median Q2 is (5+4)/2 = 4.5

Q3: For the top half, the median is between the first 6 and the second 6, so it is 6.

Q1: For the bottom half, the median is between the 4 and the 3, so the median is (4+3)/2 = 3.5

High = 8
Q3 = 6
Q2 = 4.5
Q1 = 3.5
Low = 0

Next we get the IQR = Q3 - Q1, which in our instance is 6 - 3.5 = 2.5

The high threshold for outliers is Q3 + 1.5*IQR, or 6 + 1.5*2.5 = 6 + 3.75 = 9.75.  This threshold is above 8, so 8 is not an outlier.

The low threshold for outliers is Q1 - 1.5*IQR, or 3.5 - 1.5*2.5 = 3.5 - 3.75 = -0.25.  This threshold is just barely below 0, so 0 is not an outlier.

The z-score method

We know how to take z-scores if we have the average and standard deviation, but here we are going to have to compute the average and standard deviation instead of them being given. Average isn't hard by hand with smallish data sets, and if you have a calculator that is set up for statistics, both the standard deviation and average are given to you as quickly as you can input the set. If you don't have a calculator. Here is what we need to do.

1. Find the sum of the list, which we will call sum(x).

In our case, it's 8+7+6+6+6+5+4+4+4+3+1+0 = 54

2. Find the sum of the squares of the list, which we will call sum(x²) 

In our case, it's 64+49+36+36+36+25+16+16+16+9+1+0 = 304

3. Then we get  sum(x²) - [sum(x)]²/n

This is 304 - 54²/12 = 304 - 243 = 61

4. The standard deviation is the square root of the value from step 3 divided by n-1.

sqrt(61/11) ~= 2.35487881..., which we can round to 2.35.

The average is 54/12 = 4.5 

To be a high outlier, we need a z-score over 2. To be a low outlier, we need a z-score under -2.


z(8) = (8-4.5)/2.35 ~= 1.48936..., which isn't above 2, so it's not an outlier.

z(0) = (0-4.5)/2.35 ~= =1.91489..., which isn't below -2, so it's not a low outlier, but it was close.

With this particular set, our two methods agreed there were no outliers. The methods sometimes disagree. We can have sets with just high outliers, just low outliers, outliers in both directions or no outliers at all.

Sunday, November 15, 2015

Notes on the metric system



The United States uses a measurement system originated in Great Britain, which is sometimes called the Imperial system or the customary system. The relationships between measurements aren't very user friendly, and even Americans aren't very good at remembering all of them, according to tests I gave students at the beginning of classes years ago.

Here are some examples of the stuff you have to remember.

Length
12 inches = 1 foot
3 feet = 1 yard
5,280 feet = 1 mile

There are also odd measurements that very few people use any more, like rods, fathoms, furlong and nautical miles.

Volume

Of all the parts of the system This one makes some sense because the next biggest named measurement is almost always a factor of 2 away, either 2, 4 or 8 times bigger. Let's start with the fluid ounce (fl. oz.) as the basic unit.

8 fl. oz. = 1 cup (8 fl. oz.)
2 cups = 1 pint (16 fl. oz.)
2 pints = 1 quart (32. fl. oz.)
4 quarts = 1 gallon (128 fl. oz.)

Yay, powers of two! Unfortunately it breaks down as we get smaller than a fluid ounce.

2 tablespoons = 1 fl. oz.
3 teaspoons = 1 tablespoon

Another way in the system to measure volume is the cubic inch. This is not related nicely to the fluid ounce, as 1 cubic inch = 0.554413... fluid ounces.

Weight
16 ounces = 1 pound or lb.
2,000 lbs. = 1 ton

There are also little used units like a hundredweight (100 lbs.), a stone (14 lbs.) and a long hundredweight (8 stone or 112 lbs.). When we get smaller than an ounce, the standard is a grain. 7,000 grains is a pound, which means 437.5 grains is equal to an ounce.

The metric system

Unlike the customary system, which was thrown together over time, the metric system was made all at the same time, so length is related to volume and volume is related to weight using water as the standard thing we will weigh. All you need to learn for most measuring are three words and three prefixes for most stuff.

Length 
The standard length unit is the meter or m. 10,000,000 meters is the distance from the equator to the North Pole.

The important prefixes here. For long distances that Americans would measure in miles, the metric system uses kilometers or km. Kilo means "1,000", so this is 1,000 meters.

For short distances Americans would measure in inches, the metric system uses centimeters or cm, which is 1/100 of a meter.

For even smaller lengths where Americans would use fractions of inches, the metric standard is a millimeter, which is 1/1000 meters.

Volume
The standard measurement for volume is the liter or L. It is based on a cube 1/10 or a meter (or 10 cm) on each side. The liter is just slightly larger than a quart.

When dealing with very large volumes, the unit is still the liter.

For smaller volumes, the standard unit is the milliliter or mL. This is a cube one centimeter on each side, so it is also also called a cubic centimeter or cc.

Weight
The basic unit of weight is a gram, which is the weight of a cc of water at about 4 degrees Celsius, or about 39.2 degrees Fahrenheit. The temperature was chosen as the lowest point where at normal pressure, water shows no sign of freezing.

The gram is very small, so when measuring things the customary system would measure in pounds, the metric system uses kilograms or kg. A kilogram is slightly more than 2 pounds, and for very heavy weights that Americans would measure in tons, the metric system users resort to metric tons, which are 1,000 kg. (technically, this would be a megagram, but this word is almost never used.)

As small as the gram is, some small measurements like medicine doses are doled out in milligrams or mg. When medicine is measured, not even Americans use ounces or grains, though when I was a kid, grains were used on aspirin packages. One gram is about 15 grains and sometimes there was confusion, leading to massive overdoses or underdoses.

Conversion values

We only need a single conversion number, and depending which direction the conversion is in, we either multiply by the conversion number or divide by it. Here is an example.

1 inch = 2.54 centimeters (cm)

If we have 40 inches, the 40 is related to the 1, so 40/1 = x/2.54. With fractions, we cross-multiply to get 40*2.54 = x*1, so x = 101.6 cm. If we are asked to round to the nearest whole number, it would be 102 cm.

If instead we have 40 cm, the fraction would be x/1 = 40/2.54 = 15.7480315... inches, which could round to 16 inches, 15.7 inches or 15.75 inches, depending on the level of rounding.

Here are some of the standard numbers used for conversion.

Length, middle distances: 1 meter = 3.2808 feet or 39.37 inches
Length, long distances: 1 kilometer = 0.6214 miles

Weight, small weights: 1 gram = 0.03527 ounces
Weight, medium weights: 1 kilogram = 35.27 ounces = 2.2046 pounds
Weight, large weights: 1 metric ton = 2,204.6 pounds = 1.1023 metric tons

Volume, small measures: 1 milliliter = 0.033814 fluid ounces
Volume, medium to large measures: 1 liter = 33.814 fluid ounces = 1.0567 quarts
Volume, liters to cubic inches or cubic feet: 1 liter = 61.0237 cubic inches = 0.0353 cubic feet


Tuesday, November 10, 2015

Compound interest
Effective interest rates
Doubling periods and half lifes
The Consumer Price Index
Monthly payments on loans


A lot of the math of "the real world" is linear, but some of it involves exponents. The best known interest rate situations are those of a savings account. Here is the equation; instead of using superscripts for exponents, I use the symbol ^, which is the symbol for exponentiation on most of the TI calculators, though some have an "x rasied to the y" button.

Compound interest rate equation

A(t) = P(1+r)^t

A(t) is the amount in the bank at time t
P is the original principle invested 
r is the rate of interest, usually given as a percent


Effective rate compound interest rate equation

Some saving institutions will give the rate as "4% compounded quarterly". This is slightly different from 4% a year. If we use n as the number of compounding periods in a year, the equation changes to 

A(t) = P(1+r/n)^nt

4% compounded quarterly

In the stated example (1+.04/4)^4 = (1.01)^4 = 1.04060401, so the rate r = .04060401, usually rounded to the nearest hundredth of a percent at 4.06%. The difference is small but noticeable over long stretches of time.


$1000 invested at 4% over 20 years is $2,191.12
$1000 invested at 4% compounded quarterly over 20 years is $2,216.72

Doubling periods and half lifes

How long will it take at 4% to turn $1000 into $2000. This amount of time is called the doubling period and is found by the formula log(2)/log(1 + r)

In our case, that would be log(2)/(1 + .04) = 17.6729.....

If the bank is actually compounding annually, the amount only changes on the anniversary of your putting the money in.

After 17 years you have (1.04)^17 = $1,947.90
After 18 years you have (1.04)^18 = $2,025.82

The Consumer Price Index

This week, students got a green handout sheet with the consumer price index number for the years 1950 to 2015.  The simplest way to use it goes as follows.

How did prices change from 1960 to 1980? We use the two CPI values.

CPI(1960) = 29.6
CPI(1980) = 82.4

82.4/29.6 = 2.78378.....

29.6/82.4 = .35922...

What these numbers mean is that on average, a $10 item in 1960 sold for 10*2.78378... = $27.84 in 1980, while a $10 item in 1980 would have sold for 10*.35922... = $3.59.

We can use this to figure out the cost of living increase in any given year by dividing the CPI for that year by the CPI for the previous year.  For example, the rate in 1975 would be

CPI(1975)/CPI(1974) = 53.8/49.3 = 1.09127789... This is 1 + rate, so rounded to the nearest tenth of a percent we would have 9.1% and to the nearest hundredth of a percent it would be 9.13%.

Let's look at the number CPI(1980)/CPI(1960) = 2.783783... This gives us how much prices increased in the 20 year period from 1961 to 1980. To get the average increase over those 20 years, we take (2.783783)^(1/20) = 1.05252... This is 1 + rate, so the average rate = .05252... or 5.3% if rounded to the nearest tenth of a percent and 5.25% rounded to the nearest hundredth.



Monthly payments on loans

If you know the interest rate r, the number of years y you will take to pay off a loan and the amount you wish to borrow A. The formula for the monthly payment is

Monthly payment = A(1 + ry)/(12y)

We can use this to figure out monthly payments or, if we know how much we are willing to pay a month, the rate and the numbers of years we can get the loan for, conversely we can get the amount A with the formula

A = 12y(Monthly payment)/(1 + ry)

Practice problems

a) If you put $1,000 in the bank invested at 4.5%, how much will you have in 10 years?


b) If you put $1,000 in the bank invested at 4.5%, how much will you have in 15 years?


c) what is the effective rate of 5.5% compounded monthly?

d) what is the effective rate of 5.5% compounded daily?

e) A radioactive isotope loses 0.1% of its radioactivity every year. What is the half-life, rounded to the nearest tenth of a year?

f) The worst of inflation in last century in the United States happened in the 1970s and early 1980s. Find the average inflation rates for the following presidential terms. (Remember to start with the year prior to the start of the term.

1. Nixon (1969-1974)
2. Ford (1974-1976)
3. Carter(1977-1980)
4. Reagan(1981-1988)

g) If you borrow $20,000 at 6% and have a ten year loan, what is the monthly payment?


Answers in the comments.