ph.d. course in biostatistics day 5 · 1 1 ph.d. course in biostatistics day 5 regression analysis...

26
1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative variables? Example: Relationship between height and pefr in 43 females and 58 males. Data from Bland, Table 11.4. (pefr.dta) 400 500 600 700 800 pefr 150 160 170 180 190 height Female Male 2 This type of data arise in two situations: Terminology: x = independent/explanatory variable = dose y = dependent/response variable sex = grouping variable Purpose in both cases: To describe how the response (pefr) varies with the explanatory variable (height). Note: A regression analysis is not symmetric in the two variables Situation 1: The data are a random sample of pairs of observations. In the example: both pefr and height are measured (observed) quantities, i.e. random variables, and none of these variables are controlled by the investigator. Situation 2: One of the variables is controlled by the investigator, and the other is subject to random variation, e.g. in a dose-response experiment, the dose is usually controlled by the investigator and the response is the measured quantity (random variable).

Upload: lamnhi

Post on 03-Sep-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

1

1

Ph.D. COURSE IN BIOSTATISTICS DAY 5REGRESSION ANALYSISHow do we describe and analyze the relationship or association between two quantitative variables?

Example:Relationshipbetween heightand pefr in 43 females and 58 males. Data fromBland, Table 11.4.(pefr.dta)

400

500

600

700

800

pefr

150 160 170 180 190height

Female Male

2

This type of data arise in two situations:

Terminology:x = independent/explanatory variable = dosey = dependent/response variablesex = grouping variable

Purpose in both cases: To describe how the response (pefr) varieswith the explanatory variable (height). Note: A regression analysis is not symmetric in the two variables

Situation 1: The data are a random sample of pairs of observations.In the example: both pefr and height are measured (observed) quantities, i.e. random variables, and none of these variables arecontrolled by the investigator.

Situation 2: One of the variables is controlled by the investigator, and the other is subject to random variation, e.g. in a dose-responseexperiment, the dose is usually controlled by the investigator and the response is the measured quantity (random variable).

Page 2: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

2

3

Linear relationshipIn the mathematical sense the most simple relationship between yand x is a straight line, i.e.

y x= + ⋅α β

Statistical modelIn the statistical sense this corresponds to the model:

where E represents the random variation around the straight line.

y x E= + ⋅ +α β

Random variationThe random variation reflects several sources of variation: (1)measurement error, (2) biological (inter-individual) variation and (3) deviations in the relationship from a straight line.

In a linear regression analysis the cumulative contributions from these sources are described as independent ”error” from a normal distribution . 2(0, )E N σ�

Example:does thedescriptiondepend onsex?

4

2

::

:

intercept

slope

(residual)variance

�����

αβσ

Unknown parameters

The model has 3 unknown parameters:

Statistical modelThe data consists of pair of observations and the statistical model takes the form:

( , ), 1,..,i ix y i n=

2, (0, ) 1,...,i i i iy x E E N i n= + ⋅ + =�α β σ

where the Ei’s (or equivalently the yi’s) are independent.

EstimationA linear regression can be performed by most statistical software and spreadsheets. The estimates of α and β are obtained by the methodof least squares by minimizing the residual sum of squares:

21( ) .

n

i iiRSS y xα β

== − − ⋅�

Example:does theparameters depend onsex?

Solution: 22

( )( )ˆ ˆˆ ˆ, , ( 2)( )

i i

i

y y x xy x RSS n

x xβ α β σ

− −= = − ⋅ = −

−��

Page 3: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

3

5

In Stata the command is:regress pefr height if sex==1

αβ

Note:Estimated regression line:The line pass through with slope

ˆˆ y x= − ⋅α βˆ ˆˆ ( )y x y x x= + ⋅ = + ⋅ −α β β

( , )x y β

σ

Regression for each group

Only femalesshown

����������������������������������������������������

� ��������������������� ��������������������� ��������������������� ���������������������������� ������������������ �������������������� �������������������� �������������������� �� �� �� �� �� ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� ��������������������� ���������������������� ���������������������� ���������������������� ������ ������!!����!!���������!!����!!���������� ������!!����!!���������!!����!!���������� ������!!����!!���������!!����!!���������� ������!!����!!���������!!����!!���������"� �"� �"� �"� � ������������#�#!!!������������#�#!!!������������#�#!!!������������#�#!!!

