Skip to content

Instantly share code, notes, and snippets.

@ascv
Last active August 29, 2015 14:28
Show Gist options
  • Save ascv/a040b682a13b502dbf0f to your computer and use it in GitHub Desktop.
Save ascv/a040b682a13b502dbf0f to your computer and use it in GitHub Desktop.
Example
n <- 500
a <- rnorm(n, 0, 3)
b <- rnorm(n, 1, 4)
Z <- rep(0, n)
V <- rep(0, n)
P <- rep(0, n)
for (i in seq(5, n)) {
df <- i %% 24
A <- a[1:i]
B <- b[1:i]
x1 = mean(A)
x2 = mean(B)
Z[i] <- (x1 - x2)/sqrt(var(A)^2/i + var(B)^2/i)
V[i] <- (var(A)^2/i + var(B)^2/i)^2 / ((var(A)^4/(i^2*df)) + (var(B)^4/(i^2*df)))
result <- t.test(A,B)
P[i] <- result$p.value
}
plot(P, main='T-test N(0, 3) and N(1, 4)', xlab='clicks', ylab='P-value')
lines(P, col='blue')
abline(h=.05,col='red')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment