Docsity

A Permutation Test for Correlation and Slope | MATH 324, Study notes of Applied Statistics

Toggle sidebar
bg1
Section 5.1 A Permutation Test for Correlation and Slope January 8, 2009 1
5 Tests for Trends and Associations
5.1 A Permutation Test for Correlation and
Slope
Sample data pairs (Xi, Yi),for i= 1,...,n.
The population correlation coefficient is defined by ρ=σx,y/(σxσy),
where σx,y =E(X−µx)(Y−µy).
∗σx,y is the population covariance; σxand σyare the population standard deviations;
µxand µyare the population means.
∗σx,y is the population covariance; σxand σyare the population standard deviations;
µxand µyare the population means.
∗ρis fixed, and typically is unknown.
∗ρis fixed, and typically is unknown.
ρmeasures the strength of the linear relationship between two variables.
∗ −1≤ρ≤1
∗ −1≤ρ≤1
The Pearson sample correlation coefficient is defined by
r=Pn
i=1(Xi−¯
X)(Yi−¯
Y)
qPn
i=1(Xi−¯
X)2Pn
i=1(Yi−¯
Y)2.
∗This is the usual sample correlation coefficient typically defined in Math 220 and 318.
∗This is the usual sample correlation coefficient typically defined in Math 220 and 318.
∗ris random since it is based on the data, and estimates ρ.
∗ris random since it is based on the data, and estimates ρ.
∗ −1≤r≤1
∗ −1≤r≤1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33

Partial preview of the text

Download A Permutation Test for Correlation and Slope | MATH 324 and more Study notes Applied Statistics in PDF only on Docsity!

Section 5.1 A Permutation Test for Correlation and Slope January 8, 2009 1

5 Tests for Trends and Associations

5.1 A Permutation Test for Correlation and

Slope

Sample data pairs (Xi, Yi), for i = 1,... , n. The population correlation coefficient is defined by ρ = σx,y /(σxσy), where σx,y = E(X − μx)(Y − μy). ∗ σx,y is the population covariance; σx and σy are the population standard deviations; μx and μy are the population means. ∗ σx,y is the population covariance; σx and σy are the population standard deviations; μx and μy are the population means. ∗ ρ is fixed, and typically is unknown. ∗ ρ is fixed, and typically is unknown. ρ measures the strength of the linear relationship between two variables. ∗ − 1 ≤ ρ ≤ 1 ∗ − 1 ≤ ρ ≤ 1 The Pearson sample correlation coefficient is defined by

r =

∑n √∑ i=1(Xi^ −^ X¯)(Yi^ −^ Y¯^ ) ni=1(Xi − X¯) 2 ∑ni=1(Yi − Y¯ ) 2.

∗ This is the usual sample correlation coefficient typically defined in Math 220 and 318. ∗ This is the usual sample correlation coefficient typically defined in Math 220 and 318. ∗ r is random since it is based on the data, and estimates ρ. ∗ r is random since it is based on the data, and estimates ρ. ∗ − 1 ≤ r ≤ 1 ∗ − 1 ≤ r ≤ 1

Section 5.1 A Permutation Test for Correlation and Slope January 8, 2009 2

∗ Dividing both numerator and denominator by (n − 1) reveals that r can be written as the ratio of the sample covariance to the product of the sample standard deviations; i.e., r = sx,y/(sxsy ). ∗ Dividing both numerator and denominator by (n − 1) reveals that r can be written as the ratio of the sample covariance to the product of the sample standard deviations; i.e., r = sx,y/(sxsy ).

Examples (interpreting r): For the following models, generate 100 pairs of

observations, determine the sample correlation coefficient, and plot the data. (a) X ∼ N(0, 1), Y = X + ε, where the ε are independent N(0, 0 .5). ∗ > x = rnorm(100); y = x + rnorm( 100, 0, 0.5 ) ∗ > x = rnorm(100); y = x + rnorm( 100, 0, 0.5 ) ∗ > cor( x, y ); plot( x, y ) ∗ > cor( x, y ); plot( x, y ) ∗ Correlation should be near 1/

∗ Correlation should be near 1/