$��%�����&&&� �!!!!�������!� '�!!�(���������$$��%�����&&&� �!!!!�������!� '�!!�(���������$$��%�����&&&� �!!!!�������!� '�!!�(���������$$��%�����&&&� �!!!!�������!� '�!!�(���������$�����)������������#��!�!�)������������#��!�!�)������������#��!�!�)������������#��!�!���������������������������������������������������������������������������������������������������������������������������������������������������� *�+*�+*�+*�+ $$$$�����)��������#�#(('�)��������#�#(('�)��������#�#(('�)��������#�#(('

, -����#��#'� ������!��!�#'��!�&'��������$ -���.���������� , -����#��#'� ������!��!�#'��!�&'��������$ -���.���������� , -����#��#'� ������!��!�#'��!�&'��������$ -���.���������� , -����#��#'� ������!��!�#'��!�&'��������$ -���.���������� ����������������

��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/���/���/���/���������������������������0 ��0 ��0 ��0 ������-���.��������-����"��-����1(�2�0 3���43-��5�6����-���.��������-����"��-����1(�2�0 3���43-��5�6����-���.��������-����"��-����1(�2�0 3���43-��5�6����-���.��������-����"��-����1(�2�0 3���43-��5�6

��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������7�%87-���!�(�!�&&����!!�&� ����!��&���#�#!!������&�&#��������&7�%87-���!�(�!�&&����!!�&� ����!��&���#�#!!������&�&#��������&7�%87-���!�(�!�&&����!!�&� ����!��&���#�#!!������&�&#��������&7�%87-���!�(�!�&&����!!�&� ����!��&���#�#!!������&�&#��������&�'(��'(��'(��'(�9� 3���9� 3���9� 3���9� 3�������(��'#�#���!#��� ((���(��'#�#���!#��� ((���(��'#�#���!#��� ((���(��'#�#���!#��� ((�������#�#����#�( ���#�#����#�( ���#�#����#�( ���#�#����#�( ���������(�&&�������#��������(�&&�������#��������(�&&�������#��������(�&&�������#������

��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

6

��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/���/���/���/���������������������������0 ��0 ��0 ��0 ������-���.��������-����"��-����1(�2�0 3���43-��5�6����-���.��������-����"��-����1(�2�0 3���43-��5�6����-���.��������-����"��-����1(�2�0 3���43-��5�6����-���.��������-����"��-����1(�2�0 3���43-��5�6

��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������7�%87-���!�(�!�&&����!!�&� ����!��&���#�#!!������&�&#��������&7�%87-���!�(�!�&&����!!�&� ����!��&���#�#!!������&�&#��������&7�%87-���!�(�!�&&����!!�&� ����!��&���#�#!!������&�&#��������&7�%87-���!�(�!�&&����!!�&� ����!��&���#�#!!������&�&#��������&�'(��'(��'(��'(�9� 3���9� 3���9� 3���9� 3�������(��'#�#���!#��� ((���(��'#�#���!#��� ((���(��'#�#���!#��� ((���(��'#�#���!#��� ((�������#�#����#�( ���#�#����#�( ���#�#����#�( ���#�#����#�( ���������(�&&�������#��������(�&&�������#��������(�&&�������#��������(�&&�������#������

��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

p-value for slope = 0

p-value forintercept = 0

The sampling distribution of the estimates:2

22

22

22 2

1ˆ ( , )( )

1ˆ ( , )( )

ˆ ( 2)2

i

i

xN

n x x

Nx x

nn

α α σ

β β σ

σσ χ

� �⋅ +� −� �

⋅−

⋅ −−

But note:are not

independent estimatesˆˆ and α β

t-tests of the hypotheses slope = 0 (top) and intercept = 0 (bottom)

Confidence intervals for the parameters

Page 4: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

4

7

Stata gives a t-test of the hypothesis and a t-test of the hypothesis. The test statistics are computed as

and

95% confidence intervals for the parameters are derived as in lecture 2, e.g. as where is the upper 97.5 percentile in a t-distribution with n – 2 degrees of freedom.

After the regress command other hypothesized values of theparameters can be assessed directly by

������7�%87-���!��������7�%87-���!��������7�%87-���!��������7�%87-���!��

�������������������#����������������������#����������������������#����������������������#���"� �"� �"� �"� � ���������#�'�&!���������#�'�&!���������#�'�&!���������#�'�&!

2ˆ ˆ( ),nt seβ β−± ⋅ 2nt −

test height = 2.5

Test and confidence intervals0β =

0α =ˆ 0

ˆ( )t

seβ

β−=

ˆ 0ˆ( )

tseα

α−=

These test statistics have a t-distribution with n – 2 degrees of freedom, if the corresponding hypothesis is true. The standard errors of the estimates are obtained from the sampling distribution by replacing the population variance by the estimate . 2σ 2σ

Note: F = t2

8

Change of units: If height in the example is measure in meter theslope becomes: (litre/minute/meter)

Intercept (α): the expected pefr when height = 0, which makes nobiological sense. For this reason the reference point on the x-axis is sometimes changed to a more meaningful value, e.g.

Physical unit of intercept: as y, i.e. as pefr (litre/minute).

170heightx = −

ˆ100 2.91β⋅ =

/y x

Slope (�): the expected difference in pefr between two (female) students A and B, where A is 1 cm taller than B.Physical units of slope: as , i.e. as pefr/height (litre/minute/cm)

Interpretation of the parameters

Standard deviation (�): The standard deviation of the random variationaround the regression line. Approximately 2/3 of the data points arewithin one standard deviation from the line. The estimate is often calledroot mean square error.

Physical unit of standard deviation: as y, i.e. as pefr (litre/minute).

Page 5: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

5

9

350

400

450

500

550

600

pefr

/Lin

ear

pred

ictio

n

150 160 170 180 190height

pefr Linear prediction

Fitted valueFor the ith observation the fittedvalue (expected value) is

ˆ ˆˆˆ ( )i i iy x y x xα β β= + ⋅ = + ⋅ −

ResidualThe residual is the difference between the observed valueand the fitted value: ˆi i ir y y= −

( , )i ix y

10

Checking the model assumptions

1. Look at the scatter plot of y against x. The model assumes a linear trend.

2. If the model is correct the residuals have mean zero and approximately constant variance. Plot the residuals (r) againstthe fitted values ( ) or the explanatory variable x. The plot must not show any systematic structure and the residuals must have approximately constant variation around zero.

3. The residuals represent estimated errors. Use a histogram and/ora Q-Q plot to check if the distribution is approximately normal.

y

Note:A Q-Q plot of the observed outcomes, the yi’s, can not be used to check the assumption of normality, since the yi’s do not follow thesame normal distribution (the mean depends on xi).

The explanatory variable, the xi’s, is not required to follow a normaldistribution.

Page 6: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

6

11

Stata: predicted values and residuals are obtained using two predictcommands after the regress command:regress pefr heightpredict yhat, xb (yhat is the name of a new variable)predict res, residuals (res is the name of a new variable)

Both plots look OK!

-10

0-5

00

50

10

0R

esi

du

als

440 460 480 500 520Linear prediction

-100

-50

05

01

00

Re

sid

ua

ls

-100 -50 0 50 100Inverse Normal

Plots for females

12x

Res

idua

ls

0 5 10 15 20 25 30

-150

-50

050

100

150

x

y

0 5 10 15 20 25 30

200

400

600

800

1000

Residuals

Qua

ntile

s of

Sta

ndar

d N

orm

al

-100 -50 0 50 100 150

-2-1

01

2

Example: Non linear regression

Note:

The non-linear relationshipbetween y and x is most easilyseen from the plot of theresiduals against x.

Page 7: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

7

13

x

y

0 5 10 15 20 25 30

5010

015

020

0x

Res

idua

ls

0 5 10 15 20 25 30

-150

-50

050

100

150

Residuals

Qua

ntile

s of

Sta

ndar

d N

orm

al-50 0 50 100

-2-1

01

2

Example: Variance heterogeneity

Note:

Again, the fact that the varianceincrease with x is most easily seenfrom the plot of the residualsagainst x.

14

Regression models can serve several purposes:1. Description of a relationship between two variables2. Calibration3. Confounder control and related problems, e.g. to describe the

relationship between two variables after adjusting for one orseveral other variables.

4. Prediction

Re 1. In the example about pefr and height we found a linear relationship and the regression analysis identified the parameters of the ”best” line as ˆˆy xα β= + ⋅

Re 3. Example: Describe the relationship between birth weight and smoking habit when adjusting for parity and gestational age. This is a regression problem with multiple explanatory variables (multiple linear regression or analysis of covariance)

Re 2. Example: much modern laboratory measurement equipmentdo not measure the concentrations in your samples directly, but usesbuild-in regression techniques to calibrate the measurements againstknown standards.

Page 8: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

8

15

an approximately standard normal test statistic is

female maleβ β=

2 2

ˆ ˆ ˆ ˆˆ ˆ ˆ ˆ. .( ) . . ( ) . . ( )

zs e s e s e

β β β ββ β β β

− −= =− +

female male female male

female male female male

Example (test of no effect modification):In the data on pefr and height we may want to compare the relationship for males with that for females, i.e. assess if the sexis an effect-modifier of this relationship.

The hypothesis of no effect modification is , i.e. that thetwo regression lines are parallel.

A simple test of this hypothesis can be derived from the estimates ofthe two separate regression analyses. We have

��!!'�#���!!'�#���!!'�#���!!'�#���( !#!��( !#!��( !#!��( !#!������������

��!!�&� ��!!�&� ��!!�&� ��!!�&� !�(�!�&&!�(�!�&&!�(�!�&&!�(�!�&&����������������

�-��-��-��-���������.��.��.��.�������� /��� /��� /��� /�:� �/:� �/:� �/:� �/

Inserting the values gives z =-0.608, i.e. p-value = 0.543. The slopesdoes not seem to be different.

16

Re 4. Example: Predicting the expected outcome for a specifiedx-value, e.g. predicting pefr for a female with height=175 cm:

Stata: lincom _cons+height*175

�������'��7�%87-���9� 3����#�������'��7�%87-���9� 3����#�������'��7�%87-���9� 3����#�������'��7�%87-���9� 3����#

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/���/���/���/��� ����������������0 ��0 ��0 ��0 �������-���.������-����"��-����1(�2�0 3���43-��5�6�����-���.������-����"��-����1(�2�0 3���43-��5�6�����-���.������-����"��-����1(�2�0 3���43-��5�6�����-���.������-����"��-����1(�2�0 3���43-��5�6�������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������##�� !��������' ����'�(&��#�###����'��&��&�����!'�#'!&�������##�� !��������' ����'�(&��#�###����'��&��&�����!'�#'!&�������##�� !��������' ����'�(&��#�###����'��&��&�����!'�#'!&�������##�� !��������' ����'�(&��#�###����'��&��&�����!'�#'!&

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

Note:Prediction using x-values outside the range of observed x-values(extrapolation) should in general be avoided.

The t-test assess the hypothesis that pefr= 0 for a 175 cm high female!!! (nonsense in this case).

To test the hypothesis that pefr is e.g. 400, write

lincom _cons+height*175-400

Page 9: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

9

17

If we ignore the explanatory variable, the total variation of theresponse variable y is the adjusted sum of squares (corrected total)

2( )Total iSS y y= −�When the explanatory variable x is included in the analysis wemay ask: How much of the variation in y is explained by thevariation in x ? i.e. How large would the variation in pefr be, if thepersons have the same height?.

ˆ ˆ( ) ( )i i i iy y y y y y− = − + −residual Deviation: fitted – overall mean

2 2 2ˆ ˆ( ) ( ) ( )Total Residual Modeli i i iSS y y y y y y SS SS= − = − + − = +� � �

Variation about regression= Residual

Variation explained by regression= Model

DECOMPOSITION OF THE TOTAL VARIATION

18

The degrees of freedom are decomposed in a similar way

1 ( 2) 1Tot Res Modf f f

n n

= +− = − +

Stata: All this appears in the analysis of variance table in the output from the regress command

MS = mean square = SS/df����������������������������������������������������

� ��������������������� ��������������������� ��������������������� ���������������������������� ������������������ �������������������� �������������������� �������������������� �� �� �� �� �� ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� ��������������������� ���������������������� ���������������������� ���������������������� �

� ������!!����!!���������!!����!!���������� ������!!����!!���������!!����!!���������� ������!!����!!���������!!����!!���������� ������!!����!!���������!!����!!���������"� �"� �"� �"� � ������������#�#!!!������������#�#!!!������������#�#!!!������������#�#!!!$��%�����&&&� �!!!!�������!� '�!!�(���������$$��%�����&&&� �!!!!�������!� '�!!�(���������$$��%�����&&&� �!!!!�������!� '�!!�(���������$$��%�����&&&� �!!!!�������!� '�!!�(���������$�����)������������#��!�!�)������������#��!�!�)������������#��!�!�)������������#��!�!���������������������������������������������������������������������������������������������������������������������������������������������������� *�+*�+*�+*�+ $$$$�����)��������#�#(('�)��������#�#(('�)��������#�#(('�)��������#�#(('

, -����#��#'� ������!��!�#'��!�&'��������$ -���.���������� , -����#��#'� ������!��!�#'��!�&'��������$ -���.���������� , -����#��#'� ������!��!�#'��!�&'��������$ -���.���������� , -����#��#'� ������!��!�#'��!�&'��������$ -���.���������� ����������������

The mean squares are two independent variance estimates. If the slope is 0, they both estimate the population variance . 2σ

Page 10: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

10

19

Intuitively, if the ratio is large the model explains a largepart of the variation and the slope must therefore differ from zero. This is formalized in the test statistic , which follows anF-distribution (lecture 2, page 44), if the hypothesis is true. Large valuesleads to rejection of the hypothesis.

R-squared as a measure of explained variationThe total variation is reduced from 101107.644 to 88856.2222, i.e. thereduction is 12.12% or 0.1212 which is found in the right panel as theR-squared value. Adj R-squared is a similar measure of explainedvariation, but computed from the mean squares. R-squared is also called the ”coefficient of determination”.

The F-test of the hypothesis: 0β =/Mod ResSS SS

/Mod ResF MS MS=

05.65 2.38F tβ == = =� ��������������������� ��������������������� ��������������������� ���������������������������� ������������������ �������������������� �������������������� �������������������� �� �� �� �� �� ������������������������������������

���������������������������������������������������������������������������������������������������������������������������������������������������� ��������������������� ���������������������� ���������������������� ���������������������� �� ������!!����!!���������!!����!!���������� ������!!����!!���������!!����!!���������� ������!!����!!���������!!����!!���������� ������!!����!!���������!!����!!���������"� �"� �"� �"� � ������������#�#!!!������������#�#!!!������������#�#!!!������������#�#!!!

$��%�����&&&� �!!!!�������!� '�!!�(���������$$��%�����&&&� �!!!!�������!� '�!!�(���������$$��%�����&&&� �!!!!�������!� '�!!�(���������$$��%�����&&&� �!!!!�������!� '�!!�(���������$�����)������������#��!�!�)������������#��!�!�)������������#��!�!�)������������#��!�!���������������������������������������������������������������������������������������������������������������������������������������������������� *�+*�+*�+*�+ $$$$�����)��������#�#(('�)��������#�#(('�)��������#�#(('�)��������#�#(('

, -����#��#'� ������!��!�#'��!�&'��������$ -���.���������� , -����#��#'� ������!��!�#'��!�&'��������$ -���.���������� , -����#��#'� ������!��!�#'��!�&'��������$ -���.���������� , -����#��#'� ������!��!�#'��!�&'��������$ -���.���������� ����������������

Note:

20

A linear regression describes the relationship between two variables, but not the ”strength” of this relation.

The correlation coefficient is a measure of the strength of a linear relation.

-50

050

difs

ys

-40 -20 0 20 40difdia

Example: (fishoil.dta)Fish oil trial(see: day 2, page 11).

What is the relationshipbetween the change in diastolic and in systolicblood pressure in thefish oil group?

THE CORRELATION COEFFICIENT

Page 11: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

11

21

Basic properties of the correlation coefficient:

Pearson’scorrelationcoefficient

2 2

( ) ( )

( ) ( )i i

xy

i i

x x y yr r

x x y y

− ⋅ −= =

− ⋅ −�� �

• Change of origin and/or scale of x and/or y will not changethe size of r (the sign is changed if the ordering is reversed)

1 1xyr− ≤ ≤�

If the observations lie exactly on a straightline with positive/negative slope

xy yxr r=�

1xyr�

= ± ��

Use a linear regression analysis?No obvious choice of response. The problem is symmetric.

Here the sample correlation coefficient may be a more useful way to summarize the strenght of the linear relationship between the two variables.

symmetric in x and y0xyr =� if x and y are independent

22

Stata:correlate difsys difdia if grp==1

| difsys difdia-------------+------------------

difsys | 1.0000difdia | 0.2332 1.0000

The correlation is positive indicating a positive linear relationship.

The sample correlation coefficient r is an estimate of the population correlation coefficient .ρ

A test of the hypothesis is identical to the t-test ofthe hypothesis . It can be shown that

0ρ =0β =

2

2

ˆ 02ˆ( ) 1

rt n

se r

ββ

−= = −−

Stata: The command pwcorr difsys difdia,sig gives thecorrelation coefficient and the p-value of this test.

For a linear regression: r2 = R-Squared = Explained variation

Page 12: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

12

23

������ ������

����� ������

Use of correlationcoefficients:Correlations arepopular, but whatdo they tell aboutdata?

Conclusion:Always make plot of the data!

Note:The correlationcoefficient onlymeasures thelinear relationship

24

Misuse of correlation coefficients

Comparison of two measurements methods

Two studies, each comparing two methods of measuring heights ofmen.

In both studies 10 men were measured twice, once with each method.

In such studies a correlation coefficient is often used to quantify theagreement (or disagreement) between the methods.This is a bad idea!

In general:A correlation should primarily be used to evaluate the association between two variables, when the setting is truly symmetric.

The following examples illustrate misuse or rathermisinterpretation of correlation coefficients.

Page 13: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

13

25

��� ��� ��� ��� ��

���

���

���

���

�������������� �������

��������

� �������

��� ��� ��� ��� ��

���

���

���

���

��������������� �������

��������

� �������

Is a higher correlation evidence of a better agreement ?

Higher correlation in left panel

No, this is wrong!!!

A difference vs. average plot reveals that there is a large disagreementbetween method 1 and 2, see next page.

Example 1

26

��� ��� ��� ��� ��

���

��

��

��

��

��

�������������������

�� ����������� ����������

��� ��� ��� ��� ��

���

��

��

��

��

��

�������������������

�� ����������� ����������

Compare the average disagreement between the two methods!

5.6 cm

0.2 cm

Note:The correlation coefficient does not give you any information onwhether or not the observations are located around the line x = y, i.e. whether or not the methods show any systematic disagreement.

Page 14: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

14

27

��� ��� ��� �� ���

���

���

���

��

���

������������ �������

��������

� �������

��� ��� ��� �� ���

���

���

���

��

���

������������� �������

��������

� �������

Example 2:Two other studies. The same basic set-up.

• No systematic disagreement (points are located around the line x = y).

• Correlation coefficient in left panel (method 1 vs 2) larger thancorrelation coefficient in right panel (method 3 vs 4).

Better agreement between method 1 and 2 than method 3 and 4 ???

The plots show:

28

��� ��� ��� �� ���

��

��

��

��

�������������������

�� ��������� ������������

��� ��� ��� �� ���

��

��

��

��

�������������������

�� ����������� ����������

The answer is: No!!!

Compare the standard deviations of the differences(Limits of agreement = 2 x s.d., see lecture 2, p. 29)

s.d.=2.8 cm

s.d.=1.6 cm

Note:The correlation is larger between method 1 and 2 because the variation in heights is larger in this study.The correlation coefficient says more about the persons than about themeasurement methods!

Page 15: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

15

29

NON-PARAMETRIC METHODS FOR TWO-SAMPLE PROBLEMS

Non-parametric methods, or distribution-free methods, are a classof statistical methods, which do not require a particular parametric form of the populaiton distribution.

Advantages: Non-parametric methods are based on fewer and weakerassumptions and can therefore be applied to a wider range of situations.

Disadvantages: Non-parametric methods are mainly statistical test. Use of these methods may therefore overemphasize significance testing, which is only a part of a statistical analysis.

Non-parametric tests do not depend on the observed values in thesample(s), but only the on the ordering or ranking. The non-parametricmethods can therefore also be applied in situations where the outcomeis measured on some ordinal scale, e.g. a complication registered as–, +, ++, or +++.

A large number of different non-parametric tests has been developed.Here only a few simple test in widespread use will be discussed.

30

TWO INDEPENDENT SAMPLES: WILCOXON-MANN-WHITNEY RANK SUM TESTIllustration of the basic ideaConsider a small experiment with 5 observations from two groups

Active treatmentControl

1 2

1 2 3

,, ,

x xy y y

Hypothesis of interest: the same distribution in the two samples, i.e.no effect of active treatment.

For data values 15, 26, 14, 31, 21 (in arbitrary order) there are 120 (=5!)different ways to allocate these five values to . Eachallocation is characterized by the ordering of the units. Each orderingis equally likely if the hypothesis is true.

1 2 1 2 3, , , ,x x y y y

An ordering is determined by the ranks of the observations. If e.g.

2 3 1 2 114 15 21 26 31x y x y y= < = < = < = < =

then 1 2 1 2 3( ) 3, ( ) 1, ( ) 5, ( ) 4, ( ) 2rank x rank x rank y rank y rank y= = = = =

Page 16: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

16

31

Basic idea:Compute sum of rank in treatment group. If this sum is large or small the hypothesis is not supported by the data.

There are different combinations of ranks for the

observations in the treatment group. Under the hypothesis each of these

is equally likely (i.e. has probability 0.10).

5 5 4 310

3 3 2 1� ⋅ ⋅= =� � ⋅ ⋅� �

123,4,591,3,5

112,4,581,3,4

102,3,581,2,5

92,3,471,2,4

101,4,561,2,3

sumrankssumranks

Note: The distribution is symmetric.

6 7 8 9 10 11 120.0

0.1

0.2

Pro

babi

lity

Sum of ranks in treatment group

observed value

observed configurationWe have p-value = 4·0.1=0.4

32

General case

Data: Two samples of independent observationsGroup 1 from a population with distribution functionGroup 2 from a population with distribution function

1

2

1 2

1 2

, , ,, , ,

n

n

x x xy y y

X

Y

FF

Let denote the total number of observations.1 2N n n= +

Hypothesis: The x’s and the y’s are observations from the same (continuous) distribution, i.e. . The alternatives of special interest: the y’s are shifted upwards (or downwards)

X YF F=

Test statistic (Wilcoxon’s ranksum test)

1

2

TT

==

Sum of ranks in group 1, orSum of ranks in group 2

A two-sided test will reject the hypothesis for large or small values of . Note: The two test statistics are equivalent since1 2( )T Tor

2 1

( 1)2

N NT T

+= −

Page 17: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

17

33

Some properties of the test statisticIf the hypothesis is true, the distribution of the test statistic is completely specified. In particular; the distribution is symmetric and we have

1 1 2 2

1 2 1 2

( ) ( 1) / 2 ( ) ( 1) / 2

( ) ( ) ( 1) /12

E T n N E T n N

Var T Var T n n N

= ⋅ + = ⋅ += = ⋅ ⋅ +

Moreover, mean and the variance are given by

1 1 1 1 2

2 2 2 2 1

( 1) / 2 ( 1) / 2

( 1) / 2 ( 1) / 2

n n T n N n

n n T n N n

⋅ + ≤ ≤ ⋅ + +⋅ + ≤ ≤ ⋅ + +

The formula for the variance is only valid if all observations are distinct.If the data contain tied observations, i.e. observations taking the same value, the variance is smaller and a correction is necessary. The general variance formula becomes

( )31 21 2 3

( 1) 1( ) ( ) 1

12 i isets of ties

n n NVar T Var T k k

N N

� �⋅ ⋅ += = − −� �−� ��

where

ik = number of identical observations in the i’th set of tied values

34

Finding the p-valueThe exact distribution of the of rank sum statistic under the hypothesis is rather complicated, but is tabulated for small sample sizes, see e.g. Armitage, Berry & Matthews, Table A7 or Altman, Table B10. Note: These tables are appropriate for untied data only. The p-value will be too large if the tables are used for tied data.

For larger sample size (e.g. N > 30) the distribution of the rank sum statistic is usually approximated by a normal approximation with the same mean and variance, i.e. the test statistic

1 1

1

( )( )

T E Tz

Var T−=

1 1

1

| ( ) | 0.5( )

T E Tz

Var T− −=

is approximately a standard normal variate if the hypothesis is true.

Some programs (and textbooks) use a continuity correction, and the test statistics then becomes

Page 18: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

18

35

Rank-sum test with StataExample. In the lectures day 2 we used a t-test to compare the change in diastolic blood pressure in pregnant women who were allocated to either supplementary fish oil or a control group. The analogous non-parametric test is computed by the command

use fishoil.dtaranksum difdia , by(grp)

,; ,; ,; ,; �����/����/����/����/���<%�� � 3<%�� � 3<%�� � 3<%�� � 3 �3=�3=�3=�3=���������33�����33�����33�����33����<7%-3�>��-��-<7%-3�>��-��-<7%-3�>��-��-<7%-3�>��-��-8�/8�/8�/8�/ ���������������������������� �� �� �� �� �3=���������/��-���3=���������/��-���3=���������/��-���3=���������/��-��

��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� 3-� ���������!�����������(���������(#���� 3-� ���������!�����������(���������(#���� 3-� ���������!�����������(���������(#���� 3-� ���������!�����������(���������(#����%�7� %���������!�'��������''�!������ ' ����%�7� %���������!�'��������''�!������ ' ����%�7� %���������!�'��������''�!������ ' ����%�7� %���������!�'��������''�!������ ' ���

��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� �%3������������#�������(! ��������� �%3������������#�������(! ��������� �%3������������#�������(! ��������� �%3������������#�������(! ��������(! �(! �(! �(! �

�3�+��-���5�%3����� #�#��!��3�+��-���5�%3����� #�#��!��3�+��-���5�%3����� #�#��!��3�+��-���5�%3����� #�#��!��+��-�3-�� ��-%�������+��-�3-�� ��-%�������+��-�3-�� ��-%�������+��-�3-�� ��-%�����������!�'�!��!�'�!��!�'�!��!�'�!�

�����������������������������������������+��-���5�%3������� � & '�##�+��-���5�%3������� � & '�##�+��-���5�%3������� � & '�##�+��-���5�%3������� � & '�##? @�? @�? @�? @��%��%�8�/�%��%�8�/�%��%�8�/�%��%�8�/��� 3-� �������� 3-� �������� 3-� �������� 3-� ������%��%�8�/�%��%�8�/�%��%�8�/�%��%�8�/���%�7� %�����%�7� %�����%�7� %�����%�7� %��

A����A����A����A��������#�'�'#�'�'#�'�'#�'�'"� �"� �"� �"� � ���A������#�� �!���A������#�� �!���A������#�� �!���A������#�� �! two-sided p-value

Stata computesthe approximatestandard normal variate withouta continuity correction

36

The rank-sum test can also be used to analyse a 2×C table withordered categories. In lecture 4 (page 42) first parity births in skejby-cohort.dta were cross-classified according to mother’s smoking habits and year of births.

To evaluate if the prevalence of smoking has changed we use a rank-sum test to compare the distribution on birth year among smokersand non-smokers. ranksum year if parity==0 , by(mtobacco)gives

- ��� - ��� - ��� - ��� ���������������������������� �� �� �� �� �3=���������/��-���3=���������/��-���3=���������/��-���3=���������/��-����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

� =��������������������'�!!��������!'(#�� =��������������������'�!!��������!'(#�� =��������������������'�!!��������!'(#�� =��������������������'�!!��������!'(#�3 3� =����������#'#������##'#� �����#(�!�'#3 3� =����������#'#������##'#� �����#(�!�'#3 3� =����������#'#������##'#� �����#(�!�'#3 3� =����������#'#������##'#� �����#(�!�'#

��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� �%3�����������&��������&#!'������ �%3�����������&��������&#!'������ �%3�����������&��������&#!'������ �%3�����������&��������&#!'��������&#!'����&#!'����&#!'����&#!'�

�3�+��-���5�%3�����!��(���#(�3�+��-���5�%3�����!��(���#(�3�+��-���5�%3�����!��(���#(�3�+��-���5�%3�����!��(���#(�+��-�3-�� ��-%�����+��-�3-�� ��-%�����+��-�3-�� ��-%�����+��-�3-�� ��-%��������!� (��#&!� (��#&!� (��#&!� (��#&

�����������������������������������������+��-���5�%3�������!��! ��#(�+��-���5�%3�������!��! ��#(�+��-���5�%3�������!��! ��#(�+��-���5�%3�������!��! ��#(? @�? @�? @�? @�>���- ��� >���- ��� >���- ��� >���- ��� ��� =��������� =��������� =��������� =������>���- ��� >���- ��� >���- ��� >���- ��� ��3 3� =�����3 3� =�����3 3� =�����3 3� =���

A����A����A����A�����������& ���& ���& ���& "� �"� �"� �"� � ���A������#�!��'���A������#�!��'���A������#�!��'���A������#�!��'

Page 19: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

19

37

Mann-Whitney’s U test

Some statistical program packages compute a closely related test statistic,Mann-Whitney’s U test. This test is equivalent to the Wilcoxon rank-sumtest, but is derived by a different argument.

Basic idea: Consider all pairs of observations (x,y) with one observationfrom each sample. Let

XY

YX

UU

==

number of pairs with x < y number of pairs with y < x

A pair with x = y is couinted as ½ in both sums.

Extreme values of these test statistics suggest the hypothesis is not supported by the data. One may show that

1 1 1 2 2 2( 1) / 2 ( 1) / 2YX XYU T n n U T n n= − ⋅ + = − ⋅ +

The distributions of these test statistics are therefore a simple translationof the distribution of the rank-sum and the same p-value is obtained.

38

General comments on the rank-sum testFor comparison of two independent samples the rank-sum test is a robust alterative to the t-test. For detecting a shift in locationthe rank-sum test is never much less sensitive than the t-test, but may be much better if the distribution is far from a normal distribution.

The rank-sum test is not well suited for comparison of two populations, which differ in spread, but have essentially the same mean.

Non-parametric methods are primarily statistical test. For the shift in location situation, i.e. when is distributed as , where is theunknown shift we may estimate the shift parameter as the median of the

differences between one observation from each sample, and a confidence interval for the shift parameter can then be obtained from the rank-sum test. This procedure is not included in Stata.

X Y δ+ δ

δ1 2n n⋅

Note: A monotonic transformation of the data, e.g. by a logarithm hasno impact on the value of the rank-sum statistic

Page 20: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

20

39

TWO PAIRED SAMPLES: WILCOXON’S SIGNED RANK-SUM TESTBasic problem: Analysis of paired data without assuming normality of the variation.

Data: A sample of n pairs of observations. 1 1 2 2( , ),( , ), , ( , )n nx y x y x y�

Preliminary model considerations:

Question: Does the distribution of the x’s differ from the distribution of the y’s?

For a pair of observation we may write

where and represent the expected response of x and y, and where and are error terms.

1

2

x ey e

αα δ

= += + +

α α δ+1e 2e

Assume: Error terms from different pairs are independent and follow the same distribution.

40

If the error terms and follow the same distribution then the difference

has a symmetric distribution with median (and mean) .

1e 2e

d y x= −

δStatistical model: The n differences are regarded as a random sample from a symmetric distribution F with median .

1 2, , , nd d d�

δEstimation: The population median is estimated by the sample median

Hypothesis: The x’s and the y’s have the same distribution, or equivalently 0.δ =The sign test A simple test statistic is based on the signs of the differences. If the median is 0, positive and negative difference should be equally likely,and the number of positive differences therefore follows a binomial distribution with p = 0.5. If some differences are zero the sample size isreduced accordingly.

Stata: signtest hgoral=craft

Page 21: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

21

41

Wilcoxon’s signed rank sum testThe sign test utilizes only the sign of the differences, not their magnitude.A more powerful test is available is both sign and size of the differences are taken into account.

Basic idea: Sort the differences in ascending order of their absolute value(i.e ignoring the sing of the differences). Use the sum of the ranks of thepositive differences as the test statistic.

Wilcoxon’s signed rank-sum test

T+ = sum of ranks of positive differences, when differences areare ranked in ascending order according to absolute value.

Alternatively, , defined analogously, can be used. The two test statistics are equivalent.

T−

Basic properties:With no ties and zeros present in the sample of differences, the teststatistic has a symmetric distribution and

0 ( 1) / 2

( ) ( 1) / 4 ( ) ( 1) (2 1) / 24

T n n

E T n n Var T n n n+

+ +

≤ ≤ ⋅ += ⋅ + = ⋅ + ⋅ +

42

Ties and zeroes among differencesMid ranks are used if some of the differences have the same absolute value, i.e. these differences are given the average value of the ranks thatwould otherwise apply.

Differences that are equal to zero are not included in any of the test statistics.

A formula for the variance corrected for ties and zeroes exists and is used by Stata. Zeroes are usually accounted for by ignoring these differences and reducing the sample size according.

Finding the p-valueThe exact distribution of the of Wilcoxon’s signed rank-sum test under the hypothesis is tabulated for small sample sizes (n � 25), see e.g. Armitage, Berry & Matthews, Table A6 or Altman, Table B9.

Note: These tables are appropriate for untied data only. The p-value will be too large if the tables are used for data with ties.

Page 22: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

22

43

For larger sample size (n > 25 ) the distribution of the test statistic is approximated by a normal approximation with the same mean and variance, i.e. the test statistic

( )( )

T E Tz

Var T+ +

+

−=

is approximately a standard normal variate if the hypothesis is true.

Stata computes this test statistic using a variance estimate that allows for ties and zeroes.

Some programs (and textbooks) use a continuity correction, and the test statistics then becomes

| ( ) | 0.5( )

T E Tz

Var T+ +

+

− −=

Normal approximation

The continuity correction has little or no effect even for moderate sample sizes and can safely be ignored.

44

<%�� � 3<%�� � 3<%�� � 3<%�� � 3 �%83���%83���%83���%83�������3=�-��-�3=�-��-�3=�-��-�3=�-��-�%83���������%83���������%83���������%83�������� �� �� �� �� ����3=�������/��-������3=�������/��-������3=�������/��-������3=�������/��-��

��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������/ �%-%5�����������!�����������'����������#�/ �%-%5�����������!�����������'����������#�/ �%-%5�����������!�����������'����������#�/ �%-%5�����������!�����������'����������#�3�8-%5�����������&���������� �����������#�3�8-%5�����������&���������� �����������#�3�8-%5�����������&���������� �����������#�3�8-%5�����������&���������� �����������#�

A�� ����������#�����������#�����������#A�� ����������#�����������#�����������#A�� ����������#�����������#�����������#A�� ����������#�����������#�����������#��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

�����������!#���������!�#��������������������!#���������!�#��������������������!#���������!�#��������������������!#���������!�#���������!�#!�#!�#!�#

�3�+��-���5�%3��������'�'��#�3�+��-���5�%3��������'�'��#�3�+��-���5�%3��������'�'��#�3�+��-���5�%3��������'�'��#�+��-�3-�� ��-%����������#�##�+��-�3-�� ��-%����������#�##�+��-�3-�� ��-%����������#�##�+��-�3-�� ��-%����������#�##�+��-�3-�� ��A�� ��������#�##�+��-�3-�� ��A�� ��������#�##�+��-�3-�� ��A�� ��������#�##�+��-�3-�� ��A�� ��������#�##

�����������������������������������������+��-���5�%3����������'�'��#�+��-���5�%3����������'�'��#�+��-���5�%3����������'�'��#�+��-���5�%3����������'�'��#? @�-����-&? @�-����-&? @�-����-&? @�-����-&

A�������� &A�������� &A�������� &A�������� &"� �"� �"� �"� � ���A������#��� (���A������#��� (���A������#��� (���A������#��� (

Wilcoxon’s signed rank-sum test with StataExample. In the lectures day 3 we used a paired t-test to compare counts of T4 and T8 cells in blood from 20 individuals. The analogous non-parametric test is computed by the command

use tcounts.dtasignrank t4=t8

No correction sincethese data have no ties or zeroes

The p-value is larger than 0.05, sothe difference between the distribution of T4 and T8 cells is not statistically significant

Page 23: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

23

45

Example continuedDiagnostic plots of these data (day 3, page 31 and 38) suggest that the counts initially should be log-transformed. Note: Transformations of the basic data, the x’s and the y’s, may change the value of Wilcoxon’s signed rank-sum test.

signrank logt4=logt8

�%83���������%83���������%83���������%83�������� �� �� �� �� ����3=�������/��-������3=�������/��-������3=�������/��-������3=�������/��-����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

/ �%-%5�����������!�����������#����������#�/ �%-%5�����������!�����������#����������#�/ �%-%5�����������!�����������#����������#�/ �%-%5�����������!�����������#����������#�3�8-%5�����������&���������� #����������#�3�8-%5�����������&���������� #����������#�3�8-%5�����������&���������� #����������#�3�8-%5�����������&���������� #����������#�

A�� ����������#�����������#�����������#A�� ����������#�����������#�����������#A�� ����������#�����������#�����������#A�� ����������#�����������#�����������#��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

�����������!#���������!�#��������������������!#���������!�#��������������������!#���������!�#��������������������!#���������!�#���������!�#!�#!�#!�#

�3�+��-���5�%3��������'�'��#�3�+��-���5�%3��������'�'��#�3�+��-���5�%3��������'�'��#�3�+��-���5�%3��������'�'��#�+��-�3-�� ��-%����������#�##�+��-�3-�� ��-%����������#�##�+��-�3-�� ��-%����������#�##�+��-�3-�� ��-%����������#�##�+��-�3-�� ��A�� ��������#�##�+��-�3-�� ��A�� ��������#�##�+��-�3-�� ��A�� ��������#�##�+��-�3-�� ��A�� ��������#�##

�����������������������������������������+��-���5�%3����������'�'��#�+��-���5�%3����������'�'��#�+��-���5�%3����������'�'��#�+��-���5�%3����������'�'��#

? @�� 8-����� 8-&? @�� 8-����� 8-&? @�� 8-����� 8-&? @�� 8-����� 8-&A������� &#A������� &#A������� &#A������� &#

"� �"� �"� �"� � ���A������#�#(�#���A������#�#(�#���A������#�#(�#���A������#�#(�#

Note: the number of positive ranks are unchanged, but the sum of these ranks has changed.

The p-value has also changed(a little).

46

NON-PARAMETRIC CORRELATION COEFFICIENTSNon-parametric correlation coefficients measure the strength of the association between continuous variables or between ordered categorical variables.

Spearman’s rhoData: A sample of n pairs of observations. 1 1 2 2( , ),( , ), , ( , )n nx y x y x y�

Procedure: Rank the x’s and the y’s, and let

( ) ( )i i i iR rank x Q rank y= =Then Spearman’s rho is defined as the usual correlation coefficient computed from the ranks, i.e.

2 2

( )( )

( ) ( )

i ii

i ii i

R R Q Q

R R Q Qρ

� �− − �=− −

� �We have . If Y increase with X then is positive, if Y decrease with X then is negative.

1 1ρ− ≤ ≤ρρ

Page 24: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

24

47

If X and Y are independent and the data have no tied observationsthen 1

( ) 0 ( )1

E Varn

ρ ρ= =−

From Spearman’s rho a non-parametric test of independence between X and Y can be derived.

The exact distribution of Spearman’s rho under the hypothesis of independence is complicated, but has been tabulated for small sample sizes, see e.g. Altman, Table B8.

Usually the p-value is found by computing the test statistic

2

21S

nt ρ

ρ−=

−which approximately has a t-distribution with n – 2 degrees of freedom.

Stata’s command spearman uses this approach to compute the p-value,see below.

48

Kendall’s tauA pair of pairs of observations are called concordantif and or if and , i.e. when the twopairs are ordered in the same way according to X and according to Y.

( , ), ( , )i i j jX Y X Yi jX X< i jY Y< i jX X> i jY Y>

Similarly, a pair of pairs are called discordant if the ordering according to Y is a reversal of the ordering according to X.

Let C = number of concordant pairs in the sampleD = number of discordant pairs in the sample

Ties are handled by adding ½ to both C and D.

Then number of pairs of pairs in the sample ( 1) / 2C D n n+ = ⋅ − =

Let then Kendall’s tau (or tau-a) is defined as

( 1) / 2S

n nτ =

⋅ −

Kendall’s tau-b uses a slightly different denominator to allow for ties.

S C D= −

Page 25: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

25

49

Properties of Kendall’s tau

We have . When X and Y are independent and no ties are present in the data it can be shown that

1 1τ− ≤ ≤

2 (2 5)( ) 0 ( )

9 ( 1)n

E Varn n

τ τ ⋅ += =⋅ −

Formulas valid for tied data are complicated.

Also from Kendall’s tau a non-parametric test of independence between X and Y can be derived.

The test statistic is usually based on a normal approximation to S, the numerator of Kendall’s tau. A continuity correction is routinely applied.

Stata’s command ktau uses this approach to compute the p-value,see below.

Note:Both Spearman’s rho and Kendall’s tau are unchanged if one or both of the series of observations are transformed.

50

Non-parametric correlation coefficients with StataExample. Consider the data with counts of T4 and T8 cells in blood from 20 persons, but this time we want to describe the association between the two counts.

spearman t4 t8������ �������� �������� �������� �� �� �� �� �� �������!#�������!#�������!#�������!#�/��3B���/��3B���/��3B���/��3B���7 �7 �7 �7 ��������#� �����������#� �����������#� �����������#� ���

,��-� ��? @�-��3��-&����%3��/�3��3-,��-� ��? @�-��3��-&����%3��/�3��3-,��-� ��? @�-��3��-&����%3��/�3��3-,��-� ��? @�-��3��-&����%3��/�3��3-"� �"� �"� �"� � ���-����������#�##�(���-����������#�##�(���-����������#�##�(���-����������#�##�(

ktau t4 t8������ �������� �������� �������� �� �� �� �� �� �������!#�������!#�������!#�������!#

C�3���B��C�3���B��C�3���B��C�3���B��-�-�-�-��������������#��#�����������#��#�����������#��#�����������#��#��C�3���B��C�3���B��C�3���B��C�3���B��-�-�-�-��������� ��������#��#����������#��#����������#��#����������#��#��C�3���B���� ����������( C�3���B���� ����������( C�3���B���� ����������( C�3���B���� ����������(

�.� ���� �����������#�&!!�.� ���� �����������#�&!!�.� ���� �����������#�&!!�.� ���� �����������#�&!!

,��-� ��? @�-��3��-&����%3��/�3��3-,��-� ��? @�-��3��-&����%3��/�3��3-,��-� ��? @�-��3��-&����%3��/�3��3-,��-� ��? @�-��3��-&����%3��/�3��3-"� �"� �"� �"� � ���A����������#�##!����� 3-%3�%->�� ����-������A����������#�##!����� 3-%3�%->�� ����-������A����������#�##!����� 3-%3�%->�� ����-������A����������#�##!����� 3-%3�%->�� ����-���

S = C – D

The hypothesisof independenceis rejected in both cases.Persons with ahigh T4 value typically also havea high T8 value.

Note: The hypothesis of independence differs for the hypothesistested with a paired two-sample test

Page 26: Ph.D. COURSE IN BIOSTATISTICS DAY 5 · 1 1 Ph.D. COURSE IN BIOSTATISTICS DAY 5 REGRESSION ANALYSIS How do we describe and analyze the relationship or association between two quantitative

26

51

ExampleNon-parametric correlation coefficients can also be used to analyse aR×C table with ordered categories. In lecture 4 (page 42) births in December 1993 included in skejby-cohort.dta were cross-classified according to age of the mother and parity of the child.

34358105180Total

13833525330-

13020407025-29

7551357-24

Total2-10mother

ParityAge of

The hypothesis of independence in this 3×3 table with ordered categoriescan be assessed by the following commands

gene agecat=(mage>24)+(mage>29) if mage<.gene paricat=(parity>0)+(parity>1) if parity<.spearman agecat paricat if year==1993 & mon==12

52

For comparison the same analysis of the ungrouped data isspearman mage parity if year==1993 & mon==12

Output������ �������� �������� �������� �� �� �� �� �� �������������������������������������/��3B���/��3B���/��3B���/��3B���7 �7 �7 �7 ��������#�!&#'��������#�!&#'��������#�!&#'��������#�!&#'

,��-� ��? @�,��-� ��? @�,��-� ��? @�,��-� ��? @�8��-8��-8��-8��- 3��3��3��3��/�%�-/�%�-/�%�-/�%�- ������������%3��/�3��3-%3��/�3��3-%3��/�3��3-%3��/�3��3-

"� �"� �"� �"� � ���-����������#�####���-����������#�####���-����������#�####���-����������#�####

������ �������� �������� �������� �� �� �� �� �� �������������������������������������/��3B���/��3B���/��3B���/��3B���7 �7 �7 �7 ��������#��!!���������#��!!���������#��!!���������#��!!�

,��-� ��? @�8��3��/�%->����,��-� ��? @�8��3��/�%->����,��-� ��? @�8��3��/�%->����,��-� ��? @�8��3��/�%->����%3��/�3��3-%3��/�3��3-%3��/�3��3-%3��/�3��3-

"� �"� �"� �"� � ���-����������#�####���-����������#�####���-����������#�####���-����������#�####

As expected the correlation is stronger in the ungrouped data.Note: The usual chi-square of independence, which does not take the ordering into account, is also statistically significant. We get X2 = 28.57 on 4 degrees of freedom and p-value = 0.000001.