R6 class holding the responses and design matrix used to fit a normal-block model.
Public fields
Ythe matrix of responses (rescaled column-wise if `scale = TRUE`)
Y_scalethe per-column standard deviation Y was divided by (all 1's if `scale = FALSE`)
Xthe matrix of covariates
X0the matrix of zero-inflation covariates, if applicable
formuladescribes the relationship between Y and X, and X0 if applicable, useful if not all of X's or X0's covariates should be used, should be formatted ~ X1 + X2... | Z1 + Z2... with the Normal formula before the | and the ZI formula after the |
nsample size
dnumber of covariates
d0number of zero-inflation covariates, if applicable
pnumber of variables
XtXuseful for inference in some cases
XtXm1inverse of XtX, useful for inference
XtYuseful for inference
npYtotal number of non zeros in Y
nYtotal number of non zeros for each column/variable in Y
zeroswhere are the zero in Y
zeros_barwhere are the non-zeros in Y
Methods
NormalBlockData$new()
Create a new [`NormalBlockData`] object.
Usage
NormalBlockData$new(
Y,
X,
X0 = NULL,
formula = NULL,
scale = TRUE,
zeros = NULL
)Arguments
Ythe matrix of responses (called Y in the model).
Xdesign matrix (called X in the model).
X0zero-inflation design matrix, if applicable.
formuladescribes the relationship between Y and X, useful if not all of X's covariates should be used.
scalewhether to rescale each column of Y by its own standard deviation (no centering). Default TRUE, see the class-level documentation for the rationale and its limits.
zerosan optional 0/1 matrix of structural zeros, overriding the default `Y == 0`.
NormalBlockData$ols_fit()
Ordinary-least-squares fit of Y on X, with its residuals and their covariance. Computed once and memoized.
NormalBlockData$zi_ols_fit()
Masked counterpart of `ols_fit()`: a per-variable weighted least-squares fit of B under the zero-inflation mask, with its inverse residual variances and residuals (see `zi_weighted_fit()`). Computed once and memoized.
NormalBlockData$zi_fit()
Zero-inflation component: `p` independent logistic regressions of each variable's zero pattern on `X0`, and the fixed contribution they make to the log-likelihood. The (V)EM never revisits these, so they are a property of the data rather than of a model.
Examples
ex <- generate_normal_block_var_data(n = 50, p = 20, d = 1, q = 3)
data <- NormalBlockData$new(ex$Y, ex$X)
c(n = data$n, p = data$p, d = data$d)
#> n p d
#> 50 20 1