∗ Run these several times to show variability in r. ∗ Run these several times to show variability in r. ∗ Less variability in r exists for large n. ∗ Less variability in r exists for large n. ∗ > cor( y, x ); plot( y, x ) # No change in r. ∗ > cor( y, x ); plot( y, x ) # No change in r. ∗ > # Hence, the ordering of x and y is irrelevant when calculating r. ∗ > # Hence, the ordering of x and y is irrelevant when calculating r. ∗ > cor( −x, y ); plot( −x, y ) # r is negated. ∗ > cor( −x, y ); plot( −x, y ) # r is negated. ∗ > cor( x, −y ); plot( x, −y )

Section 5.1 A Permutation Test for Correlation and Slope January 8, 2009 4

∗ Correlation should be 1. (f) X ∼ N(0, 1), Y = − 5 X + 37 ∗ > x = rnorm(100); y = x ∗ > x = rnorm(100); y = x ∗ > cor( x, y ); plot( x, y ) ∗ > cor( x, y ); plot( x, y ) ∗ Correlation should be −1. ∗ Correlation should be −1. (g) X ∼ N(20, 5), Y = X + ε, where the ε are independent N(60, 5). ∗ > x = rnorm(100, 20, 5); y = x + rnorm( 100, 60, 5 ) ∗ > x = rnorm(100, 20, 5); y = x + rnorm( 100, 60, 5 ) ∗ > cor( x, y ); plot( x, y ) ∗ > cor( x, y ); plot( x, y ) ∗ Correlation should be near 1/√2 = 0.7071. ∗ Correlation should be near 1/√2 = 0.7071. How much variability in Y can be explained by the linear relationship between X and Y? ∗ Clearly, half, since X and ε have the same standard deviation. ∗ Clearly, half, since X and ε have the same standard deviation. ∗ > cor( x, y ) ˆ 2 # Should be near 0.5. ∗ > cor( x, y ) ˆ 2 # Should be near 0.5. ∗ r^2 = 0.5, the coefficient of determination, which describes the amount of variability in Y which can be explained by X. ∗ r^2 = 0.5, the coefficient of determination, which describes the amount of variability in Y which can be explained by X. ∗ > x1 = 4 ∗ x − 60; y1 = 8 ∗ y + 34; cor( x1, y1 ); plot( x1, y1 ) ∗ > x1 = 4 ∗ x − 60; y1 = 8 ∗ y + 34; cor( x1, y1 ); plot( x1, y1 )

Section 5.1 A Permutation Test for Correlation and Slope January 8, 2009 5

∗ Graph of y1 vs. x1 should look the same as graph of y vs. x, except for the scaling. ∗ Graph of y1 vs. x1 should look the same as graph of y vs. x, except for the scaling. ∗ A linear transformation of x or y does not change |r|. ∗ A linear transformation of x or y does not change |r|. ∗ Correlation does not depend on scale. Converting between Fahrenheit and Celsius does not affect r, since F = (9/5)C + 32. ∗ Correlation does not depend on scale. Converting between Fahrenheit and Celsius does not affect r, since F = (9/5)C + 32. ∗ r has no units. ∗ r has no units. ∗ > y2 = − 8 ∗ x + 34; cor( x1, y2 ); plot( x1, y2 ) # r was negated. ∗ > y2 = − 8 ∗ x + 34; cor( x1, y2 ); plot( x1, y2 ) # r was negated. ∗ Graph of y2 vs. x1 should look the same as graph of y vs. x, except for the scaling and the reflection about the line x = ¯x. ∗ Graph of y2 vs. x1 should look the same as graph of y vs. x, except for the scaling and the reflection about the line x = ¯x. (h) X ∼ N(20, 5), Y = ε, where the ε are independent N(60, 5). ∗ > x = rnorm(100, 20, 5); y = rnorm( 100, 60, 5 ) ∗ > x = rnorm(100, 20, 5); y = rnorm( 100, 60, 5 ) ∗ > cor( x, y ); plot( x, y ) ∗ > cor( x, y ); plot( x, y ) ∗ Correlation should be near zero, since X and Y are independent. ∗ Correlation should be near zero, since X and Y are independent. (i) X ∼ Unif (10, 30), Y = −5(X − 20)^2 + ε, where the ε are independent N(900, 25). ∗ > x = runif(100, 10, 30); y = − 5 ∗ ( x − 20 ) ˆ 2 + rnorm( 100, 900, 25 ) ∗ > x = runif(100, 10, 30); y = − 5 ∗ ( x − 20 ) ˆ 2 + rnorm( 100, 900, 25 ) ∗ > cor( x, y ); plot( x, y )

