Skip to content

Instantly share code, notes, and snippets.

@allatambov
Last active May 27, 2020 20:49
Show Gist options
  • Save allatambov/850bf2f0fbbcb7c2df50e5dc293bd4bc to your computer and use it in GitHub Desktop.
Save allatambov/850bf2f0fbbcb7c2df50e5dc293bd4bc to your computer and use it in GitHub Desktop.
# загружаем данные
dat <- read.csv("https://allatambov.github.io/psms/chip_n_dale_new.csv")
# строим диаграмму рассеяния
plot(dat$tech, dat$reaction, pch=16)
abline(reg = lm(dat$reaction ~ dat$tech), col = "red")
# считаем коэффициент корреляции Пирсона
cor(dat$tech, dat$reaction)
# еще одна диаграмма рассеяния
plot(dat$cheer, dat$grump, pch=16)
plot(dat$cheer, dat$grump, pch=16, ylim=c(0, 105))
abline(reg = lm(dat$grump ~ dat$cheer), col = "red")
# устойчивость корреляции
cor(dat$cheer, dat$grump)
dat2 <- subset(dat, dat$grump < 105)
cor(dat2$cheer, dat2$grump)
# посчитаем по определению
sx <- sd(dat2$cheeze)
sy <- sd(dat2$cheer)
cov(dat2$cheeze, dat2$cheer) / (sx * sy)
# проверка гипотезы о корреляции
cor.test(dat2$cheeze, dat2$cheer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment