R - 통계

교차표 만들기

setwd(r"(C:\Users\BMChun\Desktop\2020b\기초프로그래밍\수업자료)")
usedcars = read.csv("usedcars.csv")
usedcars <- usedcars %>% mutate(group = ifelse(usedcars$cc>1900,"H","L"))
t <- table(usedcars$automatic,usedcars$group)
margin.table(t,margin=2)
prop.table(t,margin=2)

변수 간 독립성 확인

prop.table(margin.table(t,margin=1))
tt = xtabs(~ group + automatic, data =usedcars)
rp = rowSums(tt)/sum(tt)
cp = prop.table(margin.table(tt,margin = 2))
expected = sum(tt)*outer(rp,cp)
tt-expected

ggplot2

require(ggplot2)
boxplot(Sepal.Width~ Species, iris)
hist(iris$Sepal.Length)
plot(iris$Sepal.Width, iris$Sepal.Length)