Section 5.1 A Permutation Test for Correlation and Slope January 8, 2009 7

(a) Plot the data.

z = scan2( “problem5.1.1”, T, T ) ∗ > cry = z[ , 1 ] ∗ > cry = z[ , 1 ] ∗ > IQ = z[ , 2 ] ∗ > IQ = z[ , 2 ] ∗ > plot( cry, IQ ) ∗ > plot( cry, IQ ) ∗ It makes sense to put cry on the x-axis, since cry predicts IQ hopefully. ∗ It makes sense to put cry on the x-axis, since cry predicts IQ hopefully. ∗ Are the variables cry and IQ linearly related? Yes, somewhat. ∗ Are the variables cry and IQ linearly related? Yes, somewhat. (b) Determine the sample correlation coefficient. ∗ > cor( cry, IQ ) # Answer is 0.402. ∗ > cor( cry, IQ ) # Answer is 0.402. ∗ Compute and interpret r^2 ≈ 16%. ∗ Compute and interpret r^2 ≈ 16%. (c) What is an interesting hypothesis test for this data set? ∗ H 0 : ρ = 0 versus Ha : ρ > 0; i.e., does a positive relationship between cry count and IQ exist in the population? ∗ H 0 : ρ = 0 versus Ha : ρ > 0; i.e., does a positive relationship between cry count and IQ exist in the population? ∗ Is ρ really positive, or did our positive value of r occur due to randomness under ρ = 0? ∗ Is ρ really positive, or did our positive value of r occur due to randomness under ρ = 0?

2

Section 5.1 A Permutation Test for Correlation and Slope January 8, 2009 8

Define tcorr = r

√ (n − 2)/(1 − r^2 ) (need not memorize). If ρ = 0, and if the (x, y) are based on a simple random sample from a bivariate normal distribution, then tcorr is t-distributed with (n − 2) degrees of freedom. ∗ Although the t-distribution is a reasonable approximation for large sample sizes and finite variances where the data are not bivariate normal, we save that discussion until section 5.1.4. ∗ Although the t-distribution is a reasonable approximation for large sample sizes and finite variances where the data are not bivariate normal, we save that discussion until section 5.1.4. ∗ The previous scatterplots, where X and Y are both based on “rnorm”, are samples of bivariate data. ∗ The previous scatterplots, where X and Y are both based on “rnorm”, are samples of bivariate data. ∗ Note in (most of) those examples, Y was a linear combination of X and some other normal random variable independent of X. ∗ Note in (most of) those examples, Y was a linear combination of X and some other normal random variable independent of X. ∗ The shape of bivariate normal data is something like a football. ∗ The shape of bivariate normal data is something like a football. ∗ x = rnorm(500); y = x + rnorm(500); plot( x, y) # Repeat for several plots. ∗ x = rnorm(500); y = x + rnorm(500); plot( x, y) # Repeat for several plots.

Revisit problem #5.1.1 (crying babies and IQ scores): (This data

set is from Karelitz et al. (1964), Child Development.) To test whether children who cry more actively as babies later tend to have higher IQs, a cry count was taken for a sample of 38 children aged five days and was later compared with their Stanford-Binet IQ scores at age three. (a) State the null and alternative hypotheses. ∗ Let ρ be the population Pearson correlation coefficient.

Section 5.1.2 Slope of the Least Squares Line January 8, 2009 10

