farray_lm: Fitting linear models using 'farray'

farray_lmR Documentation

Fitting linear models using farray

Description

Fitting linear models using farray

Usage

farray_lm(
  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 stats::formula(). For variable names to be used, see 'Details'

data

a farray 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 stats::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 file 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 farray_lm automatically assign "V1", "V2", "V3", ... as each partition names.

Value

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

Author(s)

Zhengjia Wang

Examples


library(farray)
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.farray(arr)
object <- farray_lm(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/farray documentation built on Oct. 16, 2022, 6:13 p.m.