# residuals.mixreg: Calculate the residuals of a mixture of linear regressions. In mixreg: Functions to Fit Mixtures of 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

 ```1 2``` ```## S3 method for class '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.

## 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.

## Value

A list (of class "mixresid") with entries

 `resid` The residuals of the model, bundled together in a n x K matrix, where n is the number of observations and K is the number of components in the model. The kth column of this matrix is the vector of residuals from the kth component of the model. `fvals` Matrix of the fitted values of the model, structured like `resid` (above). `gamma` An n x 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.

## Author(s)

Rolf Turner r.turner@auckland.ac.nz

## 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.

`ncMcTest()`,`cband()`, `covMix()`, `mixreg()`, `plot.cband()`, `plot.mixresid()`, `qqMix()`, `residuals.mixreg()`
 ```1 2 3 4 5 6``` ``` 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") ```