View source: R/predicted_residuals.R

residuals.flexreg | R Documentation |

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.

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

`object` |
an object of class |

`type` |
a character indicating type of residuals ( |

`cluster` |
logical. If the model is |

`estimate` |
a character indicating the type of estimate: |

`q` |
if |

`...` |
additional arguments. Currently not used. |

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.

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

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

```
## Not run:
data("Reading")
FB <- flexreg(accuracy.adj ~ iq, data=Reading, type="FB")
residuals(FB, type="raw", cluster=TRUE)
## End(Not run)
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.