if (Infusion.getOption("example_maxtime")>50) {
myrnorm <- function(mu,s2,sample.size) {
s <- rnorm(n=sample.size,mean=mu,sd=sqrt(s2))
return(c(mean=mean(s),var=var(s)))
} # simulate means and variances of normal samples of size 'sample.size'
set.seed(123)
# simulated data with stands for the actual data to be analyzed:
ssize <- 40
Sobs <- myrnorm(mu=4,s2=1,sample.size=ssize)
# Uniform sampling in parameter space:
npoints <- 600
parsp <- data.frame(mu=runif(npoints,min=2.8,max=5.2),
s2=runif(npoints,min=0.4,max=2.4),sample.size=ssize)
# Build simulation table:
simuls <- add_reftable(Simulate="myrnorm", parsTable=parsp)
# Infer surface:
densv <- infer_SLik_joint(simuls,stat.obs=Sobs)
# Usual workflow using inferred surface:
slik_j <- MSL(densv) ## find the maximum of the log-likelihood surface
slik_j <- refine(slik_j,maxit=5)
plot(slik_j)
# etc:
profile(slik_j,c(mu=4)) ## profile summary logL for given parameter value
confint(slik_j,"mu") ## compute 1D confidence interval for given parameter
plot1Dprof(slik_j,pars="s2",gridSteps=40) ## 1D profile
# With constraints:
heart <- quote({ x <- 3*(mu-4.25); y <- 3*(s2-0.75); x^2+(y-(x^2)^(1/3))^2-1})
c_densv <- infer_SLik_joint(simuls,stat.obs=Sobs, constr_crits = heart)
c_slik_j <- MSL(c_densv, CIs=FALSE)
refine(c_slik_j, target_LR=10, ntot=3000)
}
Run the code above in your browser using DataLab