Created
February 15, 2014 23:38
-
-
Save gjkerns/9026878 to your computer and use it in GitHub Desktop.
Strong Law of Large Numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SLLN <- function( iter = 10, | |
p = 0.5){ | |
require(TeachingDemos) | |
x <- rbinom( iter, size=1, prob = p) | |
plot( cumsum(x)/1:length(x), | |
type="l", | |
#lwd = 2, | |
ylab = "Relative Frequency", | |
xlab = "Cumulative Trials", | |
ylim = c(0,1)) | |
abline( h = p, lty = 3) | |
plot.refresh <- function(...){ | |
iter <- slider(no = 1) | |
p <- slider(no = 2) | |
xr <- c(1,iter) | |
x <- rbinom( iter, size=1, prob = p) | |
plot( cumsum(x)/1:length(x), | |
type="l", | |
lwd = -.002*iter+3, | |
ylab = "Relative Frequency", | |
xlab = "Cumulative Trials", | |
main = "Strong Law of Large Numbers", | |
ylim = c(0,1)) | |
abline( h = p, lty = 3, lwd = -.002*iter+3) | |
} | |
slider( plot.refresh, | |
c("Sample size n", "Probability of event"), | |
c(10, 0), | |
c(1000000, 1), | |
c(1, 0.01), | |
c(10, 0.5), | |
title = "Strong LLN Demo") | |
} | |
cummax <- function(x){ | |
z = rep(0,length(x)) | |
for(i in 1:length(x)){ | |
z[i] = max(x[1:i]) | |
} | |
return(z) | |
} | |
rmin <- function(x){ | |
z = rep(0,length(x)) | |
for(i in 1:length(x)){ | |
z[i] = max(x[1:i]) | |
} | |
return(z) | |
} | |
limsup(rw) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment