simulate {dbd}R Documentation

Simulate data from a db or beta binomial distribution.

Description

Simulate one or more data sets from a db or beta binomial distribution. The parameters of the distribution may be equal to those obtained from fitting the distibution to data, using mleDb() or mleBb(). They may also be specified by the user via the function makeDbdpars() or makeBbdpars().

Usage

   ## S3 method for class 'mleDb'
simulate(object, nsim = 1, seed = NULL, ...,
                             ndata = NULL, drop = TRUE)
   ## S3 method for class 'mleBb'
simulate(object, nsim = 1, seed = NULL, ...,
                             ndata = NULL, drop = TRUE)
   ## S3 method for class 'Dbdpars'
simulate(object, nsim = 1, seed = NULL, ...,
                             ndata = NULL, drop = TRUE)
   ## S3 method for class 'Dbdpars'
simulate(object, nsim = 1, seed = NULL, ...,
                             ndata = NULL, drop = TRUE)

Arguments

object

An object of class "mleDb" as returned by mleDb(), or of class "mleBb" as returned by mleBb(), or of class "Dbdpars" as returned by makeDbdpars() or of class "Bbdpars" as returned by makeBbdpars().

nsim

The number of data sets to simulate.

seed

Integer vector of seeds for random number generation. It should be of length either 1 or nsim. If it is of length less than nsim then set.seed(seed[1]) is called and seed is replaced by a vector of seeds of length nsim which is created by sampling from 1:1e5. Note that in this case all entries but the first of seed are ignored. If it is longer than nsim, then only the first nsim entries are used and the others are ignored. If seed it is not supplied it is created by sampling nsim values from 1:1e5.

...

Not used.

ndata

Integer vector specifying the lengths of the data sets to be simulated. If it is of length less than nsim it is “recycled” to provide a vector of length nsim. If is longer than nsim, then only the first nsim entries are used and the others are ignored. If ndata is not supplied it is taken to be equal to the "ndata" attribute of object (i.e. the length of the data set from which the parameters in object were estimated.

drop

Logical scalar; if TRUE and if nsim==1 then this function simply returns the simulated data set (an integer vector) rather than a list of length 1 whose sole entry is that data set. If nsim>1 then drop is ignored.

Details

The actual simulation is done by rdb() or by the rbetabinom() function from the rmutil package.

Value

A list, of length nsim, whose entries are integer vectors, the length of of the ith entry being equal to ndata[i]. Each entry has an attribute "seed" which is the random number generation seed that was used in the generation of the data in that entry. If nsim==1 and if drop is TRUE, then the value is simply an integer vector (of length ndata[1]).

See Also

simulate() rdb()

Examples

   X   <- hmm.discnp::Downloads
   fit <- mleDb(X,ntop=15,zeta=TRUE)
   s1  <- simulate(fit)
   s2  <- simulate(fit,nsim=5) # All data sets of length 267.
   s3  <- simulate(fit,nsim=5,ndata=100*(2:6))
   obj <- makeDbdpars(alpha=2,beta=3,ntop=20,zeta=TRUE,ndata=500)
   s4  <- simulate(obj,nsim=5,seed=1:5)

[Package dbd version 0.0-22 Index]