∗ > # Again, t is 2.6328 and p-value is 0.006199. (f) What is the 95% lower confidence bound on ρ? ∗ (0.147, 1), from ‘> cor.test( cry, IQ, “greater” )’ ∗ (0.147, 1), from ‘> cor.test( cry, IQ, “greater” )’ ∗ We are 95% confident that the true population Pearson correlation coefficient, ρ, is greater than 0.147. ∗ We are 95% confident that the true population Pearson correlation coefficient, ρ, is greater than 0.147. ∗ Note that 0.147 is greater than zero. ∗ Note that 0.147 is greater than zero. (g) Does association imply causation? ∗ No. Just because there is a statistically significant positive correlation between cry count and IQ does not imply that one causes the other. ∗ No. Just because there is a statistically significant positive correlation between cry count and IQ does not imply that one causes the other. ∗ Tormenting babies to make them cry will NOT necessarily raise their IQ scores. ∗ Tormenting babies to make them cry will NOT necessarily raise their IQ scores. 2

5.1.2 Slope of the Least Squares Line

A simple linear regression model is defined by

Yi = β 0 + β 1 Xi + εi,

where the εs are independent and identically distributed random variables with mean zero and finite variance. ∗ We insist on finite variance so that correlation is a reasonable measure. ∗ We insist on finite variance so that correlation is a reasonable measure.

Section 5.1.2 Slope of the Least Squares Line January 8, 2009 11

∗ β 0 is the intercept parameter, and β 1 is the slope parameter, and typically both pa- rameters are unknown. ∗ β 0 is the intercept parameter, and β 1 is the slope parameter, and typically both pa- rameters are unknown. ∗ Note that normality of the ε is not assumed. ∗ Note that normality of the ε is not assumed. However, if the ε are normal, then X and Y are bivariate normal.

We define the least squares estimates of β 0 and β 1 by:

βˆ 1 = rsy/sx and βˆ 0 = Y¯ − βˆ 1 X¯ (memorize these two formulas). ∗ Equivalent formulas for βˆ 1 are often given. ∗ Equivalent formulas for βˆ 1 are often given. ∗ The formula for βˆ 1 shows that βˆ 1 and r always have the same sign; i.e., positive, negative, or zero. ∗ The formula for βˆ 1 shows that βˆ 1 and r always have the same sign; i.e., positive, negative, or zero. ∗ The least squares line always goes through the sample means ( X,¯ Y¯ ). ∗ The least squares line always goes through the sample means ( X,¯ Y¯ ). The least squares line, ˆy = βˆ 0 + βˆ 1 x, is the line which minimizes the sum of the squares of the vertical distances between the observations and the line. ∗ Hence, the least squares line is random (since it is based on data) and estimates the simple linear regression model. ∗ Hence, the least squares line is random (since it is based on data) and estimates the simple linear regression model. For large n, what are the asymptotic values in the formula βˆ 1 = rsy/sx? ∗ β 1 = ρ σy/σx ∗ β 1 = ρ σy/σx

Section 5.1.2 Slope of the Least Squares Line January 8, 2009 13

(d) Predict the child’s IQ at age three years if the cry count at age five days was 25. ∗ intercept + slope ∗ 25 # Answer is 129. ∗ intercept + slope ∗ 25 # Answer is 129. (e) Determine the least squares equation using the macro ‘lm’. ∗ > lm( IQ ∼ cry ) ∗ > lm( IQ ∼ cry ) (f) Verify that the least squares equation goes through the sample means. ∗ Prove that ¯y = 90.755 + 1.536¯x ∗ Prove that ¯y = 90.755 + 1.536¯x ∗ > mean( cry ) # Answer is 17.24. ∗ > mean( cry ) # Answer is 17.24. ∗ > mean( IQ ) # Answer is 117.24. ∗ > mean( IQ ) # Answer is 117.24. ∗ > intercept + slope ∗ mean( cry ) # Answer is 117.2368. ∗ > intercept + slope ∗ mean( cry ) # Answer is 117.2368. (g) Regarding the simple linear regression model, what is an interesting hypothesis test? ∗ H 0 : β 1 = 0 vs. a one-sided or two-sided alternative ∗ H 0 : β 1 = 0 vs. a one-sided or two-sided alternative ∗ If β 1 = 0, then no linear relationship between x and y exists. ∗ If β 1 = 0, then no linear relationship between x and y exists. ∗ Typically, we want to show that a statistically significant linear relationship between x and y exists. ∗ Typically, we want to show that a statistically significant linear relationship between x and y exists. ∗ Since β 1 = ρ σy /σx, then for fixed σx and σy a one-to-one correspondence between ρ and β 1 exists.

