x <- c(3, 5, 8, 10, 2, 3, 7, 5, 3, 10)
y <- c(12, 32, 12, 76, 12, 34, 76, 15, 18, 10)
plot(x, y)

cor(x, y)
## [1] 0.3973532
cor(x, y, method="spearman")
## [1] 0.09717916
cor.test(x, y)
## 
##  Pearson's product-moment correlation
## 
## data:  x and y
## t = 1.2247, df = 8, p-value = 0.2555
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.3097735  0.8214627
## sample estimates:
##       cor 
## 0.3973532
x <- rnorm(50)
y <- rnorm(50)
hist(x)

plot(x, y)

cor(x, y)
## [1] 0.01249428
cor.test(x, y)
## 
##  Pearson's product-moment correlation
## 
## data:  x and y
## t = 0.08657, df = 48, p-value = 0.9314
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.2667812  0.2898340
## sample estimates:
##        cor 
## 0.01249428
x <- rnorm(50)
y <- -x + 2.0 * rnorm(50)
# this produces positively correlated x and y
# 1. change this to get negatively correlated x and y
# 2. x and y with small positive correlation
plot(x, y)

cor(x, y)
## [1] -0.4020637
dat <- read.csv("http://bit.ly/3cB6DDn")
# what can you say about correlation
# between n_words and n_unique?
# plot scatter plot, 
# find correlation coefficient
# check for significance
plot(dat$n_words, dat$n_unique)

cor(dat$n_words, dat$n_unique, method = 'spearman')
## [1] 0.8984314
cor.test(dat$n_words, dat$n_unique, method='spearman')
## Warning in cor.test.default(dat$n_words, dat$n_unique, method =
## "spearman"): Cannot compute exact p-value with ties
## 
##  Spearman's rank correlation rho
## 
## data:  dat$n_words and dat$n_unique
## S = 456.55, p-value = 1.621e-11
## alternative hypothesis: true rho is not equal to 0
## sample estimates:
##       rho 
## 0.8984314
dat <- read.csv("http://bit.ly/2TtNkoa")
install.packages("ggplot2")
## 
## The downloaded binary packages are in
##  /var/folders/79/1y_t9vcx3ws9shyf4nd1vblc0000gn/T//RtmpkQpzGP/downloaded_packages
library(ggplot2)
ggplot(dat) + geom_point(aes(x=math, y=write))

ggplot(dat) + geom_point(aes(x=math, y=write, color=schtyp, shape=ses)) + facet_grid(race ~ gender)

install.packages("GGally")
## 
## The downloaded binary packages are in
##  /var/folders/79/1y_t9vcx3ws9shyf4nd1vblc0000gn/T//RtmpkQpzGP/downloaded_packages
library(GGally)
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
ggpairs(dat, columns=c('read', 'schtyp', 'prog'))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.