[R 통계분석] 상관과 회귀
Section 01. 상관계수 > # 서로 다른 상관계수와 그에 따른 산점도의 변화 > > set.seed(9) > rvnorm > r1 plot(r1, main="r=0.8") > abline(lm(r1[,2] ~ r1[,1]), col="red") > > r2 plot(r2, main="r=0") > abline(h=0, col="red") > > r3 plot(r3, main="r=-0.8") > abline(lm(r3[,2] ~ r3[,1]), col="red") > > ## 01) 아버지와 아들 키의 공분산과 상관계수 > > hf https://www.randomservices.org/random/data/Galton.txt", header=T, stringsAsFactors = FALSE, s..
2022. 8. 27.
[R 통계분석] 범주형 자료분석
Section 01. 적합도 검정 > # 자유도가 3인 χ2-분포에서 기각역(α=0.05) > > x dc > alpha tol > par(mar=c(0,1,1,1)) > plot(x, dc, type="l", axes=F, ylim=c(-0.03, 0.25), xlab="", ylab="", col = "blue") > abline(h=0) > abline(h=0, col = "blue") > tol.g polygon(c(tol.g, x[x>tol.g], 15), c(0, dc[x>tol.g], 0), col="red") > text(0, -0.03, "0", cex=0.8) > text(tol, -0.03, expression(chi[0.05]^{2}==2.14), cex=0.8) > > # 적합도 ..
2022. 8. 19.
[R 통계분석] 가설검정
Section 01. 가설검정 > # 자유도가 14인 t-분포에서 유의수준 α = 0.05일 때의 기각역 > > par(mar=c(0.5,1,1,1)) > x y plot(x, y, type="l", axes=F, ylim=c(-0.02, 0.38), main="", xlab="t", ylab="", col = "blue") > abline(h=0, col = "blue") > alpha ul ll polygon(c(-3, x[xul], 3), c(0, y[x>ul], 0), col=2) > text(-2.2, 0.1, expression(plain(P)(T text(2.2, 0.1, expression(plain(P)(T>t) == 0.025), cex=0.7) > text(ll, -0.02, expr..
2022. 8. 12.
[R 통계분석] 추정
Section 01. 점추정 > ## 01) 유효성 > > # 두 추정량의 분산 비교 > # Y1 = (X1 + X2 + X3) / 3 > # Y2 = (X1 + 2X2 + 3X3) / 6 > > x y # Y1 : N(1, sqrt(1/3)) > y.1 # Y2 : N(1, sqrt(7/18)) > y.2 > # P(-0.1 pnorm(0.1, sd = sqrt(7/18)) - pnorm(-0.1, sd = sqrt(7/18)) [1] 0.1273999 > # Y1의 분포의 확률값이 더 높아 모평균 주변으로 더 많이 모여 있다고 할 수 있다. > > # 분포 확인 > plot(x, y, type = "l", ylim = c(0, 0.8), axes = F, ylab = "", lwd = 3, col =..
2022. 8. 11.
[R 통계분석] 표본분포
Section 01. 표본분포 > ## 01) 표본평균 x의 분포 > > m10 m40 set.seed(9) > for (i in 1:1000) { + m10[i] options(digits = 4) > c(mean(m10), sd(m10)) [1] -0.01214 0.30311 > c(mean(m40), sd(m40)) [1] 0.004212 0.160942 > # 표본 크기를 4배 늘려서 표준편차는 대략 1/2 수준으로 줄었다. > > hist(m10, xlim = c(-1.5, 1.5), main = "", xlab = "x", ylab = "", + col = "cyan", border = "blue") > hist(m40, xlim = c(-1.5, 1.5), main = "", xlab = "..
2022. 8. 10.