Learn R Programming

mixreg (version 2.0-10)

cband: Calculate confidence and prediction bands for mixtures of one-variable regressions.

Description

Produces confidence and prediction bands, two-sided or upper or lower, for the lines fitted in a model consisting of a mixture of one-variable regressions.

Usage

cband(object, alpha=0.05, MC=FALSE, xlen=100, plot=FALSE,...)

Arguments

object

Object describing the fitted mixture of regressions, as returned by mixreg().

alpha

One minus the confidence level for the confidence and prediction bands; e.g. alpha = 0.05 for 95% confidence.

MC

Logical scalar; should the covariance matrix of the parameter estimates be calculated by a Monte Carlo procedure? If the covariance matrix is extracted from object, the "MC" attribute of this matrix is checked. If argument MC disagrees with this attribute then the covariance matrix is re-calculated using the appropriate procedure.

xlen

The number of points to be plotted in the band envelopes. The \(x\)-values of the points will be equispaced from the minimum to the maximum of the predictor variable.

plot

Logical scalar; should a plot of the fitted model and confidence and prediction bands be produced immediately?

...

Extra arguments to be passed to covMixMC() if the covariance matrix needs to be (re-) calculated and MC is TRUE.

Value

An object of class "cband", consisting of a list with entries:

theta

The parameter list from object (as returned by mixreg).

intercept

The logical value from object indicating whether intercepts were fitted.

x

The predictor for the model (extracted from the data entry of object).

y

The response for the model (extracted from the data entry of object).

xf

The equispaced sequence of values, extending from min(x) to max(x), at which the values of the band envelopes were calculated.

bnds

A list with one entry for each component of the mixture. Each entry is a matrix with 8 columns (lower and upper confidence and prediction bounds for one-sided intervals and lower and upper confidence and prediction bounds for two-sided interval).

alpha

Numeric scalar; the alpha argument.

varnms

Character vector of length two providing the names of the predictor (first entry) and of the response (second entry).

If plot is TRUE the value is returned invisibly.

Side Effects

If plot is TRUE a plot of the fit and the confidence and prediction bands is produced in whatever device is currently open or on screen if no device is open.

Warning

If MC is FALSE then an error may be thrown if the observed Fisher information (the inverse of which is use as the estimated covariance matrix) is singular. Note that if MC is FALSE then any call to covMix() is made with useMC="no".

Details

The prediction bands are conditional in that the associated probability is conditional upon the associated observation being generated by the relevant component of the mixture.

The covariance matrix need to construct the confidence and prediction bands is extracted from object, given that object has an entry named "covMat" (i.e. if the call to mixreg that produced object was made with covMat=TRUE). If object has no such entry then covMix() is called to produce the covariance matrix. (Such a call may take a bit of time.)

References

T. Rolf Turner (2000). Estimating the rate of spread of a viral infection of potato plants via mixtures of regressions. Applied Statistics 49 Part 3, pp. 371 -- 384.

See Also

ncMcTest(), covMix(), mixreg(), plot.cband(), residuals.mixreg(), plot.mixresid(), qqMix(),

Examples

Run this code
# NOT RUN {
# Aphids.
    thStrt <- list(list(beta=c(3.0,0.1),sigsq=16,lambda=0.5),
                   list(beta=c(0.0,0.0),sigsq=16,lambda=0.5))
    fit    <- mixreg(plntsInf~aphRel,ncomp=2,thetaStart=thStrt,
                     covMat=TRUE,data=aphids)
    cbds   <- cband(fit,plot=TRUE)
    plot(cbds) # Same plot as was produced by call to cband().
# Kilns.
   thStrt <- list(
                   list(beta=c(26.07,48808),sigsq=1.1573,lambda=0.33333333),
                   list(beta=c(23.48,32387),sigsq=1.8730,lambda=0.33333333),
                   list(beta=c(-0.0597,20760),sigsq=0.2478,lambda=0.33333333)
                 )
    fit    <- mixreg(y ~ x,ncomp=3,data=kilnAoneOut,thetaStart=thStrt)
    
# }
# NOT RUN {
 # Takes too long.
        res    <- residuals(fit,std=TRUE)
        qqMix(res) # No way are these residuals Gaussian!
        cbdsG  <- cband(fit)
        cbdsMC <- cband(fit,MC=TRUE)
        plot(cbdsG)
        plot(cbdsMC)
    # Same-same, despite the lack of Gaussianity!
    
# }

Run the code above in your browser using DataLab