View source: R/confintLR.SLik.R
confint.SLik | R Documentation |
confint
takes an SLik
object (as produced by MSL
) and deduces confidence bounds for each parameter, using a (profile, if relevant) likelihood ratio method, and optionally a bootstrap method.
allCIs
calls confint
for all fitted parameters and re-structure the results.
allCIs(object, level=0.95, verbose=TRUE, ...)
## S3 method for class 'SLik_j'
confint(object, parm, level=0.95, verbose=interactive(), fixed=NULL,
which=c(TRUE,TRUE), nsim=0L, reset=TRUE,
cluster_args=NULL, nb_cores=NULL, type="perc",...)
## S3 method for class 'SLik'
confint(object, parm, level=0.95, verbose=interactive(), fixed=NULL,
which=c(TRUE,TRUE), ...)
object |
an |
parm |
The parameter which confidence bounds are to be computed |
level |
The desired coverage of the interval |
verbose |
Whether to print some information or not |
fixed |
When this is |
which |
A pair of booleans, controlling whether to compute respectively the lower and the upper CI bounds. |
nsim |
Integer: number of bootstrap replicates. If >1, bootstrap interval(s) are computed as further controlled by the |
reset |
Boolean: Whether to use any previously computed distribution (see Details) or not. |
cluster_args , nb_cores |
Passed to parallelization wrappers such as |
type |
Character vector, ignored if |
... |
further arguments passed to or from other methods. |
confint.SLik_j
results are stored in the object
(until the next refine
), including the result of the bootstrap simulations if it was performed. This distribution may then be reused by a next call to confint
for the same parm
if reset=FALSE
. The default is however to recompute the distribution (reset=TRUE
).
Bootstrap CIs computed using boot.ci
are stored as distinct elements of the return list (see Value). However, for the "Bartlett"
type of CI, the interval
element of the return value is modified.
Both functions modify the fit object
as a side effect (see Details).
confint
returns a list with sublists for each parameter, each sublist containing: the bounds of the one-dimensional confidence interval (element interval
, a vector); the parameter point for the lower bound (element lowerpar
, a vector including all parameters fitted in the SLik
object), the full parameter point for the upper bound (element upperpar
, formatted as lowerpar
), and optionally if a bootstrap was run, the return value of a boot::boot.ci
call (element bootCI
) and the simulated distribution of parameter estimates (element booreps
, 1-column matrix).
allCIs
returns invisibly a list with elements including CIs
(itself a list of confint
results), bounds
(a matrix made of bound points for all parameters), and some other elements.
SLRT
if (Infusion.getOption("example_maxtime")>3) {
#### Provide fit for minimal toy example:
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 <- 40L
(Sobs <- myrnorm(mu=4,s2=1,sample.size=ssize) )
## Construct initial reference table:
# Uniform sampling in parameter space:
parsp <- init_reftable(lower=c(mu=2.8, s2=0.4, sample.size=ssize),
upper=c(mu=5.2, s2=2.4, sample.size=ssize))
# Build simulation table:
# set.seed(456)
simuls <- add_reftable(Simulate="myrnorm", parsTable=parsp)
# Infer surface:
densv <- infer_SLik_joint(simuls,stat.obs=Sobs)
# Usual workflow using inferred surface:
slik_1 <- MSL(densv) ## find the maximum of the log-likelihood surface
#### Confidence interval calculations:
(ci1 <- confint(slik_1,"mu")) # basic likelihood ratio interval
(ci2 <- confint(slik_1,"mu", nsim=199L)) # Percentile interval added
(ci3 <- confint(slik_1,"mu", nsim=199L, type="Bartlett")) # 'interval' corrected
# Previous bootstrap computations are stored in the fit object,
# and recycled if reset=FALSE *and* nsim > 0:
(ci4 <- confint(slik_1,"mu", nsim=199L, type= "Bartlett", reset=FALSE)) # = ci3
(ci5 <- confint(slik_1,"mu", nsim=199L, type= "perc", reset=FALSE)) # = ci2
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.