Efficient Linear Model Weighted Fit ("elm.wfit") is used
to fit linear models in an equivalent way to "glm.fit" but in
a reduced time depending on the design matrix and the family (or link).
elm.wfit(
x,
y,
weights = rep.int(1, n),
offset = NULL,
method = "qr",
tol = 1e-07,
singular.ok = TRUE,
reduce = TRUE,
...
)logical values indicating whether the
model matrix (x) and the response vector (y)
used in the fitting process should be returned as components of the returned
value.
logical values indicating whether the
model matrix (x) and the response vector (y)
used in the fitting process should be returned as components of the returned
value.
an optional vector of weights to be used in the fitting
process. Should be NULL or a numeric vector. If non-NULL, weighted
least squares is used with weights weights (that is, minimizing
sum(w*e^2)); otherwise ordinary least squares is used.
this can be used to specify an a priori known component
to be included in the linear predictor during fitting. This should be
NULL or a numeric vector or matrix of extents matching those of the
response. One or more offset terms can be included in the
formula instead or as well, and if more than one are specified their sum is
used. See model.offset.
the method to be used in fitting the model. The default method
"eglm.wfit" uses iteratively reweighted least squares (IWLS): the
alternative "model.frame" returns the model frame and does no
fitting. User-supplied fitting functions can be supplied either as a
function or a character string naming a function, with a function which
takes the same arguments as glm.fit from the stats package.
If specified as a character string it is looked up from within the
eflm namespace.
tolerance for the qr decomposition. Default is 1e-7.
logical; if FALSE a singular fit is an error.
logical; if TRUE an alternate design matrix of p * p is
used for the fitting instead of the traditional n * p design matrix.
For eglm: arguments to be used to form the default control argument if it is not supplied directly. For weights: further arguments passed to or from other methods.
A list that contains the same elements as the output from
"lm.fit".
elm.wfit is a workhorse function: it is not normally called
directly but can be more efficient where the response vector, design matrix
and family have already been calculated. Use elm for most of the
cases.
x <- cbind(rep(1, nrow(mtcars)), mtcars$wt)
y <- mtcars$mpg
elm.wfit(x, y)
#> $coefficients
#> x1 x2
#> 37.285126 -5.344472
#>
#> $residuals
#> [1] -2.2826106 -0.9197704 -2.0859521 1.2973499 -0.2001440 -0.6932545
#> [7] -3.9053627 4.1637381 2.3499593 0.2998560 -1.1001440 0.8668731
#> [13] -0.0502472 -1.8830236 1.1733496 2.1032876 5.9810744 6.8727113
#> [19] 1.7461954 6.4219792 -2.6110037 -2.9725862 -3.7268663 -3.4623553
#> [25] 2.4643670 0.3564263 0.1520430 1.2010593 -4.5431513 -2.7809399
#> [31] -3.2053627 -1.0274952
#>
#> $fitted.values
#> [1] 23.282611 21.919770 24.885952 20.102650 18.900144 18.793255 18.205363
#> [8] 20.236262 20.450041 18.900144 18.900144 15.533127 17.350247 17.083024
#> [15] 9.226650 8.296712 8.718926 25.527289 28.653805 27.478021 24.111004
#> [22] 18.472586 18.926866 16.762355 16.735633 26.943574 25.847957 29.198941
#> [29] 20.343151 22.480940 18.205363 22.427495
#>
#> $effects
#> [,1]
#> [1,] -2014.51225
#> [2,] -47.08028
#> attr(,"names")
#> [1] "x1" "x2"
#>
#> $weights
#> [1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
#>
#> $rank
#> [1] 2
#>
#> $assign
#> NULL
#>
#> $qr
#> $qr
#> [,1] [,2]
#> [1,] -107.8105482 -375.194743
#> [2,] 0.9549344 8.809156
#>
#> $qraux
#> [1] 1.296817 8.809156
#>
#> $pivot
#> [1] 1 2
#>
#> $tol
#> [1] 1e-07
#>
#> $rank
#> [1] 2
#>
#> attr(,"class")
#> [1] "qr"
#>
#> $df.residual
#> [1] 30
#>