17
Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to have a numerical description of how both variables vary together. For instance, is one variable increasing faster than the other one? And we would like to make predictions based on that numerical description. But which line best describes our data?

Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

Embed Size (px)

Citation preview

Page 1: Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

Correlation tells us about

strength (scatter) and direction

of the linear relationship

between two quantitative

variables.

In addition, we would like to have a numerical description of how both

variables vary together. For instance, is one variable increasing faster

than the other one? And we would like to make predictions based on that

numerical description.But which line best

describes our data?

Page 2: Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

Explanatory (independent) variable: number of beers

Response

(dependent)

variable:

blood alcohol

content

xy

Recall: explanatory and response variablesA response variable measures or records an outcome of a study - the

endpoint of interest in the study. An explanatory variable explains changes in

the response variable.

Typically, the explanatory or independent variable is plotted on the x axis, and

the response or dependent variable is plotted on the y axis.

Page 3: Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

Some plots don’t have clear explanatory and response variables.

Do calories explain

sodium amounts?

Does percent return on Treasury

bills explain percent return

on common stocks?

Page 4: Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

The regression line

A regression line is a straight line that describes how a response variable y changes as an explanatory variable x changes - the description is made through the slope and intercept of the line.

We often use a regression line to predict the value of y for a given value of x; the line is also called the prediction line, or the least-squares line, or the best fit line.

In regression, the distinction between explanatory and response variables is important - if you interchange the roles of x and y, the regression line is different.

xbby 10ˆ += y-hat is the predicted value of y

b1 is the slope

b0 is the y-intercept

Page 5: Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

Distances between the points and line are squared so all are positive values. This is done so that distances can be properly added…

The regression lineThe least-squares regression line is the unique line such that the sum

of the squares of the vertical (y) distances between the data points and

the line is as small as possible ("least squares")

Page 6: Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

b1 = rsy

sx

First we calculate the slope of the line, b1; from statistics we already know:

r is the correlation.sy is the standard deviation of the response variable y.sx is the the standard deviation of the explanatory variable x.

Once we know b1, the slope, we can calculate b0, the y-intercept:

b0 = y − b1x Where and are the sample means of the x and y variables

How to:

Typically, we use the TI-83 or the R function lm (linear model) to compute the b's, rarely using the above formulas…

x

y

Page 7: Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

The equation completely describes the regression line.

To plot the regression line you only need to plug two x values into the equation, get the two y's, and draw the line that goes through those points. Hint: The regression line always passes through the mean of x and the mean of y.

Let R draw the regression line with the abline function after you've done the scatterplot:

plot(x,y)

lm(y~x)

abline(lm(y~x))

Page 8: Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

Unlike in Correlation, the distinction between explanatory and response

variables is crucial in Regression. If you exchange y for x in calculating

the regression line, you will get a different line.

Regression examines the distance of all points from the line in the y

direction only.

Hubble telescope data about

galaxies moving away from earth:

These two lines are the two

regression lines calculated either

correctly (x = distance, y = velocity,

solid line) or incorrectly (x =

velocity, y = distance, dotted line).

Page 9: Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

Making predictionsThe equation of the least-squares regression allows you to predict y

for any x within the range studied - be careful about extrapolation!

Confirm the regression line's equation below using R…

ˆ y = 0.0144x + 0.0008 Nobody in the study drank 6.5

beers, but by finding the value

of from the regression line for

x = 6.5 we would expect a

blood alcohol content of 0.094

mg/ml.

mg/ml 0944.00008.0936.0ˆ

0008.05.6*0144.0ˆ

=+=+=

yy

y

Page 10: Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

Year Powerboats Dead Manatees

1977 447 13

1978 460 21

1979 481 24

1980 498 16

1981 513 24

1982 512 20

1983 526 15

1984 559 34

1985 585 33

1986 614 33

1987 645 39

1988 675 43

1989 711 50

1990 719 47

There is a positive linear relationship between the number of powerboats registered and the number of manatee deaths.

(in 1000s)

The least squares regression line has the equation:

1.214.415.62ˆ 4.41)500(125.0ˆ =−=⇒−= yy

Roughly 21 manatees.

Thus if we were to limit the number of powerboat registrations to 500,000, what

could we expect for the number of manatee deaths?

ˆ y 0.125x 41.4

ˆ y 0.125x 41.4

Confirm this slide by plotting the data, computing the l.s. line and evaluating it at x=500

Page 11: Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

Extrapolation is the use of a

regression line for predictions

outside the range of x values

used to obtain the line.

This is not a smart thing to do,

as seen here.H

eig h

t in

Inch

e sH

eig h

t in

Inch

e s

!!!

!!!

Extrapolation - Beware!

Page 12: Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

Sometimes the y-intercept is not realistically possible. Here we have

negative blood alcohol content, which makes no sense…

y-intercept shows

negative blood alcohol

But the negative value is correct

for the equation of the

regression line.

There is a lot of scatter in the

data, and the slope and intercept

of the line are both estimates.

We'll see later the y-intercept is

probably not "significantly

different from zero"

The y intercept

Page 13: Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

Coefficient of determination, r 2

In this example, r 2 represents the

percentage of the variation in BAC

(vertical scatter from the regression

line) that can be explained by the

regression of BAC on number of

beers.

r 2, the coefficient of determination, is the square of the correlation

coefficient.

r = 0.87r 2 = 0.76

Page 14: Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

r = -1r 2 = 1

Changes in x

explain 100% of

the variation in y.

Y can be entirely

predicted for any

given value of x. Here the regression of y on x

explains only 76% of the

variation in y. The rest of the

variation in y (the vertical

scatter, shown as red arrows)

must be explained by

something other than the line.

r = 0.87r 2 = 0.76

Page 15: Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

r=0.994, r-square=0.988

r=0.921, r-square=0.848

Here are two plots of height (response) against age (explanatory) of some children. Notice how r2 relates to the variation in heights...

Page 16: Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

r = 0.86, but this is misleading.

The elephant is an influential point. Most

mammals are very small in comparison.

Without this point, r = 0.50 only.

Body weight and brain weight in 96 mammal species

Now we plot the log of brain weight

against the log of body weight.

The pattern is linear, with r = 0.96.

The vertical scatter is homogenous

→ good for predictions of brain weight

from body weight (in the log scale).

Page 17: Correlation tells us about strength (scatter) and direction of the linear relationship between two quantitative variables. In addition, we would like to

Homework: You should have read through section 2.3, carefully

reviewing what you know about lines from your algebra course…Go over Examples 2.18-2.21 in some detail so you understand them!

Do #2.66, 2.71-2.73, 2.78, 2.82, 2.83 Use R to make the scatterplots, describe the association you see between the two variables, and then let R (using the lm function) calculate the intercept and slope and use cor (square it's value) to get r-square for the regression line. Explain what the slope, intercept, and r-square mean in the context of the specific problem. Also, if you'd like, I can show you how to do all this on the TI-83 …