Section 5.1.3 The Permutation Test January 8, 2009 14

∗ Since β 1 = ρ σy /σx, then for fixed σx and σy a one-to-one correspondence between ρ and β 1 exists. ∗ Since β 1 and ρ always have the same sign, then testing β 1 = 0 is equivalent to testing ρ = 0. ∗ Since β 1 and ρ always have the same sign, then testing β 1 = 0 is equivalent to testing ρ = 0. ∗ Textbook provides additional details, which we will skip. ∗ Textbook provides additional details, which we will skip. 2

5.1.3 The Permutation Test

Specifically, this permutation correlation test is for nonzero, negative, or positive Pearson correlation (or slope). If the simple linear regression model holds, and the null hypothesis of β 1 = 0 holds, what can we say about X and Y? ∗ X and Y must be independent, since knowing X has no impact on Y. ∗ X and Y must be independent, since knowing X has no impact on Y. How should a permutation test be performed? ∗ By, say, keeping the X values fixed and scrambling the Y values. ∗ By, say, keeping the X values fixed and scrambling the Y values. ∗ Then, compare the permuted values of βˆ 1 (or r) with the observed value, to obtain a p-value. ∗ Then, compare the permuted values of βˆ 1 (or r) with the observed value, to obtain a p-value. ∗ For determining the p-value of a two-sided test, determine the proportion of the permuted values of | βˆ 1 | (or |r|) at least as large as the observed value of | βˆ 1 | (or |r|).

Section 5.1.3 The Permutation Test January 8, 2009 16

∗ > y = c(139, 87, 143); lm(y ∼ x); cor(x, y) # And so on. ∗ > y = c(139, 87, 143); lm(y ∼ x); cor(x, y) # And so on.

X 1 = 11 X 2 = 15 X 3 = 21 Y 1 Y 2 Y 3 βˆ 1 r 87 139 143 5.21 0. 87 143 139 4.74 0. 139 87 143 1.11 0. 139 143 87 − 5. 53 ∗^ − 0. 890 ∗ 143 87 139 0.316 0. 143 139 87 − 5. 84 − 0. 941

β^ ˆ 1 r probability − 5. 84 − 0. 941 1 / 6 − 5. 53 ∗^ − 0. 890 ∗^1 / 6 0.316 0.051 1 / 6 1.11 0.178 1 / 6 4.74 0.763 1 / 6 5.21 0.839 1 / 6 sum 1

∗ Note that the ordering of βˆ 1 is the same as the ordering of r. ∗ Note that the ordering of βˆ 1 is the same as the ordering of r. ∗ The permutation distribution of neither βˆ 1 nor r is symmetric. ∗ The permutation distribution of neither βˆ 1 nor r is symmetric. (c) Determine the p-value of the permutation correlation test, using hand-calculations. ∗ The p-value is the proportion of the permuted values of r at least as small as − 0 .890, the observed value. ∗ The p-value is the proportion of the permuted values of r at least as small as − 0 .890, the observed value.

Section 5.1.3 The Permutation Test January 8, 2009 17

