# residuals.flexreg: Residuals Method for flexreg Objects In FlexReg: Regression Models for Bounded Continuous and Discrete Responses

 residuals.flexreg R Documentation

## Residuals Method for flexreg Objects

### Description

Method that computes various types of residuals from objects of class flexreg. If the model type is FB or FBB and cluster = TRUE, the method returns also residuals with respect to cluster means.

### Usage

## S3 method for class 'flexreg'
residuals(
object,
type = "raw",
cluster = FALSE,
estimate = "mean",
q = NULL,
...
)


### Arguments

 object an object of class flexreg, usually the result of flexreg or flexreg_binom functions. type a character indicating type of residuals ("raw" or "standardized"). cluster logical. If the model is "FB" without augmentation or "FBB", cluster = TRUE returns the cluster means. By default cluster = FALSE. estimate a character indicating the type of estimate: "mean" (default), "median", or "quantile". q if estimate = "quantile", a numeric value of probability in (0, 1). ... additional arguments. Currently not used.

### Details

The residuals method computes raw and standardized residuals from objects of class flexreg. Raw residuals are defined as r=y-\hat{\mu} for bounded continuous responses or as r= y/n-\hat{\mu} for bounded discrete responses. Values y and y/n are the observed responses which are specified on the left-hand side of formula in the flexreg and flexreg_binom functions, respectively. Moreover, \hat{\mu} is the predicted value, the result of the predict function with type = "response". Standardized residuals are defined as \frac{r}{\sqrt{\widehat{Var}(y)}} where \widehat{Var}(y) is the variance of the response evaluated at the posterior means –by default, otherwise evaluated at the posterior quantiles of order q– of the parameters. If the model is "FB" or "FBB", type = "raw", and cluster = TRUE, the cluster raw residuals are computed as the difference between the observed response/relative response and the cluster means, i.e., \hat{\lambda}_{1} and \hat{\lambda}_{2}. If the model is "FB" or "FBB", type = "standardized" and cluster = TRUE, the cluster standardized residuals are computed as the cluster raw residuals divided by the square root of the cluster variances. Cluster residuals, either raw or standardized, can be used for classification purpose. Indeed, with cluster = TRUE the residuals method returns also a column named "label" assigning values 1 or 2 to observations depending on whether they are classified in cluster 1 (if the corresponding cluster residual is smaller) or in cluster 2.

### Value

The method returns an array with as many rows as the number of observations in the sample. If cluster = FALSE, the array has only one column containing either the raw or standardized residuals. If cluster = TRUE, the array has four columns: the first column contains the raw or standardized residuals, the second and third columns contain the cluster residuals, and the fourth column contains the classification labels (see Details).

### References

Ascari, R., Migliorati, S. (2021). A new regression model for overdispersed binomial data accounting for outliers and an excess of zeros. Statistics in Medicine, 40(17), 3895–3914. doi:10.1002/sim.9005

Di Brisco, A. M., Migliorati, S. (2020). A new mixed-effects mixture model for constrained longitudinal data. Statistics in Medicine, 39(2), 129–145. doi:10.1002/sim.8406

Migliorati, S., Di Brisco, A. M., Ongaro, A. (2018). A New Regression Model for Bounded Responses. Bayesian Analysis, 13(3), 845–872. doi:10.1214/17-BA1079

### Examples

## Not run: