Title: | Seeing Convergence Concepts in Action |
---|---|
Description: | This is a pedagogical package, designed to help students understanding convergence of random variables. It provides a way to investigate interactively various modes of convergence (in probability, almost surely, in law and in mean) of a sequence of i.i.d. random variables. Visualisation of simulated sample paths is possible through interactive plots. The approach is illustrated by examples and exercises through the function 'investigate', as described in Lafaye de Micheaux and Liquet (2009) <doi:10.1198/tas.2009.0032>. The user can study his/her own sequences of random variables. |
Authors: | Pierre Lafaye De Micheaux [aut, cre], Benoit Liquet [aut] |
Maintainer: | Pierre Lafaye De Micheaux <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.2.3 |
Built: | 2024-12-03 06:32:43 UTC |
Source: | CRAN |
This function enables one to investigate the four classical modes of convergence on simulated data: in probability, almost surely, in r-th mean and in law.
check.convergence(nmax,M,genXn,argsXn=NULL,mode="p",epsilon=0.05,r=2,nb.sp=10, density=FALSE,densfunc=dnorm,probfunc=pnorm,tinf=-3,tsup=3,plotfunc=plot,...)
check.convergence(nmax,M,genXn,argsXn=NULL,mode="p",epsilon=0.05,r=2,nb.sp=10, density=FALSE,densfunc=dnorm,probfunc=pnorm,tinf=-3,tsup=3,plotfunc=plot,...)
nmax |
number of points in each sample path. |
M |
number of sample paths to be generated. |
genXn |
a function that generates the Xn-X values, or only the Xn values in the law case. |
argsXn |
a list of arguments to |
mode |
a character string specifying the mode of convergence to be investigated, must be one of "p" (default), "as", "r" or "L". |
epsilon |
a numeric value giving the interval endpoint. |
r |
a numeric value (r>0) if convergence in r-th mean is to be studied. |
nb.sp |
number of sample paths to be drawn on the left plot. |
density |
if density=TRUE, then the plot of the density of X and the histogram of Xn is returned. If density=FALSE, then the plot of the distribution function F(t) of X and the empirical distribution Fn(t) of Xn is returned. |
densfunc |
function to compute the density of X. |
probfunc |
function to compute the distribution function of X. |
tinf |
lower limit for investigating convergence in law. |
tsup |
upper limit for investigating convergence in law. |
plotfunc |
R function used to draw the plot: for example |
... |
optional arguments to |
The objective of this function is to investigate graphically the convergence of some
random variable Xn to some random variable X. In order to use it, you
should be able to provide generators of Xn and X (or of Xn-X). The four modes of
convergence that you can try are: in probability, almost surely, in r-th
mean and in law. For the convergence in law, we compute
for ten values equally distributed between
tinf
and tsup
.
P. Lafaye de Micheaux and B. Liquet
Lafaye de Micheaux, P. ([email protected]), Liquet, B. "Understanding Convergence Concepts: a Visual-Minded and Graphical Simulation-Based Approach", The American Statistician, 63:2, 173–178, (2009).
criterion
, generate
, investigate
,
law.plot2d
, law.plot3d
, p.as.plot
,
visualize.crit
, visualize.sp
## Not run: ####################### Exercise 3 ############################## # Let X1, X2, ..., Xn be independent random variables such that # # P[Xn=sqrt(n)]=1/n and P[Xn=0]=1-1/n # # Does Xn converges to 0 in 2-th mean? in probability? # ################################################################# options(example.ask=FALSE) pnotrgen<-function(n){rbinom(n,1,1/(1:n))*sqrt(1:n)} check.convergence(nmax=1000,M=500,genXn=pnotrgen,mode="r",r=2) legend(100,6,legend=expression(hat(e)["n,2"]),lty=1) tt3.1 <<- check.convergence(nmax=1000,M=500,genXn=pnotrgen,mode="p") ## End(Not run)
## Not run: ####################### Exercise 3 ############################## # Let X1, X2, ..., Xn be independent random variables such that # # P[Xn=sqrt(n)]=1/n and P[Xn=0]=1-1/n # # Does Xn converges to 0 in 2-th mean? in probability? # ################################################################# options(example.ask=FALSE) pnotrgen<-function(n){rbinom(n,1,1/(1:n))*sqrt(1:n)} check.convergence(nmax=1000,M=500,genXn=pnotrgen,mode="r",r=2) legend(100,6,legend=expression(hat(e)["n,2"]),lty=1) tt3.1 <<- check.convergence(nmax=1000,M=500,genXn=pnotrgen,mode="p") ## End(Not run)
This function computes the values of the criterion convergence function for convergence in probability, almost surely or in r-th mean, given the sample paths.
criterion(data,epsilon=0.05,mode="p",r=2)
criterion(data,epsilon=0.05,mode="p",r=2)
data |
matrix containing the sample paths of Xn-X values. |
epsilon |
a numeric value giving the interval endpoint. |
mode |
a character string specifying the mode of convergence to be investigated, must be one of "p" (default), "as" or "r". |
r |
a numeric value (r>0) if convergence in r-th mean is to be studied. |
The data
matrix contains the values. If mode="p",
criterion
approximates . If mode="as",
criterion
approximates . If mode="r",
criterion
approximates
. The approximations are
based on the frequentist approach.
crit |
the vector of criterion values. |
P. Lafaye de Micheaux and B. Liquet
Lafaye de Micheaux, P. ([email protected]), Liquet, B. "Understanding Convergence Concepts: a Visual-Minded and Graphical Simulation Based Approach", The American Statistician, 63:2, 173–178, (2009).
check.convergence
, generate
, investigate
,
law.plot2d
, law.plot3d
,
p.as.plot
, visualize.crit
, visualize.sp
myrbinom <- function(n,alpha){rbinom(n,1,1/(1:n))*((1:n)**alpha)} data <- generate(nmax=1000,M=500,myrbinom,args=list(alpha=0.5))$data critr1 <- criterion(data,mode="r",r=1)$crit
myrbinom <- function(n,alpha){rbinom(n,1,1/(1:n))*((1:n)**alpha)} data <- generate(nmax=1000,M=500,myrbinom,args=list(alpha=0.5))$data critr1 <- criterion(data,mode="r",r=1)$crit
This function generates the sample paths of a sequence of random variables.
generate(randomgen,nmax=1000,M=500,argsgen=NULL)
generate(randomgen,nmax=1000,M=500,argsgen=NULL)
nmax |
number of points in each sample path. |
M |
number of sample paths to be generated. |
randomgen |
a function that generates the Xn-X values. |
argsgen |
a list of arguments to |
data |
matrix containing in each row a sample path of Xn-X values. |
P. Lafaye de Micheaux and B. Liquet
Lafaye de Micheaux, P. ([email protected]), Liquet, B. "Understanding Convergence Concepts: a Visual-Minded and Graphical Simulation-Based Approach", The American Statistician, 63:2, 173–178, (2009).
check.convergence
, criterion
, investigate
,
law.plot2d
, law.plot3d
,
p.as.plot
, visualize.crit
, visualize.sp
myrbinom<-function(n,alpha){rbinom(n,1,1/(1:n))*((1:n)**alpha)} data <- generate(randomgen=myrbinom,argsgen=list(alpha=0.5))$data
myrbinom<-function(n,alpha){rbinom(n,1,1/(1:n))*((1:n)**alpha)} data <- generate(randomgen=myrbinom,argsgen=list(alpha=0.5))$data
This function investigates the convergence for all the examples and exercises from the article cited in references.
investigate()
investigate()
P. Lafaye de Micheaux and B. Liquet
Lafaye de Micheaux, P. ([email protected]), Liquet, B. "Understanding Convergence Concepts: a Visual-Minded and Graphical Simulation-Based Approach", The American Statistician, 63:2, 173–178, (2009).
check.convergence
, criterion
, generate
,
law.plot2d
, law.plot3d
, p.as.plot
,
visualize.crit
, visualize.sp
investigate()
investigate()
This function enables one to draw the interactive 2D plot to investigate convergence in law.
law.plot2d(data,density=FALSE,densfunc=dnorm,probfunc=pnorm,tinf=-5,tsup=5)
law.plot2d(data,density=FALSE,densfunc=dnorm,probfunc=pnorm,tinf=-5,tsup=5)
data |
matrix containing the sample paths of Xn values. |
density |
if density=TRUE, then the plot of the density of X and the histogram of Xn is returned. If density=FALSE, then the plot of the distribution function F(t) of X and the empirical distribution Fn(t) of Xn is returned. |
densfunc |
function to compute the density of X. |
probfunc |
function to compute the distribution function of X. |
tinf |
lower limit for investigating convergence in law. |
tsup |
upper limit for investigating convergence in law. |
P. Lafaye de Micheaux and B. Liquet
Lafaye de Micheaux, P. ([email protected]), Liquet, B. "Understanding Convergence Concepts: a Visual-Minded and Graphical Simulation-Based Approach", The American Statistician, 63:2, 173–178, (2009).
check.convergence
, criterion
,
generate
, investigate
,
law.plot3d
,
p.as.plot
, visualize.crit
, visualize.sp
rand <- function(n){(cumsum(rchisq(n,df=1))-(1:n))/sqrt(2*(1:n))} data <- generate(randomgen=rand,nmax=1000,M=500)$data law.plot2d(data)
rand <- function(n){(cumsum(rchisq(n,df=1))-(1:n))/sqrt(2*(1:n))} data <- generate(randomgen=rand,nmax=1000,M=500)$data law.plot2d(data)
This function enables one to draw the static 3D plot to investigate convergence in law.
law.plot3d(data,probfunc,tinf=-5,tsup=5)
law.plot3d(data,probfunc,tinf=-5,tsup=5)
data |
matrix containing the sample paths of Xn values. |
probfunc |
function to compute the distribution function of X. |
tinf |
lower limit for investigating convergence in law. |
tsup |
upper limit for investigating convergence in law. |
P. Lafaye de Micheaux and B. Liquet
Lafaye de Micheaux, P. ([email protected]), Liquet, B. "Understanding Convergence Concepts: a Visual-Minded and Graphical Simulation-Based Approach", The American Statistician, 63:2, 173–178, (2009).
check.convergence
, criterion
,
generate
, investigate
,
law.plot2d
,
p.as.plot
, visualize.crit
, visualize.sp
rand <- function(n){(cumsum(rchisq(n,df=1))-(1:n))/sqrt(2*(1:n))} data <- generate(randomgen=rand,nmax=300,M=2000)$data law.plot3d(data,pnorm)
rand <- function(n){(cumsum(rchisq(n,df=1))-(1:n))/sqrt(2*(1:n))} data <- generate(randomgen=rand,nmax=300,M=2000)$data law.plot3d(data,pnorm)
This function enables one to draw the interactive plots used to study convergence in probability and almost surely.
p.as.plot(data,critp,critas,epsilon=0.05,nb.sp=10,mode="p")
p.as.plot(data,critp,critas,epsilon=0.05,nb.sp=10,mode="p")
data |
matrix containing the sample paths of Xn-X values. |
critp |
vector containing the criterion values for convergence in probability. |
critas |
vector containing the criterion values for convergence almost surely. |
epsilon |
a numeric value giving the interval endpoint. |
nb.sp |
number of sample paths to be drawn on the left plot. |
mode |
a character string specifying the mode of convergence to investigate, must be one of "p" (default), "as" or "r". |
P. Lafaye de Micheaux and B. Liquet
Lafaye de Micheaux, P. ([email protected]), Liquet, B. "Understanding Convergence Concepts: a Visual-Minded and Graphical Simulation-Based Approach", The American Statistician, 63:2, 173–178, (2009).
check.convergence
, criterion
, generate
, investigate
,
law.plot2d
, law.plot3d
,
visualize.crit
, visualize.sp
myrbinom <- function(n,alpha){rbinom(n,1,1/(1:n))*((1:n)**alpha)} data <- generate(randomgen=myrbinom,nmax=1000,M=500,argsgen=list(alpha=0.5))$data critp <- criterion(data,epsilon=0.05,"p")$crit critas <- criterion(data,epsilon=0.05,"as")$crit p.as.plot(data,critp,critas,epsilon=0.05,nb.sp=10,mode="p")
myrbinom <- function(n,alpha){rbinom(n,1,1/(1:n))*((1:n)**alpha)} data <- generate(randomgen=myrbinom,nmax=1000,M=500,argsgen=list(alpha=0.5))$data critp <- criterion(data,epsilon=0.05,"p")$crit critas <- criterion(data,epsilon=0.05,"as")$crit p.as.plot(data,critp,critas,epsilon=0.05,nb.sp=10,mode="p")
This function enables one to visualize the convergence criterion curve.
visualize.crit(crit,plotfunc=plot,...)
visualize.crit(crit,plotfunc=plot,...)
crit |
vector containing the criterion values. |
plotfunc |
R function used to draw the plot: for example |
... |
optional arguments to |
P. Lafaye de Micheaux and B. Liquet
Lafaye de Micheaux, P. ([email protected]), Liquet, B. "Understanding Convergence Concepts: a Visual-Minded and Graphical Simulation-Based Approach", The American Statistician, 63:2, 173–178, (2009).
check.convergence
, criterion
, generate
, investigate
,
law.plot2d
, law.plot3d
,
p.as.plot
, visualize.sp
myrbinom <- function(n,alpha){rbinom(n,1,1/(1:n))*((1:n)**alpha)} data <- generate(randomgen=myrbinom,nmax=1000,M=500,argsgen=list(alpha=0.5))$data critr1 <- criterion(data,epsilon=0.05,mode="r",r=2)$crit visualize.crit(critr1,main="Convergence in 2-th mean?",col="red") legend(0,5,legend=expression(hat(e)["n,2"]),lty=1,col="red")
myrbinom <- function(n,alpha){rbinom(n,1,1/(1:n))*((1:n)**alpha)} data <- generate(randomgen=myrbinom,nmax=1000,M=500,argsgen=list(alpha=0.5))$data critr1 <- criterion(data,epsilon=0.05,mode="r",r=2)$crit visualize.crit(critr1,main="Convergence in 2-th mean?",col="red") legend(0,5,legend=expression(hat(e)["n,2"]),lty=1,col="red")
This function enables one to visualize the sample paths.
visualize.sp(data,epsilon=0.05,nb.sp=10,plotfunc=plot,...)
visualize.sp(data,epsilon=0.05,nb.sp=10,plotfunc=plot,...)
data |
matrix containing the sample paths of Xn-X values. |
epsilon |
a numeric value giving the interval endpoint. |
nb.sp |
number of sample paths to draw on the plot. |
plotfunc |
R function used to draw the plot: for example |
... |
optional arguments to |
P. Lafaye de Micheaux and B. Liquet
Lafaye de Micheaux, P. ([email protected]), Liquet, B. "Understanding Convergence Concepts: a Visual-Minded and Graphical Simulation-Based Approach", The American Statistician, 63:2, 173–178, (2009).
check.convergence
, criterion
, generate
, investigate
,
law.plot2d
, law.plot3d
,
p.as.plot
, visualize.crit
myrand <- function(n,...){cumsum(rnorm(n,...))/(1:n)} data <- generate(randomgen=myrand,nmax=1000,M=500)$data visualize.sp(data,main="Ten sample paths",col="grey")
myrand <- function(n,...){cumsum(rnorm(n,...))/(1:n)} data <- generate(randomgen=myrand,nmax=1000,M=500)$data visualize.sp(data,main="Ten sample paths",col="grey")