residuals.lmvar: Residuals from an 'lmvar' object

Description Usage Arguments Details Value See Also Examples

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

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

Details

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

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

Value

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

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# 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)

Example output

  [1]  0.1390897203 -0.0521538180 -0.0069438252 -0.0124535393 -0.0570631604
  [6] -0.0624822169 -0.0418300439  0.0499220361  0.1309645880  0.2101357245
 [11]  0.2243309139 -0.0056444484  0.2453129760 -0.0863896151  0.3310534943
 [16]  0.2925377680  0.1093125136 -0.0921384579 -0.0389640840 -0.0359307817
 [21] -0.0247355922 -0.0601487071 -0.0082106871 -0.0206917235  0.0514461107
 [26] -0.0135770130 -0.0148869129 -0.0179488929  0.0376699777  0.0505746954
 [31]  0.0543175259  0.0716413001 -0.0742697469 -0.0817066715 -0.0324492590
 [36]  0.0631316846  0.0788079104 -0.0415778437 -0.0605445413  0.1822897776
 [41]  0.0116450042 -0.0405807128  0.0015807118  0.0186130892  0.1525811743
 [46] -0.0714771059 -0.0803771988 -0.0314512031  0.0350973630 -0.0664831181
 [51] -0.0267407500 -0.0173845984 -0.0413832110 -0.0972203990 -0.0783166063
 [56] -0.1044132760 -0.1066389930 -0.1030580495 -0.0738295577 -0.0700867271
 [61] -0.0572153118 -0.0729635978 -0.1053831837 -0.0763360072  0.1236871165
 [66]  0.2045518148 -0.0637554081 -0.0086314481 -0.1045932779 -0.0072075238
 [71]  0.0453734197  0.0153734197 -0.0607029207 -0.0997315983 -0.0723125418
 [76] -0.0610220701  0.0816479948  0.2620351363  0.1577132121 -0.0752395057
 [81] -0.1615609675 -0.0590359918  0.2513957205  0.0619119093 -0.0284095525
 [86]  0.0946219000  0.1066866548  0.0993966455 -0.0370534010 -0.0253757877
 [91] -0.1019558063 -0.0874386926 -0.0739534939 -0.0078852313  0.0353409481
 [96]  0.1124339180  0.3125629652  0.5134662955  0.1135953426  0.6051439088
[101]  0.4366924749  0.3569505692  0.3083700882  0.1997896071  0.4105638902
[106]  0.0614672204  0.0415962676  0.2626286450  0.0227576922  0.0327576922
[111]  0.0854676829  0.1880486264  0.0781776736  0.1184357679  0.0098552869
[116] -0.0788542414  0.2424362304  0.0846300324 -0.0349828261 -0.0298209390
[121] -0.0298209390 -0.0485304672  0.0117276271 -0.0407876366 -0.1009162213
[126]  0.1839871089 -0.0617543343  0.0079242040 -0.0049782013 -0.0817830119
[131] -0.0916211248  0.1470210895  0.1476987028  0.1148277500  0.0324729859
[136]  0.1718601274  0.0428601274  0.1238925048  0.0198925048 -0.0561717875
[141] -0.0139136932  0.0188605899  0.0841834391  0.0395705806  0.0500548544
[146] -0.0358151735 -0.0373956546 -0.0362157505  0.0041075611 -0.0966019671
[151] -0.0983110328 -0.0473744003 -0.0714382301 -0.0531468334  0.1103198153
[156]  0.1261916931 -0.0685178351  0.1439992785 -0.0668064570 -0.0936445700
[161] -0.0774183905 -0.0019664942 -0.0400622390 -0.0655122855 -0.0124834863
[166]  0.0055174387 -0.0543535142 -0.0195135513 -0.0205135513  0.1196807131
[171] -0.0146402861  0.0136178082  0.0138759026  0.0007149404 -0.0495426914
[176] -0.0367036535 -0.0636712761 -0.0134774741 -0.0021870024 -0.0484127193
[181] -0.0624770117 -0.0524441718

lmvar documentation built on May 16, 2019, 5:06 p.m.