Learn R Programming

spaMM (version 3.5.0)

confint.HLfit: Confidence intervals

Description

This computes confidence intervals for a given parameter, based either on parametric bootstrap or, for fixed-effect parameters, on the p_v-based approximation of the profile likelihood ratio for this parameter. The profiling is over all other fitted parameters, including fixed effects, as well as variances of random effects and spatial correlations if these were fitted. The bootstrap is performed if the parm argument is a function or a quoted expression or if the boot_args argument is a list. The profile confidence interval is computed if neither of these conditions is true; in that case parm must be the name of a fixed-effect coefficient.

Usage

# S3 method for HLfit
confint(object, parm, level=0.95, verbose=TRUE, 
                          boot_args=NULL, ...)

Arguments

object

An object of class HLfit, as returned by the fitting functions in spaMM.

parm

character vector, integer vector, or function, or a quoted expression. If character, the name(s) of parameter(s) to be fitted; if integer, their position in the fixef(object) vector. Valid names are those of this vector. If a function, it must return a (vector of) parameter estimate(s) from a fit object. If a quoted expression, it must likewise extract parameter estimate(s) from a fit object; this expression must refer to the fitted object as ‘hlfit’ (see Examples).

level

The coverage of the interval.

verbose

whether to print the interval or not. As the function returns its more extensive results invisibly, this printing is the only visible output.

boot_args

NULL or a list of arguments passed to functions spaMM_boot and boot.ci. It must contain element nsim (for spaMM_boot). The type argument of boot.ci can only be given as element ci_type, to avoid conflict with the type argument of spaMM_boot.

Additional arguments (maybe not used, but conforming to the generic definition of confint).

Value

For each parameter, if a bootstrap was performed, the result of the boot.ci call is returned. Otherwise, a list is returned including the confidence interval for the target parameter, and the fits lowerfit and upperfit giving the profile fits at the confidence bounds.

If intervals are returned for several parameters, a list of such structures is returned.

These results are returned invisibly.

The boot.ci return value includes the call to boot.ci. This call includes the t vector that makes a bulky display. Some versions of spaMM hacked the object to hide this, but spaMM now only hacks the printing, not the object.

Examples

Run this code
# NOT RUN {
<!-- % checked in test-confint.R -->
# }
# NOT RUN {
data("wafers")
wfit <- HLfit(y ~X1+(1|batch),family=Gamma(log),data=wafers,method="ML")
confint(wfit,"X1")  # profile CI
if (spaMM.getOption("example_maxtime")>30) {
   # bootstrap CI induced by 'boot_args':
   confint(wfit,names(fixef(wfit)), boot_args=list(nsim=99, seed=123)) 
   # bootstrap CI induced by 'parm' being a function:
   confint(wfit,parm=function(v) fixef(v), 
           boot_args=list(nb_cores=10, nsim=199, seed=123))
   # Same effect if 'parm' is a quoted expression in terms of 'hlfit':
   confint(wfit,parm=quote(fixef(hlfit)), 
           boot_args=list(nb_cores=10, nsim=199, seed=123))
           
   # CI for the variance of the random effect:          
   ( ci <- confint(wfit,parm=function(fit){VarCorr(fit)[1,"Variance"]}, 
        boot_args=list(nb_cores=10, nsim=199, seed=123)) )
   # The distribution of bootstrap replicates:
   plot(ecdf(ci$call$t))
   # We may be far from ideal condition for accuracy of bootstrap intervals;
   # for variances, a log transformation may sometimes help, but not here.
}
# }

Run the code above in your browser using DataLab