∗ This p-value is 1/6 + 1/6 = 1/3, so fail to reject H 0. ∗ This p-value is 1/6 + 1/6 = 1/3, so fail to reject H 0. ∗ Likewise, this p-value is the proportion of the permuted values of βˆ 1 at least as small as − 5 .53, the observed value. ∗ Likewise, this p-value is the proportion of the permuted values of βˆ 1 at least as small as − 5 .53, the observed value. (d) What would be the p-value for a two-sided test? ∗ The p-value is the proportion of the permuted values of |r| at least as large as |− 0. 890 |, the observed value. ∗ The p-value is the proportion of the permuted values of |r| at least as large as |− 0. 890 |, the observed value. ∗ This p-value is 1/6 + 1/6 = 1/3, same as for the one-sided test. ∗ This p-value is 1/6 + 1/6 = 1/3, same as for the one-sided test. ∗ Likewise, this p-value is the proportion of the permuted values of βˆ 1 at least as large as | − 5. 53 |, the observed value. ∗ Likewise, this p-value is the proportion of the permuted values of βˆ 1 at least as large as | − 5. 53 |, the observed value. (e) Obtain the simulated p-value using the macro ‘perm.cor.test’. ∗ > x = c(11, 15, 21); y = c(139, 143, 87) ∗ > x = c(11, 15, 21); y = c(139, 143, 87) ∗ > perm.cor.test( x, y, “less” ) # p-value should be close to 0.33. ∗ > perm.cor.test( x, y, “less” ) # p-value should be close to 0.33. (f) What assumptions were needed to perform this test from part (e)? ∗ The data satisfy the simple linear regression model, defined by Yi = β 0 + β 1 Xi + εi, where the εs are independent and identically distributed random variables with mean zero and finite variance.

Section 5.1.4 Large-Sample Approx. for Permutation Distrib. of r January 8, 2009 19

∗ > plot( x, y ) # Probably not, since two observations are close together, while the other observation is far away, especially in terms of y. 2

In general, for n data pairs, how many permutations (groupings) exist when performing the permutation correlation test? ∗ n!, since for the first X there are n choices for Y ; for the second X there are (n − 1) choices for Y , and so on. ∗ n!, since for the first X there are n choices for Y ; for the second X there are (n − 1) choices for Y , and so on.

5.1.4 Large-Sample Approximation for the

Permutation Distribution of r

Suppose n independent pairs of observations (X, Y ) are sampled from distributions with finite variances such that X and Y are independent. ∗ Note that normality is NOT assumed. ∗ Note that normality is NOT assumed. What is ρ, the population Pearson correlation coefficient? ∗ zero ∗ zero What is r, the sample Pearson correlation coefficient? ∗ r is random, so r can be any number between −1 and 1, but r converges to zero as n → ∞ with probability one. ∗ r is random, so r can be any number between −1 and 1, but r converges to zero as n → ∞ with probability one. Consider the permutation distribution of r. What is Er (where the expectation is taken conditionally on the permutation distribu- tion)?

Section 5.1.4 Large-Sample Approx. for Permutation Distrib. of r January 8, 2009 20

∗ Zero. The answer is also zero, where r is UNconditional on the permutation distribu- tion, as proved in Math 318. ∗ Zero. The answer is also zero, where r is UNconditional on the permutation distribu- tion, as proved in Math 318. var(r) = 1/(n − 1), conditional on the permutation distribution. ∗ as proved in the textbook. This result is exact for permutation distributions, but only approximate when UNconditional on permutation distributions due to Slutsky’s theorem. ∗ as proved in the textbook. This result is exact for permutation distributions, but only approximate when UNconditional on permutation distributions due to Slutsky’s theorem. ∗ Notice that the variance decreases at the rate of 1/n, which is quite typical. ∗ Notice that the variance decreases at the rate of 1/n, which is quite typical. ∗ The formula for r involves sample sums, so a version of the Central Limit Theorem applies to r. ∗ The formula for r involves sample sums, so a version of the Central Limit Theorem applies to r. ∗ r =

∑n √∑ i=1(Xi^ −^ X¯)(Yi^ −^ Y¯^ ) ni=1(Xi − X¯) 2 ∑ni=1(Yi − Y¯ ) 2 ∗ r =

∑n √∑ i=1(Xi^ −^ X¯)(Yi^ −^ Y¯^ ) ni=1(Xi − X¯) 2 ∑ni=1(Yi − Y¯ ) 2

∗ {Typically, use this formula for large n, and the formula from section 5.1.1 for bivariate normality, since the t-distribution perhaps is more sensible when the data really are bivariate normal.} ∗ {Typically, use this formula for large n, and the formula from section 5.1.1 for bivariate normality, since the t-distribution perhaps is more sensible when the data really are bivariate normal.}