Generating t- distribution from the standard normal
x <- seq(-3, 3, 0.01)
sampSize <- 6
tval <- rep(0, 2000)
for (i in 1:2000) {
samp <- sample(rnorm(1000), sampSize, replace = T)
mean1 <- round(mean(samp), 3)
sd <- round(sd(samp), 3)
tval[i] <- mean1/(sd/sqrt(sampSize))
}
plot(density(tval), lwd = 1, main = "Comparing t-dist with the normal dist")
lines(x, dt(x, sampSize - 1), col = "red", lwd = 2)
lines(x, dnorm(x), col = "green", lwd = 2)
text(2,0.3,"BLACK-sampling, RED-t-dist, GREEN-Normal",adj = c(0,0),cex = 0.8)
