Learn R Programming

mixreg (version 2.0-10)

residuals.mixreg: Calculate the residuals of a mixture of linear regressions.

Description

Calculates the residuals from each component of the mixture and the matrix of probabilities that each observation was generated by each component.

Usage

# S3 method for mixreg
residuals(object, std=FALSE,...)

Arguments

object

An object of class "mixreg" as returned by mixreg().

std

Logical argument; if TRUE then the residuals are standardized (by dividing them by their estimated standard deviation).

Not used.

Value

A list (of class "mixresid") with entries

resid

The residuals of the model, bundled together in a \(n \times K\) matrix, where \(n\) is the number of observations and \(K\) is the number of components in the model. The \(k\)th column of this matrix is the vector of residuals from the \(k\)th component of the model.

fvals

Matrix of the fitted values of the model, structured like resid (above).

gamma

An \(n \times K\) matrix of probabilities. The entry gamma[i,j] of this matrix is the (fitted) probability that observation \(i\) was generated by component \(j\).

x

The matrix of predictors in the regression model (or if there is only one predictor, this predictor as a vector).

y

The vector of response values.

vnms

Character vector; the first entry is the name of the response. The remaining entries are “reasonable” names for the individual (vector) predictors. Note that if there is no predictor then vnms is of length two with second entry "index".

noPred

Logical scalar; set to TRUE if there are no predictors in the model.

Details

The calculation of the estimated standard deviations of the residuals is a little bit complicated since each component of the model is fitted using weighted regression in a setting in which the weights are NOT the reciprocals of error variances. See the reference below for more detail.

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(),cband(), covMix(), mixreg(), plot.cband(), plot.mixresid(), qqMix(), residuals.mixreg()

Examples

Run this code
# NOT RUN {
    fit    <- mixreg(aphRel,plntsInf,ncomp=2,seed=42,data=aphids)
    r      <- residuals(fit)
    plot(r)
    fit    <- mixreg(plntsInf ~ 1,ncomp=2,data=aphids)
    r      <- residuals(fit)
    plot(r,shape="l",polycol="green")
# }

Run the code above in your browser using DataLab