if (Infusion.getOption("example_maxtime")>20) { # 2D plots relatively slow
#### Toy bivariate gaussian model, three parameters, no projections
#
myrnorm2 <- function(mu1,mu2,s2,sample.size) {
sam1 <- rnorm(n=sample.size,mean=mu1,sd=sqrt(s2))
sam2 <- rnorm(n=sample.size,mean=mu2,sd=sqrt(s2))
s <- c(sam1,sam2)
e_mu <- mean(s)
e_s2 <- var(s)
c(mean=e_mu,var=e_s2,kurt=sum((s-e_mu)^4)/e_s2^2)
}
#
## simulated data, standing for the actual data to be analyzed:
set.seed(123)
Sobs <- myrnorm2(mu1=4,mu2=2,s2=1,sample.size=40) ##
#
## build reference table
parsp <- init_reftable(lower=c(mu1=2.8,mu2=1,s2=0.2),
upper=c(mu1=5.2,mu2=3,s2=3))
parsp <- cbind(parsp,sample.size=40)
simuls <- add_reftable(Simulate="myrnorm2", parsTable=parsp)
## Inferring the summary-likelihood surface...
densvj <- infer_SLik_joint(simuls,stat.obs=Sobs)
slik_j <- MSL(densvj) ## find the maximum of the log-likelihood surface
### plots
# Plot 1: a 1D profile:
prof1 <- plot1Dprof(slik_j,pars="s2",gridSteps=40,xlabs=list(s2=expression(paste(sigma^2))))
# Using 'add' for comparison of successive profiles:
slik_2 <- refine(slik_j, n=600)
# Plot 2: comparing 1D profiles of different iterations:
prof2 <- plot1Dprof(slik_2,"s2", gridSteps=40,xlabs=list(s2=expression(paste(sigma^2))),
add=prof1$profiles, col="grey30")
# Plot 3: using 'decorations' and 'profiles' for recycling previous computation for s2:
DGpars <- c(mu1=4,mu2=2,s2=1,sample.size=40) # data-generating parameters
plot1Dprof(slik_2, gridSteps=40,xlabs=list(s2=expression(paste(sigma^2))),
profiles=prof2$profiles,
decorations=function(par) {
points(y=-7,x=DGpars[par],pch=20,cex=2,col="red");
points(y=-0.5,x=slik_2$MSL$MSLE[par],pch=20,cex=2,col="blue")
}
)
plot2Dprof(slik_j,gridSteps=21,
## alternative syntaxes for non-default 'pars':
# pars = c("mu1","mu2"), # => all combinations of given elements
# pars = list("s2",c("mu1","mu2")), # => combinations via expand.grid()
# pars = matrix(c("mu1","mu2","s2","mu1"), ncol=2), # => each row of matrix
xylabs=list(
mu1=expression(paste(mu[1])),
mu2=expression(paste(mu[2])),
s2=expression(paste(sigma^2))
))
# One could also add (e.g.)
# cluster_args=list(spec=4, type="FORK"),
# when longer computations are requested.
}
if (Infusion.getOption("example_maxtime")>5) {
#### Older example with primitive workflow
data(densv)
slik <- infer_surface(densv) ## infer a log-likelihood surface
slik <- MSL(slik) ## find the maximum of the log-likelihood surface
prof1 <- plot1Dprof(slik,pars="s2",gridSteps=40,xlabs=list(s2=expression(paste(sigma^2))))
}
Run the code above in your browser using DataLab