Overview:

This program can be used for simulation and associated explanatory text the properties of the Exponential and Poison distribution of the mean. We made:

  1. Show the sample mean and compare it to the theoretical mean of the distribution.
  2. Show how variable the sample is (via variance) and compare it to the theoretical variance of the distribution.

Get started

For initialize simulation we seted :

lambda<-0.2
n<-1000
len<-10

You can choose lambda with using Shyny component Input Slider in interval from 0.1 to 5 with step 0.1

You can set number of experiment n with using Shyny component Numeric input.

You can set length of set len with using Shyny component Numeric input.

You have to choose type of distribution (Exponential or Poison) with using Shyny component Select Input.

This program make simulation and calculate means depends on type of distribution. For example, if you choose Poison distribution.

For initialize simulation we seted :

experiment<-function(lambda,n,len,distr) {
  
  if (distr=="Exponential") {
  matrixExp<-matrix(rexp(n*len,lambda),n,len)
  means<-apply(matrixExp,1,mean)
  
  }
  else{ 
    matrixExp<-matrix(rpois(n*len,lambda),n,len)
    means<-apply(matrixExp,1,mean)
    
  }
  means
}

m<-experiment(lambda,n,len,"Poison")
head(m)
## [1] 0.2 0.2 0.0 0.2 0.0 0.1

After that program calculate theoretical mean, sample mean, theoretical variance, sample variance and print the results.

In the end program plot the distribution of means and aproximate it.

Example:

 hist(m,col="gray",labels=TRUE,probability=T, main="Distribution plot",freq=F)
      lines(density(m))

Total

You can use this program for exploring Exponential an Poison distribution.