lazylm: Fitting linear models using 'lazyarray'

lazylmR Documentation

Fitting linear models using lazyarray

Description

Fitting linear models using lazyarray

Usage

lazylm(
  formula,
  data,
  fitted = FALSE,
  weights = NULL,
  offset = NULL,
  contrasts = NULL,
  na.action = getOption("na.action"),
  qr.tol = 1e-07,
  ...
)

Arguments

formula

an object of class formula. For variable names to be used, see 'Details'

data

a lazyarray object

fitted

whether to calculate fitted data and residuals. This may take time and memory if data is large

weights, offset, contrasts, na.action

see lm

qr.tol

the tolerance for detecting linear dependencies in the partitions of data; see qr

...

passed to chunk_map

Details

The array will be reshaped to a matrix first before fitting the linear models. A 100 x 20 x 5 array will be reshaped to a 2000 x 5 lazy matrix. The variables are the partitions of the array. If dimnames are set for the last margin index, then those will be used as variable names, otherwise lazylm automatically assign "V1", "V2", "V3", ... as each partition names.

Value

An object of class c("lazylm", "lm") or for multiple responses of class c("lazylm", "mlm").

Examples


library(lazyarray)
arr <- array(rnorm(72), c(6,3,4))
arr[1,1,1] <- NA        # Allow NA to be treated
offset = rnorm(18)    # offset and weights are optional
weights = runif(18)

formula <- V1 ~ .-V2-1 + (V2 > 0)

data <- as.lazyarray(arr, type = 'file')
object <- lazylm(formula, data, weights = weights, offset = offset)


# Compare to stats::lm
dim(arr) <- c(18, 4)
lm_data <- as.data.frame(arr)
flm <- lm(formula, lm_data, weights = weights, offset = offset)

cbind(coef(object), coef(flm))
cbind(resid(object), resid(flm))
cbind(fitted(object), fitted(flm))
summary(object)
summary(flm)


dipterix/lazyarray documentation built on June 30, 2023, 6:30 a.m.