Extract Model Residuals from an slmfit object.

# S3 method for slmfit
residuals(object, type = "raw", cross.validation = FALSE, ...)

Arguments

object

a slmfit object generated from the slmfit() function.

type

residual type: "raw" (the default) or "normalized"

cross.validation

a logical (TRUE or FALSE) that indicates whether the residuals computed should be found using leave one out cross-validation. Set to FALSE by default.

...

further arguments passed to or from other methods.

Value

a vector of residuals, consisting of each observed response/density minus the estimated mean, or, in the case of cross-validation, the observed response/density minus the leave-one-out-cross-validation prediction.

Examples

data(exampledataset) ## load a toy data set
slmobj <- slmfit(formula = counts ~ pred1 + pred2, data = exampledataset,
xcoordcol = 'xcoords', ycoordcol = 'ycoords', areacol = 'areavar')
residuals(slmobj)
#>            [,1]
#> 1   21.65360918
#> 3   -5.63425514
#> 4   -5.23213905
#> 5    7.56865139
#> 6   -1.73824935
#> 8   17.83149076
#> 9    3.78817823
#> 10  -8.35757819
#> 11 -11.18495096
#> 12  -2.19780475
#> 13 -10.80208753
#> 14 -10.45373933
#> 15   0.19589278
#> 16  -6.05612257
#> 17   0.04062533
#> 18  28.59448145
#> 21 -11.62734338
#> 22  -6.62201520
#> 23  -1.73516897
#> 25  16.61202685
#> 26  19.72611531
#> 27  -0.22645359
#> 28 -16.08614089
#> 29   2.94857146
#> 30  -5.54447368
#> 31  17.66308486
#> 32  -6.44394228
#> 33 -14.49559460
#> 34  -9.88298458
#> 35 -10.48915263
#> 36   6.13878220
#> 37 -13.25671602
#> 38  -4.86550277
#> 39  15.11620704
#> 40  -4.59592941
residuals(slmobj, cross.validation = TRUE)
#>  [1]  17.8184636  -3.4907706  -2.7508644  12.8183681  -0.2353784  12.6092536
#>  [7]   1.8527164  -6.4820119 -14.2140274  -2.2371921  -8.6698986  -5.0657358
#> [13]  -1.3126980  -7.1264357  -4.4663820  26.1792147  -4.7158679  -6.9119665
#> [19]  -0.1412452   7.1542171  20.1773746   3.0519787 -11.5387141   5.4216379
#> [25]  -6.7275490  20.8709145 -14.9485792 -20.0950688  -5.2070195  -4.4629285
#> [31]   9.5725572 -13.4525219  -8.5085968  18.8893488  -3.7860189