lm {complexlm} | R Documentation |
Linear Model Fitting for Complex or Numeric Variables
Description
An adaptation of lm that is compatible with complex variables. If the response is not complex, it calls the standard stats::lm()
Note: It is not capable of dealing with contrasts in the complex case.
The formula interpretation is also unable of handle algebraic expressions in formula
.
Usage
lm(
formula,
data,
subset,
weights,
na.action,
method = "qr",
model = TRUE,
x = TRUE,
y = FALSE,
qr = TRUE,
singular.ok = TRUE,
contrasts = NULL,
offset,
...
)
Arguments
formula |
an object of class "formula" (or one that can be coerced to that class): a symbolic description of the model to be fitted. For complex variables there are restrictions on what kinds of formula can be comprehended. See zmodel.matrix for details. |
data |
an optional data frame, list or environment (or object
coercible by |
subset |
an optional vector specifying a subset of observations to be used in the fitting process. |
weights |
an optional vector of weights to be used in the fitting
process. Should be |
na.action |
a function which indicates what should happen
when the data contain |
method |
the method to be used; for fitting, currently only
|
model |
logicals. If |
x |
logical. If |
y |
logicals. If |
qr |
logicals. If |
singular.ok |
logical. If |
contrasts |
Not implemented for complex variables. See zmodel.matrix for details. Default is |
offset |
this can be used to specify an a priori known
component to be included in the linear predictor during fitting.
This should be |
... |
additional arguments to be passed to the low level regression fitting functions (see below). |
Details
Like stats::lm the models are specified symbolically using the standard R formula notation:
response ~ terms
Meaning response
is a linear combination of the predictor variables in terms
.
For compatibility with complex numbers complexlm::lm
uses zmodel.matrix to build the model matrix
from the model formula. As such it is limited to terms consisting of predictor names connected by +
and/or :
operators.
Anything more complicated will result in an error.
If response is a matrix, then then lm()
fits a model to each column, and returns an object with class "mlm".
For complex input, this function calls zlm.wfit.
Value
Returns an object of class c("zlm", "lm")
, or for multiple responses c("zlm", "mlm", "lm")
.
The functions summary and anova are used to obtain and print a summary and analysis of variance table of the results.
The generic functions coefficients, effects, fitted.values and residuals extract various useful features of the value returned by lm.
Of course these things can also be accessed by simply using the get element symbol $
.
Objects of class "zlm" are lists with the following components.
coefficients |
a named vector of coefficients. |
residuals |
the residuals, that is response minus fitted values. |
fitted.values |
The fitted values, which are response values obtained by feeding the predictors into the model. |
rank |
The numeric rank of the fitted linear model. |
weights |
Numeric. The user supplied weights for the linear fit. If none were given, a vector of |
df.residual |
The residual degrees of freedom. |
call |
The matched call. |
terms |
the terms object used. |
contrasts |
The contrasts used, as these are not supported this component will probably be |
xlevels |
(only where relevant) a record of the levels of the factors used in fitting. |
offset |
the offset used (missing if none were used). |
y |
if requested, the response used. |
x |
the model matrix used, unless requested to not return it. |
model |
if requested, the model frame used. |
na.action |
(where relevant) information returned by model.frame on the special handling of NAs. |
assign |
Used by extractor functions like summary and effects to understand variable names. Not included in null fits. |
effects |
Complex list. See effects for explanation. Not included in null fits. |
qr |
unless declined, the output of the qr object created in the process of fitting. Not included in null fits. |
Note
In complexlm
, the x
parameter defaults to TRUE
so that followup
methods such as predict.lm have access to the model matrix.
See Also
lm.fit, lm.wfit, zlm.wfit, zmodel.matrix, complexdqlrs, stats::lm
Examples
set.seed(4242)
n <- 8
slop <- complex(real = 4.23, imaginary = 2.323)
interc <- complex(real = 1.4, imaginary = 1.804)
e <- complex(real=rnorm(n)/6, imaginary=rnorm(n)/6)
xx <- complex(real= rnorm(n), imaginary= rnorm(n))
tframe <- data.frame(x= xx, y= slop*xx + interc + e)
lm(y ~ x, data = tframe, weights = rep(1,n))