mixture.sim: Simulation Of A Mixture Of Two Normal Or Gamma Distributions

Description Usage Arguments Details Value Examples

View source: R/mixture.sim.R

Description

Simulation of M random variables from a mixture of two Gaussian or Gamma distributions

Usage

1
mixture.sim(M, density.phi, param)

Arguments

M

number of simulated variables

density.phi

name of the chosen density 'mixture.normal' or 'mixture.gamma'

param

vector of parameters with the proportion of mixture of the two distributions and means and standard-deviations of the two normal or shapes and scales of the two Gamma distribution

Details

If 'mixture.normal', the distribution is p N(μ1,σ1^2) + (1-p)N(μ2, σ2^2)

and param=c(p, μ1, σ1, μ2, σ2)

If 'mixture.gamma', the distribution is p Gamma(shape1,scale1) + (1-p)Gamma(shape2,scale2)

and param=c(p, shape1, scale1, shape2, scale2)

Value

Y

vector of simulated variables

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
density.phi <- 'mixture.gamma'
param <- c(0.2,1.8,0.5,5.05,1); M <- 200
gridf <- seq(0, 8, length = 200)  
f <- param[1] * 1/gamma(param[2]) * (gridf)^(param[2]-1) * 
           exp(-(gridf) / param[3]) / param[3]^param[2] + 
           (1-param[1]) * 1/gamma(param[4]) * (gridf)^(param[4]-1) * 
           exp(-(gridf) / param[5]) / param[5]^param[4]
Y <- mixture.sim(M, density.phi, param)
hist(Y)
lines(gridf, f)

Example output

Loading required package: sde
Loading required package: MASS
Loading required package: stats4
Loading required package: fda
Loading required package: splines
Loading required package: Matrix

Attaching package: 'fda'

The following object is masked from 'package:graphics':

    matplot

Loading required package: zoo

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

sde 2.0.15
Companion package to the book
'Simulation and Inference for Stochastic Differential Equations With R Examples'
Iacus, Springer NY, (2008)
To check the errata corrige of the book, type vignette("sde.errata")
Loading required package: moments

mixedsde documentation built on May 1, 2019, 7:33 p.m.