Learn R Programming

lmvar (version 1.5.2)

residuals.lmvar: Residuals from an 'lmvar' object

Description

Calculates residuals from an 'lmvar' object. This object can be a fit to either a response vector or the logarithm of the response vector.

Usage

# S3 method for lmvar
residuals(object, log = FALSE, ...)

Arguments

object

Object of class 'lmvar'

log

Boolean, specifies whether object is a fit to a response-variable \(Y\) or to its logarithm \(\log Y\) In both cases, residuals.lmvar returns residuals for \(Y\) itself.

...

For compatibility with residuals generic

Value

A numeric vector with the residual for each observation in object.

Details

In case log = FALSE, the residual of an observation is defined as \(y - \mu\), where \(y\) is the value of the observation and \(\mu\) its expected value.

In case log = TRUE, the residual of an observation is defined as \(e^y - \mu\), where \(\mu\) is the expected value of \(e^y\).

See Also

fitted.lmvar for the expected values in an object of class 'lmvar'.

Examples

Run this code
# NOT RUN {
# As example we use the dataset 'attenu' from the library 'datasets'. The dataset contains
# the response variable 'accel' and two explanatory variables 'mag'  and 'dist'.
library(datasets)

# Create the model matrix for the expected values
X = cbind(attenu$mag, attenu$dist)
colnames(X) = c("mag", "dist")

# Create the model matrix for the standard deviations.
X_s = cbind(attenu$mag, 1 / attenu$dist)
colnames(X_s) = c("mag", "dist_inv")

# Carry out the fit
fit = lmvar(attenu$accel, X, X_s)

# Calculate the residuals
residuals(fit)
# }

Run the code above in your browser using DataLab