Setting
We will once again visualize the act of ordering food at In-n-Out.
: number of fries orders : number of beef patties ordered
Covariance
We define the covariance of random variables as
Correlation
Correlation
Just like how the
- If
, the data are constant, and simply return - If
, the data are constant, and simply return
- Compute the correlation in the In-n-Out setting
Interpretation of Correlation
Ranges
Aside: the infinity-sized expected values might happen in continuous distributions.
Interpretation of Correlation
Early development of the concept of correlation was done by Karl Pearson. Pearson suggested the following interpretations of the correlation (but there is no strict rule for this):
: virtually uncorrelated : slightly correlated : strongly correlated
Examples of Correlation
= function(x, r = 0.9){
correlatedValues = r**2
r2 = 1-r2
ve = sqrt(ve)
SD = rnorm(length(x), mean=0, sd=SD)
e = r*x + e
y return(y)
}
= rnorm(100, mean = 0, sd = 1)
x1 = correlatedValues(x1, r = -0.9)
y1 = rnorm(100, mean = 0, sd = 1)
x2 = correlatedValues(x2, r = -0.4)
y2 = rnorm(100, mean = 0, sd = 1)
x3 = correlatedValues(x3, r = 0.0)
y3 = rnorm(100, mean = 0, sd = 1)
x4 = correlatedValues(x4, r = 0.4)
y4 = rnorm(100, mean = 0, sd = 1)
x5 = correlatedValues(x5, r = 0.9)
y5
<- data.frame(x1, y1, "group 1")
df1 <- data.frame(x2, y2, "group 2")
df2 <- data.frame(x3, y3, "group 3")
df3 <- data.frame(x4, y4, "group 4")
df4 <- data.frame(x5, y5, "group 5")
df5 names(df1) <- c("xdata", "ydata", "group")
names(df2) <- c("xdata", "ydata", "group")
names(df3) <- c("xdata", "ydata", "group")
names(df4) <- c("xdata", "ydata", "group")
names(df5) <- c("xdata", "ydata", "group")
<- rbind(df1, df2, df3, df4, df5) main_df
Continuous Joint Probability Distribution Functions
We will once again visualize the act of ordering food at In-n-Out.
: number of fries orders : number of beef patties ordered
with joint PDF
- Compute the correlation in the In-n-Out setting
Looking Ahead
due Fri., Mar. 17:
- WHW8
- LHW7
Exam 2 will be on Mon., Apr. 10
no lecture on Mar. 24, Apr. 3