## Define a function to plot for Cauchy distribution
PlotCauchy <- function(n = 100, ...) {
## Create n random variables from Cauchy distribution
vecRCauchy <- rcauchy(n = n)
## Cumulative sum
vecRCauchyCumSum <- cumsum(vecRCauchy)
## Cumulative mean
vecRCauchyCumMean <- vecRCauchyCumSum/seq_along(vecRCauchyCumSum)
## Plot
plot(vecRCauchyCumMean, ylab = "", ...)
}
## Define a function to plot for Cauchy distribution
PlotNormal <- function(n = 100, ...) {
## Create n random variables from Normal distribution
vecRNormal <- rnorm(n = n)
## Cumulative sum
vecRNormalCumSum <- cumsum(vecRNormal)
## Cumulative mean
vecRNormalCumMean <- vecRNormalCumSum/seq_along(vecRNormalCumSum)
## Plot
plot(vecRNormalCumMean, ylab = "", ...)
}
## Layout of plots
layout(matrix(1:2, ncol = 2))
## Number of random variables
n <- 10^6
## Plot for normal distribution (mean = 0)
PlotNormal(n = n, ylim = c(-20,20))
## Plot for Cauchy distribution (mean undefined)
PlotCauchy(n = n, ylim = c(-20,20))