if (FALSE) {
## Estimation of mean matrix from simulated data
# Variables and parameters
d <- 3
n <- 30
N <- c(10,10,10)
LeslieMatrix <- matrix( c(0.08, 1.06, 0.07,
0.99, 0, 0,
0, 0.98, 0), 3, 3 )
# offspring distributions from the Leslie matrix
# (with independent distributions)
Dists.pois <- data.frame( name=rep( "pois", d ),
param1=LeslieMatrix[,1],
param2=NA,
stringsAsFactors=FALSE )
Dists.binom <- data.frame( name=rep( "binom", 2*d ),
param1=rep( 1, 2*d ),
param2=c(t(LeslieMatrix[,-1])),
stringsAsFactors=FALSE )
Dists.i <- rbind(Dists.pois,Dists.binom)
Dists.i <- Dists.i[c(1,4,5,2,6,7,3,8,9),]
Dists.i
# mean matrix of the process from its offspring distributions
m <- BGWM.mean(Dists.i,"independents",d)
# generated trajectories of the process from its offspring distributions
simulated.data <- rBGWM(Dists.i, "independents", d, n, N,
TRUE, FALSE, FALSE)$o.c.s
# mean matrix empiric estimate from generated trajectories of the process
m.EE <- BGWM.mean.estim( simulated.data, "EE", d, n, N )$m
# mean matrix maximum likelihood estimate from generated trajectories
# of the process
m.MLE <- BGWM.mean.estim( simulated.data, "MLE", d, n, N )$m
# Comparison of exact and estimated mean matrices
m
m - m.EE
m - m.MLE
}
Run the code above in your browser using DataLab