Sas corr

9
CORR procedure 2013/3/6

description

 

Transcript of Sas corr

Page 1: Sas corr

CORR procedure2013/3/6

Page 2: Sas corr

The CORR procedure gives you

• Pearson product-moment correlation• Rank correlation:• Spearman rank-order correlation• Kendall’s tau-b coefficient

• Hoeffding’s measure of dependence, D• Partial correlations for Pearson, Spearman, and Kendall’s

measurement

Page 3: Sas corr

Syntax

PROC CORR <options> ;BY variables ;FREQ variable ;ID variables ;PARTIAL variables ;VAR variables ;WEIGHT variable ;WITH variables ;

RUN;

指定計算淨相關時的 control variable

proc corr; var x1 x2; with y1 y2 y3;run;

Page 4: Sas corr

Example 1

data example1;do i=1 to 200;

x=10*rannor(100);y=x+10*rannor(3);output;

end;drop i;;

proc corr plots=scatter spearman;run;

Page 5: Sas corr

Example 2 (SAS 9.2 guide)

data Fitness;input Age Weight Oxygen RunTime @@;datalines;

44 89.47 44.609 11.37…

;proc corr data=Fitness plots=matrix(histogram);var RunTime Weight;partial Oxygen Age;run;

Without control

With control

不指定 var

Page 6: Sas corr

Questions ?

Page 7: Sas corr

Why correlation?

• Suppose 2 random variables Y and X, where Y is a variable you cannot observe directly, but X is the variable you can observe directly.• If Y and X are dependent in a certain relationship f(X), then we can

observe Y through X by the relationship

• e.g. Y ~ Happiness, X ~ Smiling

Page 8: Sas corr

Pearson’s r (for linear correlation)

• How many variance of Y can be explained by X

Var Y

Var X

Page 9: Sas corr

Correlation does not “imply” causation• Tufte:

• "Empirically observed covariation is a necessary but not sufficient condition for causality."

• "Correlation is not causation but it sure is a hint."

• If Y and X correlate significantly, then one of the following may be true:• X causes Y• Y causes X• X and Y are consequences of a common cause other than X or Y• Just coincidence

• What does “cause” mean actually?• It is a philosophical question