Section One: Finding the correlation by hand
gorilla.x=c(1,3,4,4,4,5)
gorilla.y=c(4, 21, 33, 41, 43, 46)
plot(gorilla.x,gorilla.y)
cor(gorilla.x,gorilla.y)
# What is correlation? Look on page 105 for formula we are going to recreate
g.x.mean = mean(gorilla.x)
g.y.mean = mean(gorilla.y)
g.x.sd = sd(gorilla.x)
g.y.sd = sd(gorilla.y)
z.g.x = (gorilla.x-g.x.mean)/g.x.sd
z.g.y = (gorilla.y-g.y.mean)/g.y.sd
total.z = z.g.x*z.g.y
1/(length(gorilla.x)-1)*sum(total.z)
Section 2: Finding the correlation by being awesome:
cor(gorilla.x, gorilla.y)
Section 3: Finding the line of best fit:
gorilla.line=lm(gorilla.y~gorilla.x) # Y VALUE GOES FIRST, Y'ALL.
gorilla.line
Step 4: The Wonder That is Statistics: